4.17.2013

Number Star Pyarmid

Q. Write a C program to print the following number star pyramid as:

1
1*
1*3
1*3*
1*3*5
1*3*5*

Ans.

/*number star c pyramid program*/
#include<stdio.h>
int main()
{
 int num,r,c;
 printf("Enter no. of rows: ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
  for(c=1; c<=r; c++)
  {
    if(c%2==0)
       printf("*");
    else
       printf("%d",c);
  }
  printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:

Output of number star pyramid C program
Figure: Screen shot for number star pyramid C program

No comments:

Post a Comment