Write a program in c to print
1
121
12321
1234321
123454321

Answer Posted / rohit1729

#include<iostream>
using namespace std;
int main()
{
int i,j,k,t,n,c,a[20];
cin>>t;
for(k=0;k<20;k++)
a[k]=(k+1);
while(t--)
{
cin>>n;
for(i=0;i<n;i++)
{
c=i-1;
for(j=0;j<(2*i+1);j++)
{
if(i>=j)
cout<<a[j];
else
{
cout<<a[c];
c--;
}
}cout<<" ";
}cout<<endl;
}
return 0;
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define the scope of static variables.

697


What does the format %10.2 mean when included in a printf statement?

1206


Explain what does the format %10.2 mean when included in a printf statement?

934


What are the three constants used in c?

639


What is meant by high-order and low-order bytes?

750






What does the error 'Null Pointer Assignment' mean and what causes this error?

842


How do you override a defined macro?

790


How does placing some code lines between the comment symbol help in debugging the code?

650


What is the difference between a free-standing and a hosted environment?

754


what is the basis for selection of arrays or pointers as data structure in a program

3882


Is c compiled or interpreted?

774


Explain the difference between null pointer and void pointer.

760


What are the rules for identifiers in c?

685


Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?

681


Describe wild pointers in c?

737