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

what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?

1887


What is C language ?

1511


What is sizeof array?

596


the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+....

22150


How do you print an address?

716






Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

637


What is call by reference in functions?

541


What is the use of static variable in c?

581


What is static function in c?

617


What is the difference between if else and switchstatement

1297


Are the variables argc and argv are always local to main?

557


What is array of structure in c programming?

737


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3720


What is the heap in c?

627


What is huge pointer in c?

569