Senin, 03 Desember 2012

beberapa source code yang sering digunakan buat ngetes algoritma :D

postingan kedua :D

/* Tugas ALProg
Nama : Rahmat Yani Hidayat
NIM : 12.11.6570
Kelas : 12.S1TI.12 */

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

int main() {
//variabel
int p,n,x,jmlhkt; //int1
int a,b,c,d=7; //int2
int jlmhkt; //int3
char r[255];
char klmt[100];
char a1;

//fungsi
system("cls");
printf("Masukkan pilihan : \n\n1.Membalik String\n2.Menghitung Jumlah Karakter\n3.Tampilan Angka1\n4.Tampilan Angka2\n");
scanf("%d", &p);
getch();

//if func balik string
if ( p == 1 ) {
    system("cls");
    printf("Masukkan Kata yang akan di reverse : ");
    gets(r);
    printf("Kebalikkannya : ");
    printf((strrev(r)));
    printf("\n");
    system("pause");
    system("cls");
    main();
    }

//if hitung jumlah huruf dlm klimat
/* Still failing else if ( p == 2 ) {   
    int i1 = 0, b1 = 0, c1 = 0;                                                    
    char klmt1[100];                                                             
    char a1;
   
    system("cls");                                                                                                                                     
    printf ("Masukkan kalimat : ");                                            
    scanf ("%s", &klmt1);                                                       
                                                                            
    getch();                                                                   
                                                                        
    printf ("Masukkan Huruf yang akan di cari : ");                            
    scanf("%s",&a1);                                                            
    for(i1=0; i1 <= strlen(klmt1); i1++){                                            
    if(klmt1[i1] == a1){                                                          
    c1 = c1+1;                                                                 
    }                                                                          
}                                                                          
                                                                        
    printf("Huruf yang anda cari %s ",&a1);                                        
    printf(", Muncul : %i kali \n\n",c1);                                       
                                                                            
    getch();
    system("pause");                                                                    
    }                                                                                     
                   
                  
*/                   
//if hitung semua karakter
else if ( p == 2 ) {
    system("cls");    
    printf("Hitung karakter dalam kalimat : ");
    gets (klmt);      
    n = strlen(klmt); 
    printf("%i\n", n);
    system("pause");  
    main();           
                   
    }                    
//if angka1        
else if ( p == 3 ) {
    //yeaaaaaaaah     
    system("cls");    
    for(a=1;a<=b;a++){
              
    printf("%d", a);
   

            }
       

}
   

   
//if angka2
else if ( p == 4 ) {
 //yeaaaaaaaah
    system("cls");
    for(c=6;c<=d;c--){
    for(d=1;d<=c;d++){
    printf("%d", c);
       

        }           
    }
}

else {
    printf("Menu salah !\n");
    main();

    }
}

//created by Rahmat Yani Hidayat
//nim 12.11.6570


maaf jika masih banyak salah nya :D. mohon bimbingannya

Tidak ada komentar:

Poskan Komentar