9.25.2015

Odd and Even Number Pattern Program In C

Q. Write a Odd and Even number pattern in C language as following:

    1
    2 4 6
    1 3 5 7 9
    2 4 6 8 10 12 14
    1 3 5 7  9 11 13 15 17

Ans.

/* even odd number pattern program in c*/
#include<stdio.h>
int main()
{

  int r,c,n,p;
  for(r=1,n=1; r<=5; r++,n=n+2)
  {
    if(r%2==0)
    {
      for(c=1,p=2; c<=n; c++,p=p+2)
          printf(" %d", p);
    }
    else
    {
      for(c=1,p=1; c<=n; c++,p=p+2)
          printf(" %d", p);
    }
    printf("\n");
  }
  getch();
  return 0;
}

/*******************************************************
The output of above program would be:
******************************************************/

Output of Odd and Even Number Pattern Program In C
Figure: Screen shot of Output of Odd and Even Number Pattern
 Program In C

You might also like to read:

  1. Big list of 98+ C pyramid programs
  2. Latest user asking pyramid programs list


No comments:

Post a Comment