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

Answers were Sorted based on User's Feedback



Write a program in c to print 1 121 12321 1234321 1234..

Answer / mohammedayub.y(c.i.e.t)

#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n,k;
printf("enter the number :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=n;k>i;k--)printf(" ");
for(j=1;j<=i;j++)
{
printf("%d",j);
}
if(i>1)
{
for(j=i;j>1;j--)
{
printf("%d",j-1);
}
}
printf("\n");
}

getch();
return 0;
}

Is This Answer Correct ?    72 Yes 28 No

Write a program in c to print 1 121 12321 1234321 1234..

Answer / sahil and dipanshu

#include<stdio.h>
#include<iostream.h>

int main()
{
int i,j,k,num;
num=5;
for(i=1;i<=num;i++)
{
for(j=1;j<num-i;j++)
{
cout<<" ";
}
for(k=1;k<=i;k++)
{
cout<<k;
}
for(k=i;k>1;k--)
{
cout<<k-1;
}
cout<<endl;
}
return 0;
}

Is This Answer Correct ?    21 Yes 8 No

Write a program in c to print 1 121 12321 1234321 1234..

Answer / sabby

#include<stdio.h>
main()
{
int i,j,s,n;
printf("Enter the number of rows:");
scanf("%d\n",&n);
for(i=1;i<=n;i++)
{
for(s=1;s<=n-i;s++)
printf(" ");
for(j=1;j<=i;j++)
printf("%d",j);
j=j-2;
for(;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
}
}

Is This Answer Correct ?    16 Yes 7 No

Write a program in c to print 1 121 12321 1234321 1234..

Answer / arun c s

#include <stdio.h>
main()
{
int i, j, k, space, n=9;

for (i=1; i<=n; i++)
{
for (j=1; j<=n-i; j++)
putchar(' ');
for (j=1,k=2*i-1; j<=2*i-1; j++,k--)
{
if (j <= k)
printf("%d", j);
else
printf("%d", k);
}
putchar('
');
}

getch();
}

Is This Answer Correct ?    4 Yes 3 No

Write a program in c to print 1 121 12321 1234321 1234..

Answer / 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

Write a program in c to print 1 121 12321 1234321 1234..

Answer / rahim

int i, j, k, num = 5;
cout << "number u1=";


cin >> num;
for (i = 1; i <= num; i++)
{
for (j = 1; j <= num - i; j++)
{
cout << " ";
}
for (k = 1; k < i; k++)
{
cout << k;

}
for (k = i; k >= 1; k--)
{
cout << k;
}

cout << endl;
}

//----------------------------------------
for (i = num; i >= 1; i--)
{
for (j = 1; j <= num - i; j++)
{
cout << " ";
}
for (k = 1; k < i; k++)
{
cout << k;

}
for (k = i; k >= 1; k--)
{
cout << k;
}

cout << endl;
}

Is This Answer Correct ?    1 Yes 1 No

Write a program in c to print 1 121 12321 1234321 1234..

Answer / smita adhikari

a = 1
FOR i = 1 TO 5
PRINT a * a
a = a * 10 + 1
NEXT i
END

Is This Answer Correct ?    1 Yes 1 No

Write a program in c to print 1 121 12321 1234321 1234..

Answer / roshan patil

#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,k,num;
cout<<num;
for(i=1;i<=num;i++)
{
for(j=1;j<num-1;j++)
{
cout<<" ";
}
for(k=1;k<i;k++)
{
cout<<k;
}
for(k=i;k>=1;k--)
{
cout<<k;
}
}
}

Is This Answer Correct ?    12 Yes 14 No

Write a program in c to print 1 121 12321 1234321 1234..

Answer / durai

int a, b;
for( a=1;i<=5;a++)
{
for(b=1;b<=(2*a-1);b++)
{ if(b<=a)
printf b;
else
printf(2*a-b);
}
printf
;
}

Is This Answer Correct ?    0 Yes 5 No

Write a program in c to print 1 121 12321 1234321 1234..

Answer / ayas kumar das

#include"stdio.h"
int main()
{
int i,j,n;
printf("enter the number :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
if(i>1)
{
for(j=i;j>1;)
{
printf("%d",j-1);
j=j-1;
}
}
printf("\n");
}
return 0;
}

Is This Answer Correct ?    12 Yes 20 No

Post New Answer

More C Interview Questions

What is union and structure in c?

0 Answers  


How will you write a code for accessing the length of an array without assigning it to another variable?

0 Answers  


Write a C program to check a number even or odd, without using any relational, arithmetic operator and any loops.

1 Answers  


Is the exit() function same as the return statement? Explain.

0 Answers   Agilent, ZS Associates,


Where are the auto variables stored?

0 Answers   TISL,






main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } what is the output?

7 Answers   AMCAT, HCL, Ramco, Zycus Infotech,


What is variable and explain rules to declare variable in c?

0 Answers  


which is the best antivirus and how to update it

7 Answers   Infosys,


Find occurence of a character in a sting.

3 Answers   TCS,


why return type of main is not necessary in linux

0 Answers   TCS,


the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

0 Answers  


What will happen when freeing memory twice

2 Answers  


Categories