Contoh Program (For) Trapesium Horizontal Pada C | Linux
#include
int main()
{
int a,b,c;
printf("\n Masukkan Nilai Deret = ");
scanf("%d", &a);
for(b=1;b<=a;b++)
{
for(c=1;c<=b;c++)
{
printf(" %d", c);
}
printf(" \n");
}
for(b=1;b<=a;b++)
{
for(c=1;c<=a;c++)
{
printf(" %d", c);
}
printf(" \n");
}
for(b=a;b>=1;b--)
{
for(c=1;c<=b;c++)
{
printf(" %d", c);
}
printf(" \n");
}
return 0;
}
Output:
int main()
{
int a,b,c;
printf("\n Masukkan Nilai Deret = ");
scanf("%d", &a);
for(b=1;b<=a;b++)
{
for(c=1;c<=b;c++)
{
printf(" %d", c);
}
printf(" \n");
}
for(b=1;b<=a;b++)
{
for(c=1;c<=a;c++)
{
printf(" %d", c);
}
printf(" \n");
}
for(b=a;b>=1;b--)
{
for(c=1;c<=b;c++)
{
printf(" %d", c);
}
printf(" \n");
}
return 0;
}
Output:
Posting Komentar