C Programming

C Programming


Character Rectangle Structure

Posted: 26 Dec 2013 11:42 PM PST

Q. Write  a C program to display the following character rectangle structure/pattern/design as:

ABCDEEDCBA
ABCD__DCBA
ABC____CBA
AB______BA
A________A

Ans.

/*c program for character rectangle pattern*/
#include<stdio.h>
int main()
{
 char ch,r='A',c,sp;
 printf("Enter any character : ");
 scanf("%c",&ch);
 if(ch>='a' && ch<='z')
    ch=ch-32;
 printf("\n");
 for(; ch>='A'; ch--,r++)
 {
  for(c='A'; c<=ch; c++)
     printf("%c",c);
  for(sp=r; sp>'A'; sp--)
     printf("__");
  for(c=ch; c>='A'; c--)
     printf("%c",c);
  printf("\n");
 }
 getch();
 return 0;
}

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


Output of character rectangle pattern C program
Figure: Screen shot for character rectangle structure C program




Post a Comment

C Programming

C Programming


Number Rectangle Pattern

Posted: 10 Dec 2013 06:28 AM PST

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

1 2 3 4 5 4 5
2 3 4 5 3 4 5
3 4 5 2 3 4 5
4 5 1 2 3 4 5

Ans.

/*c program for number pattern rectangle design*/
#include<stdio.h>
int main()
{

 int n=4,num=5,p=4,r,c,z;
 for(r=1; r<=n; r++,p--)
 {
   for(c=r; c<=num; c++)
      printf(" %d",c);
   for(c=1,z=p; c<=r+1; c++,z++)
     printf(" %d",z);
   printf("\n");
 }
 getch();
 return 0;
}

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


Output of Number Rectangle Pattern C program
Figure: Screen-shot for Number Rectangle Pattern C program



Post a Comment

IPL Twenty20 Cricket

IPL Twenty20 Cricket


Only T20: Pakistan vs Afghanistan in UAE 2013

Posted: 07 Dec 2013 09:20 AM PST


DateMatch DetailsTime
(IST)
Place
Dec 08 - SunAfghanistan v Pakistan, Only T20I21:30Sharjah

West Indies tour of New Zealand 2013-14

Posted: 07 Dec 2013 09:05 AM PST

DateMatch DetailsTime
(IST)
Place
Jan 11 - Sat1st T20I - New Zealand v West Indies11:30Auckland
Jan 15 - Wed2nd T20I - New Zealand v West Indies11:30Wellington


Post a Comment