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
When should the volatile modifier be used?
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
Difference between malloc() and calloc() function?
Which is better pointer or array?
#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }
What is signed and unsigned?
Explain the use of #pragma exit?
How can a program be made to print the line number where an error occurs?
What is file in c preprocessor?
What is the auto keyword good for?
How do you define CONSTANT in C?
How can I call fortran?
What is the best way to comment out a section of code that contains comments?
Why array is used in c?
What is memory leak in c?