Pages

Wednesday, March 23, 2011

PATTERN PRINTING


THIS PROGRAM WILL GIVE THE FOLLOWING OUTPUT DEPENDING ON THE NUMBER N GIVEN BY USER.
1
12
123
1234
12345

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<"enter a number";
cin>>n;
for(int i=1;i<=n;i++)
{
    for(int j=1;j<=i;j++)
    {
    cout<<j;
    }
    cout<<"\n";
}
getch();
}


IF YOU WANT TO PRINT THE NUMBERS IN FOLLOWING MANNER ,THE PROGRAM IS GIVEN BELOW :
1
22
333
4444
55555

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<"enter a number";
cin>>n;
for(int i=1;i<=n;i++)
{
    for(int j=1;j<=i;j++)
    {
    cout<<i;
    }
    cout<<"\n";
}
getch();
}

Just copy and paste the above programs in the notepad file ans save it with .cpp extension and open it in ur compiler, and the work is done , enjoy :)


No comments:

Post a Comment