Number-Character Pattern

Q. Write a C program to print the following number-character pattern as:

1111111
1A1AAAA
1AA1AAA
1AAA1AA
1AAAA1A
1AAAAA1
1111111

Ans.

/*c program for number-character pattern*/
#include<stdio.h>
int main()
{
 int num=7,r,c,z;
 printf("1111111\n");
 for(r=1; r<=5; r++)
 {
  for(c=1; c<=num; c++)
  {

   if(c==1)
     printf("1");
   else
   {
     if( (r==1 && c==3) || (r==2 && c==4) || (r==3 && c==5) || (r==4 && c==6) || (r==5 && c==7) )
        printf("1");
     else
        printf("A");
   }
  }
  printf("\n");
 }
 printf("1111111");
 getch();
 return 0;
}

The output of above program would be:


output of Number-Character pattern C program
Figure: Screen-shot for number-character pattern C program

 

Comments