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
What is the heap?
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
Explain what is a stream?
Are there constructors in c?
struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer
Why is structure padding done in c?
Is javascript written in c?
What is a c token and types of c tokens?
What is the g value paradox?
Explain the bubble sort algorithm.
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
Explain low-order bytes.
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
When can you use a pointer with a function?
What are pointers really good for, anyway?