patternprogram_315 softethics

Pattern 315

C

#include<stdio.h>
int main()
{
  int m=1;
  int p_height=5;
  int p_space=p_height-1;

  int i,j,k;  // loop variable


  int np=1; // for number printing
  char cp='A'; // for char printing

  for(i=1; i<=p_height; i++)
  {
    for(j=p_space; j>=i; j--)
    {
      printf(" ");
    }

    for(k=1; k<=m; k++)
    {
      if(i%2!=0)
      {
        printf("%d",np);  // print numbers if row is Odd
        np++;
      }
      else
      {
        printf("%c",cp); // print character if row is Even
        cp++;
      }

      np=(np>9)?1:np; //reset number
      cp=(cp>'Z')?'A':cp; //reset character
    }
    m+=2;
    printf("\n");
  }
}

C++

Java

C#

Python

0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments