To print even odd in pyramid
#include <stdio.h>
int main() {
int rows;
int n=2;
int p=1;
printf("Enter the no. of rows: ");
scanf("%d",&rows);
for (int i=1;i<=rows;i++){
for(int j=1;j<=rows-i;j++){
printf(" ");
}
if(i%2==0){
for (int j=1;j<=i;j++){
printf("%d ",n);
n+=2;
}
}else{
for (int j=1;j<=i;j++){
printf("%d ",p);
p+=2;
}
}
printf("\n");
}
return 0;
}
Enter the no. of rows: 5
1
2 4
3 5 7
6 8 10 12
9 11 13 15 17
Comments
Post a Comment