Output Pattern:
Enter the Value of n:3
333
313
323
333
Enter the Value of n:4
44444
44144
44244
44344
44444
Code for above Pattern:
#include<iostream>
using namespace std;
int main()
{
int n=0,i=0,j=0,k=0,tt=0,w=0,ww=0,mm=0;
cout<<"Enter the Value of n:";
cin>>n;
if(n%2==1)
{
for(int y=0;y<=n;y++)
{
ww=ww+y;
}
ww=ww/n;
for(i=0;i<n;i++)
{
cout<<n;
}
cout<<endl;
for(i=0;i<(n);i++)
{
mm++;
for(j=0;j<(n);j++)
{
if(j==(ww-1))
{
cout<<mm;
}
else
{
cout<<n;
}
}
cout<<endl;
}
}
else
{
for(int b=0;b<(n+1);b++)
{
cout<<n;
}
cout<<endl;
for(k=1;k<(n+1);k++)
{
tt=tt+k;
}
tt=tt/(n+1);
for(i=0;i<(n);i++)
{
w++;
for(j=0;j<(n);j++)
{
if(j==tt)
{
cout<<w;
}
cout<<n;
}
cout<<endl;
}
}
}
Enter the Value of n:3
333
313
323
333
Enter the Value of n:4
44444
44144
44244
44344
44444
Code for above Pattern:
#include<iostream>
using namespace std;
int main()
{
int n=0,i=0,j=0,k=0,tt=0,w=0,ww=0,mm=0;
cout<<"Enter the Value of n:";
cin>>n;
if(n%2==1)
{
for(int y=0;y<=n;y++)
{
ww=ww+y;
}
ww=ww/n;
for(i=0;i<n;i++)
{
cout<<n;
}
cout<<endl;
for(i=0;i<(n);i++)
{
mm++;
for(j=0;j<(n);j++)
{
if(j==(ww-1))
{
cout<<mm;
}
else
{
cout<<n;
}
}
cout<<endl;
}
}
else
{
for(int b=0;b<(n+1);b++)
{
cout<<n;
}
cout<<endl;
for(k=1;k<(n+1);k++)
{
tt=tt+k;
}
tt=tt/(n+1);
for(i=0;i<(n);i++)
{
w++;
for(j=0;j<(n);j++)
{
if(j==tt)
{
cout<<w;
}
cout<<n;
}
cout<<endl;
}
}
}
No comments:
Post a Comment
we are hear to discuss your queries ,so please feel free to ask any of your queries.