Monday, 22 October 2012

Odd Number Series Pyramid

Q. Write a C program to print the odd number series pyramid.
or
Q. Write a C program to print the following number pyramid as:

1
3  5  7
9 11  13  15  17  19

Ans.

/*c program for odd number pyramid*/
#include<stdio.h>
int main()
{
 int n=2,r,c,z=3;
 printf("1\n");
 for(r=1; r<=2; r++)
 {
  for(c=1; c<=r*3; c++,z=z+2)
     printf("%d ",z);
  printf("\n");
 }
 return 0;
}

The output of above program would be:


Output of odd number series pyramid C program
Figure: Screen shot for odd number series
pyramid C program

No comments:

Post a Comment