21. Write a program using nested loops to produce the following designs: Using functions
A)
*
**
***
****
*****
|
B)
1
12
123
1234
12345
|
C)
1
23
456
78910
|
#include<iostream.h>
#include<conio.h>
void dis21A(int x)
{
int i,j;
i=1;
while(i<=x)
{
for(j=1;j<=i;j++)
{
cout<<"*";
}
cout<<"\n";
i++;
}
}
void dis21B(int x)
{
int i,j;
i=1;
while(i<=x)
{
for(j=1;j<=i;j++)
{
cout<<j;
}
cout<<"\n";
i++;
}
}
void dis21C(int x)
{
int i,j,k;
i=1,k=1;
while(i<=x)
{
for(j=1;j<=i;j++)
{
cout<<k<<"\t";
k++;
}
cout<<"\n";
i++;
}
}
void main()
{
int x,ch ;
clrscr();
cout<<"enter x \n";
cin>>x;
cout<<"enter choice\n";
cin>>ch;
switch(ch)
{
case 1:{
dis21A(x);
break;
}
case 2:{
dis21B(x);
break;
}
case 3:{
dis21C(x);
break;
}
default:{
cout<<"wrong choice\n";
break;
}
}
getch();
}
No comments:
Post a Comment