Selasa, 29 Mei 2012

program generate permutasi

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
using namespace std;
int hasil;
//funsi faktorial :
int faktorial (int nilai)
{
hasil = nilai;
while(nilai>1)
{
hasil = hasil*(nilai-1);
nilai = nilai-1;
}
return hasil;
}
main()
{
int p,nq,max,x,i,j,n,k,r,s,tr,no ;
int a[100];
div_t xx;
for (i=0;i<100;i++)
{
a[i] =0;
}
//Tampilkan pembuka
printf(“\n                             PROGRAM GENERATE PERMUTASI\n\n”);
//input nilai n(jumlah data <maksimal 100>)
printf(“Masukan nilai n : “);
scanf(“%d”,&n);
//input data ke dalam array
for(i=1;i<=n;i++)    //ulangi untuk semua data hingga data ke-n
{
printf(“Masukan nilai himpunan a[%d] : “,i);
scanf(“%d”,&a[i]);
}
//input nilai r
printf(“nilai r : “);
scanf(“%d”,&tr);
//hitung nilai permutasi
p=faktorial(n);
nq=faktorial(n-tr);
if(nq==0)nq=1;
max=p/nq;
printf(“nilai permutasi : %d\n\nTekan Enter untuk melihat hasil generate permutasi…\n”,max);
getche();//fungsi membaca karakter keyboard
no=1;//variabel untuk menampilkan nomor
//men-generate permutasi dengan
//algoritma generate next-permutation
//genere sabanyak nilai permutasi
for(x=1;x<=max;x++)
{
printf(“%3d. “,no);
for(i=1;i<=tr;i++)
printf(“%d”,a[i]);
printf(“\n”,a[i]);
no++;
j=n-1;
while(a[j] > a[j+1])
j=j-1 ; //j adalah subcript terbesar dengan aj<aj+1
k=n;
while(a[j] > a[k])
k=k-1 ; //ak adalah integer terkecil dan lebih besar dari aj
//tukar aj dan ak
i=a[k];
a[k]=a[j];
a[j]=i;
r=n;
s=j+1;
while (r>s)
{
//tukar ar dan as
i=a[r];
a[r]=a[s];
a[s]=i;
r=r-1;
s=s+1;
}
}
system(“PAUSE”);
return EXIT_SUCCESS;
}

tugas PEMROGRAMAN WEB

Kelompok :
  1. Eko Febri Nur W                   11018135
  2. Agus Triyono                        11018140
  3. Lalu Wahyu Reza Pratama     11018144
  4. Dimas Nugroho Setyadi W.A  11018158
1. Form input eksekusi dengan asp
01<html>
02 <head>
03 <title>Form Input</title>
04 </head>
05 <body>
06 <form method="get" action="simpleform.asp">
07 <table>
08 <tr>
09 <td>Nama</td><td><input type="text" value="" name="Nama"></td>
10 </tr>
11 <tr>
12 <td>Alamat</td><td><input type="text" value="" name="Alamat"></td>
13 </tr>
14 <tr>
15 <td>Telp</td><td><input type="text" value="" name="Telp"></td>
16 </tr>
17 <tr>
18 <td>Jenis Kelamin</td><td><input type="radio" value="L" name="jenis kelamin">Laki-laki</td>
19 <td><input type="radio" value="P" name="jenis kelamin">Perempuan</td>
20 </tr>
21 <tr><td>
22 Agama <td><select name="Agama">
23 <option>Islam</option>
24 <option>Kristen</option>
25 <option>Katolik</option>
26 <option>Hindu</option>
27 <option>Budha</option></td>
28 </td></tr>
29 </select>
30 <tr><td>
31 Prestasi Yang Pernah diraih <td><textarea></textarea></td>
32 </td></tr>
33 </table>
34 <input type="submit" value="Simpan">
35 <input type="button" value="Batal">
36 
37</table>
38 </form>
39 </body>
40 </html>
Hasil ouputnya seperti ini :
2. Perulangan for, while, dan do while dalam php
  • Perulangan for php
1<?php
2 $n=0;
3 for($i=1; $i<=5; $i++)
4 {
5 $n=$n+$i;
6 }
7 echo "$n";
8 ?>
Hasil outputnya : 15
  • Perulangan while php
1<?php
2 $x = 0;
3 while($x != 10)
4 {
5 echo $x;
6 $x++;
7 }
8 ?>
Hasil outputnya : 123456789
  • Perulangan do while php
1<?php
2 $x = 0;
3 do
4 {
5 echo $x;
6 $x++;
7 }
8 while($x != 10)
9 ?>
Hasil outputnya : 123456789
3. Fungsi-fungsi php
01<?php
02function writeName()
03{
04echo "Slamet"."<br/>";
05}
06echo "Nama Saya Adalah : " ;
07writeName();
08 
09function add($x,$y)
10{
11$total=$x+$y;
12return $total;
13}
14echo "50 + 50 = " . add(50,50)."<br/>";
15function kurang($x,$y)
16{
17$total=$x-$y;
18return $total;
19}
20echo "50 - 50 = " . kurang(50,50)."<br/>";
21echo "Today is ".date("d-F-Y")."<br/>";
22$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
23echo "Tomorrow is ".date("d-F-Y", $tomorrow)."<br/>";
24$str="saya mahasiswa uad";
25echo "Kalimat : ".($str)."<br/>"."Dibalik : ".strrev($str)."<br/>";
26?>
Hasil outputnya seperti ini :