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

10 comments:

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

    ReplyDelete
    Replies
    1. its java code you have to convert it in c

      package Triangle;

      import java.util.Scanner;

      public class Prg48 {

      /**
      * @param args
      */
      public static void main(String[] args) {
      int i,j,no,d=1,c=1;
      Scanner sc = new Scanner(System.in);
      no = sc.nextInt();

      for(i=1;i<=no;i++)
      {
      if(i%2==0)
      {
      c=c+i;
      d=c+1;
      if(i>2)
      {
      c=c*2;
      d=c+1;
      }
      for(j=1;j<=i*2-1;j++)
      {
      if(j%2==0)
      {
      System.out.print("*");
      }
      else
      {
      System.out.print(c);
      c--;
      }
      }
      System.out.println();
      }
      else
      {
      for(j=1;j<=i*2-1;j++)
      {
      if(j%2==0)
      {
      System.out.print("*");
      }
      else
      {
      System.out.print(d);
      d++;
      }
      }
      System.out.println();
      }
      }
      }
      // TODO Auto-generated method stub

      }


      Delete
  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. print the pattern
    *
    * *
    * * *
    * * * *

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

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

      Delete