oke hello guy ini ada source code perulangan hihih
semoga bermanfaat
ini perulangan kompleks yak
PERLU DIPERHATIKAN ! KOMPILE LAH DENGAN bahasa C karena menggunakan perintah printf dan scanf
#include <stdio.h>
/*PROGRAM RHAMAD NURSANI SIDIK*/
int segitiga_siku(int b);//pil 1
int segitiga_siku_terbalik(int b); //pil 2
int siku_mirror(int b); //pil 3
int mirror_terbalik(int b); //pil 4
int segitiga_piramid(int b); //pil 5
int piramid_terbalik(int b); //pil 6
int diamond(int b); //pil 7
/*PROGRAM RHAMAD NURSANI SIDIK*/
int main()//program utama
{/*PROGRAM RHAMAD NURSANI SIDIK*/
int a, pilihan;
/*PROGRAM RHAMAD NURSANI SIDIK*/
printf("-------------program menamplkan gambar segitiga------------\n\n\n");
printf("masukan jumlah baris bintang segi tiga\n"); scanf("%d",&a);
do/*PROGRAM RHAMAD NURSANI SIDIK*/
{/*PROGRAM RHAMAD NURSANI SIDIK*/
printf("\n1.segitiga siku\n2.segitiga siku terbalik\n3.segitiga siku mirror\n4.segitiga mirror terbalik\n");
printf("5.piramid\n6.piramid terbalik\n7.diamond\n"); scanf("%d",&pilihan);
if(pilihan != 0 )
switch(pilihan)
{/*PROGRAM RHAMAD NURSANI SIDIK*/
case 1:/*PROGRAM RHAMAD NURSANI SIDIK*/
segitiga_siku(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 2:/*PROGRAM RHAMAD NURSANI SIDIK*/
segitiga_siku_terbalik(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 3:/*PROGRAM RHAMAD NURSANI SIDIK*/
siku_mirror(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 4:/*PROGRAM RHAMAD NURSANI SIDIK*/
mirror_terbalik(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 5:/*PROGRAM RHAMAD NURSANI SIDIK*/
segitiga_piramid(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 6:/*PROGRAM RHAMAD NURSANI SIDIK*/
piramid_terbalik(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 7:/*PROGRAM RHAMAD NURSANI SIDIK*/
diamond(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
/*PROGRAM RHAMAD NURSANI SIDIK*/
default:/*PROGRAM RHAMAD NURSANI SIDIK*/
printf("tidak ada pilihan");
}
}while(pilihan != 0);/*PROGRAM RHAMAD NURSANI SIDIK*/
return 0;/*PROGRAM RHAMAD NURSANI SIDIK*/
}
int segitiga_siku(int b)//1.fungsi segitiga siku
{
int a, c;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = 1; c <= a;c++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int segitiga_siku_terbalik(int b)//2.fungsi segitiga siku terbalik
{
int a, c;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = b; c >= a;c--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int siku_mirror(int b)//3.fungsi segitiga siku mirror
{
int a, c, d;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = b; c >= a;c--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for (d =1 ; d <=a; d++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int mirror_terbalik(int b)//4.fungsi segitiga siku mirror terbalik
{
int a, c, d;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = 1; c <= a;c++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for (d = b ; d >=a; d--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int segitiga_piramid(int b)//5.fungsi segitiga piramid
{
int a,c,d,e;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = b-1; c >= a;c--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(d = 1; d<=a;d++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(e=2; e<=a; e++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int piramid_terbalik(int b)//6.fungsi segitiga piramid terbalik
{
int a,c,d,e;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = 1; c <= a;c++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(d = b-1; d>=a;d--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(e = b ; e>=a; e--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int diamond(int b) //7.fungsi diamond
{
int a,c,d,e;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = b-1; c >= 1;c--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(d = 1; d<=a;d++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(e=2; e<=a; e++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(a = 1; a<b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = 1; c <= a;c++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("|");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(d = b-1; d>a;d--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(e = b ; e>a; e--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
Nah perulangan diatas merupakan perulangan dengan menampilkan berbagai bentuk persegi daengan menggunkan bintang.
semoga bermanfaat
ini perulangan kompleks yak
PERLU DIPERHATIKAN ! KOMPILE LAH DENGAN bahasa C karena menggunakan perintah printf dan scanf
#include <stdio.h>
/*PROGRAM RHAMAD NURSANI SIDIK*/
int segitiga_siku(int b);//pil 1
int segitiga_siku_terbalik(int b); //pil 2
int siku_mirror(int b); //pil 3
int mirror_terbalik(int b); //pil 4
int segitiga_piramid(int b); //pil 5
int piramid_terbalik(int b); //pil 6
int diamond(int b); //pil 7
/*PROGRAM RHAMAD NURSANI SIDIK*/
int main()//program utama
{/*PROGRAM RHAMAD NURSANI SIDIK*/
int a, pilihan;
/*PROGRAM RHAMAD NURSANI SIDIK*/
printf("-------------program menamplkan gambar segitiga------------\n\n\n");
printf("masukan jumlah baris bintang segi tiga\n"); scanf("%d",&a);
do/*PROGRAM RHAMAD NURSANI SIDIK*/
{/*PROGRAM RHAMAD NURSANI SIDIK*/
printf("\n1.segitiga siku\n2.segitiga siku terbalik\n3.segitiga siku mirror\n4.segitiga mirror terbalik\n");
printf("5.piramid\n6.piramid terbalik\n7.diamond\n"); scanf("%d",&pilihan);
if(pilihan != 0 )
switch(pilihan)
{/*PROGRAM RHAMAD NURSANI SIDIK*/
case 1:/*PROGRAM RHAMAD NURSANI SIDIK*/
segitiga_siku(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 2:/*PROGRAM RHAMAD NURSANI SIDIK*/
segitiga_siku_terbalik(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 3:/*PROGRAM RHAMAD NURSANI SIDIK*/
siku_mirror(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 4:/*PROGRAM RHAMAD NURSANI SIDIK*/
mirror_terbalik(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 5:/*PROGRAM RHAMAD NURSANI SIDIK*/
segitiga_piramid(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 6:/*PROGRAM RHAMAD NURSANI SIDIK*/
piramid_terbalik(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
case 7:/*PROGRAM RHAMAD NURSANI SIDIK*/
diamond(a);/*PROGRAM RHAMAD NURSANI SIDIK*/
break;/*PROGRAM RHAMAD NURSANI SIDIK*/
/*PROGRAM RHAMAD NURSANI SIDIK*/
default:/*PROGRAM RHAMAD NURSANI SIDIK*/
printf("tidak ada pilihan");
}
}while(pilihan != 0);/*PROGRAM RHAMAD NURSANI SIDIK*/
return 0;/*PROGRAM RHAMAD NURSANI SIDIK*/
}
int segitiga_siku(int b)//1.fungsi segitiga siku
{
int a, c;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = 1; c <= a;c++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int segitiga_siku_terbalik(int b)//2.fungsi segitiga siku terbalik
{
int a, c;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = b; c >= a;c--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int siku_mirror(int b)//3.fungsi segitiga siku mirror
{
int a, c, d;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = b; c >= a;c--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for (d =1 ; d <=a; d++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int mirror_terbalik(int b)//4.fungsi segitiga siku mirror terbalik
{
int a, c, d;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = 1; c <= a;c++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for (d = b ; d >=a; d--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int segitiga_piramid(int b)//5.fungsi segitiga piramid
{
int a,c,d,e;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = b-1; c >= a;c--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(d = 1; d<=a;d++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(e=2; e<=a; e++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int piramid_terbalik(int b)//6.fungsi segitiga piramid terbalik
{
int a,c,d,e;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = 1; c <= a;c++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(d = b-1; d>=a;d--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(e = b ; e>=a; e--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
int diamond(int b) //7.fungsi diamond
{
int a,c,d,e;/*PROGRAM RHAMAD NURSANI SIDIK*/
for(a = 1; a<=b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = b-1; c >= 1;c--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf(" ");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(d = 1; d<=a;d++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(e=2; e<=a; e++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(a = 1; a<b; a++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
for (c = 1; c <= a;c++)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("|");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(d = b-1; d>a;d--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
for(e = b ; e>a; e--)/*PROGRAM RHAMAD NURSANI SIDIK*/
{
printf("*");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
printf("\n");/*PROGRAM RHAMAD NURSANI SIDIK*/
}
}
Nah perulangan diatas merupakan perulangan dengan menampilkan berbagai bentuk persegi daengan menggunkan bintang.
No comments:
Post a Comment