4.17.2013

Even Odd Number Star Pyramid

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

1
*2
1*3
*2*4
1*3*5
*2*4*6

Ans.

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

The output of above program would be:

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

9 comments:

  1. 1
    3*2
    4*5*6
    10*9*8*7
    11*12*13*14*15
    please send me code...its urgent

    ReplyDelete
  2. *
    * * *
    * * * * *
    please provide program for this star pattern?

    ReplyDelete
    Replies
    1. @ Arundhati Saxena,

      Your required star pattern C program source code as:

      http://cprogrammingcodes.blogspot.com/2012/10/star-pyramid-pattern.html

      Delete
  3. Plz print
    ××××××
    ×××
    ×

    ReplyDelete
    Replies
    1. Your required symbol hash pattern C program source code as:

      #include"stdio.h>
      int main()
      {
      int n=6,r,c;
      for(r=1; r<=3; r++,n=n-3)
      {
      for(c=1; c<=n; c++)
      printf("*");
      printf("\n");
      }
      printf("#");
      getch();
      return 0;
      }

      /****************Output****************/

      ######
      ###
      #

      Delete
  4. Plz print
    ×××××
    ×××
    ×

    ReplyDelete
  5. print the pattern
    *
    * *
    * * *
    * * * *

    ReplyDelete
    Replies
    1. Symbol pattern C program source code as:

      http://cprogrammingcodes.blogspot.com/2011/09/4design-tringle-praymid.html

      Delete