Sunday, February 15, 2015

C C Program to Print Following Pattern

ABCDEFGFEDCBA
ABCDEF  FEDCBA
ABCDE     EDCBA
ABCD         DCBA
ABC             CBA
AB                 BA
A                     A

C Program

#include<stdio.h>

int main()
{
int i,j,k,l,m;
for(i=0;i<=6;i++)
{
for(k=65;k<=71-i;k++)
printf("%c",k);

for(j=1;j<=i*2-1;j++)
printf(" ");

for(l=71-i;l>=65;l--)
if(l!=71)
printf("%c",l);

printf("
");
}

return 0;
}

C++ Program

#include<iostream>

using namespace std;

int main()
{
int i,j,k,l,m;
for(i=0;i<=6;i++)
{
for(k=65;k<=71-i;k++)
cout<<(char)k; //typecasting integer to character

for(j=1;j<=i*2-1;j++)
cout<<" ";

for(l=71-i;l>=65;l--)
if(l!=71)
cout<<(char)l;
cout<<"
";
}

return 0;
}

C/C++ Program to Print Following Pattern ABCDEFGFEDCBA ABCDEF  FEDCBA ABCDE     EDCBA ABCD         DCBA ABC             CBA AB                 BA A                     A

Comment below if you find any difficulty in understanding the above programs.