Berikut contoh program menggunakan array :
#include <string.h>
int main(){
int i, nilai[3], jml, a, b, c;
char nama[3][10];
char nm[10];
printf("\t\t\t= = = Program Array Dimensi Dua = = = \n\n");
for (i=0;i<=2;i++){
printf(" Input Nama ke-%d : ", i+1); scanf("%s", &nama[i]);
printf(" Input Nilai ke-%d : ", i+1); scanf("%d", &nilai[i]);
}
jml=0;
for(i=0;i<=2;i++){
jml=jml+nilai[i];
}
printf("______________________________________________________\n");
printf(" No\t Nama\t \tNilai \n");
printf("______________________________________________________\n");
for(i=0;i<=2;i++){
printf("%d\t %s\t \t %d \n", i+1, nama[i], nilai[i]);
}
printf("______________________________________________________\n");
printf("\t Jumlah Nilai : %d\n", jml);
printf("\n______________________________________________________\n");
printf("\n\n Nama Yang Ingin di Cari: "); scanf("%s", &nm);
a=strcmp(nm,nama[0]);
b=strcmp(nm,nama[1]);
c=strcmp(nm,nama[2]);
if(a==0)
printf("\n No %d\t\t Nama: %s\t\t Nilai:%d\n",i,nama[0],nilai[0]);
else if(b==0)
printf("\n No %d\t\t Nama: %s\t\t Nilai:%d\n",i,nama[1],nilai[1]);
else if(c==0)
printf("\n No %d\t\t Nama: %s\t\t Nilai:%d\n",i,nama[2],nilai[2]);
else
printf(" Maaf nama yang anda cari tidak ada ");
printf("\n\n\t\t- - - Created by: Muhammad Ashi Dicky - - - \n\n");
}
Hasil Program :
Sekian yang bisa saya tulis, Semoga bermanfaat, Terimakasih...
- Listing Program :
#include <string.h>
int main(){
int i, nilai[3], jml, a, b, c;
char nama[3][10];
char nm[10];
printf("\t\t\t= = = Program Array Dimensi Dua = = = \n\n");
for (i=0;i<=2;i++){
printf(" Input Nama ke-%d : ", i+1); scanf("%s", &nama[i]);
printf(" Input Nilai ke-%d : ", i+1); scanf("%d", &nilai[i]);
}
jml=0;
for(i=0;i<=2;i++){
jml=jml+nilai[i];
}
printf("______________________________________________________\n");
printf(" No\t Nama\t \tNilai \n");
printf("______________________________________________________\n");
for(i=0;i<=2;i++){
printf("%d\t %s\t \t %d \n", i+1, nama[i], nilai[i]);
}
printf("______________________________________________________\n");
printf("\t Jumlah Nilai : %d\n", jml);
printf("\n______________________________________________________\n");
printf("\n\n Nama Yang Ingin di Cari: "); scanf("%s", &nm);
a=strcmp(nm,nama[0]);
b=strcmp(nm,nama[1]);
c=strcmp(nm,nama[2]);
if(a==0)
printf("\n No %d\t\t Nama: %s\t\t Nilai:%d\n",i,nama[0],nilai[0]);
else if(b==0)
printf("\n No %d\t\t Nama: %s\t\t Nilai:%d\n",i,nama[1],nilai[1]);
else if(c==0)
printf("\n No %d\t\t Nama: %s\t\t Nilai:%d\n",i,nama[2],nilai[2]);
else
printf(" Maaf nama yang anda cari tidak ada ");
printf("\n\n\t\t- - - Created by: Muhammad Ashi Dicky - - - \n\n");
}
Hasil Program :
output program
Tidak ada komentar:
Posting Komentar
Tolong berkomentar dengan sopan dan baik, Terimakasih.