Home » C » C Program
Print Pyramid, Rectangle, Triangle & Different shapes using loops in C programing
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
Solution:
#include <stdio.h>
int main(int argc, char *argv[]) {
int count = 5;
int i,j,k;
for(i = 0 ; i<5; i++)
{
for(j=0; j<i; j++)
printf(" ");
for(k=count; k>0; k-- )
printf("%d", k);
count--;
printf("\n");
}
return 0;
}
1
1 2
1 2 3
1 2
1
Solution:
#include <stdio.h>
int main(int argc, char *argv[]) {
int count = 0;
int i,j;
int rows = 5;
for(i = 0 ; i<rows; i++)
{
if(i<=(rows/2))
count++;
else
count--;
for(j=1; j<=count; j++ )
printf("%d", j);
printf("\n");
}
return 0;
}
1 2 3
1 2
1
1 2
1 2 3
Solution:
#include <stdio.h>
int main(int argc, char *argv[]) {
int count = 0;
int i,j;
int rows = 5;
count = rows/2 +1;
for(i = 0 ; i<rows; i++)
{
for(j=1; j<=count; j++ )
printf("%d", j);
printf("\n");
if(i+1 <= count)
count --;
else
count++;
}
return 0;
}
1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1
Solution:
#include<stdio.h>
int main(int argc, char *argv[]) {
int count = 0;
int i,j;
int rows = 5;
int temp = rows;
count = rows/2 +1;
for(i = 0 ; i<rows; i++)
{
for(j=1; j<=temp; j++)
printf("%d",j);
for(j=0; j<i; j++)
printf(" ");
for(j=temp;j>=1;j--)
printf("%d",j);
printf("\n");
temp--;
}
return 0;
}
12345
1234
123
12
1
Solution:
#include<stdio.h>
int main()
{
int no[5];
int min;
int i,j;
for(i=0;i<5;i++)
{
for(j=1;j<=5-i;j++)
printf("%d", j);
printf("\n");
}
return 0;
}