Tuesday, September 4, 2018

printing alphabets in a grid pattern (1 to r) pattern program

// Program to print Pattern
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int num; // To input number of lines
cout<<"Enter Number "; cin>>num;
char ch; int c;
for(int r=1; r<=num; r++) {
for(c=1,ch='A' ; c<=r; c++,ch++)
{
cout<<(char)ch<<" "; // will print * in a single line
}
cout<<"\n"; // At end of inner loop next line will
// come in a new line
}
getch();
}

No comments:

Post a Comment