SIR PLS TELL ME THE CODE IN C LANGUAGE TO PRINT THE
FOLLOWING SERIES
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Answers were Sorted based on User's Feedback
Answer / sakthivel
/*
Written By : Sakthivel
Tested By : Rajavelraj
*/
#include<stdio.h>
#include<conio.h>
public void main()
{
int i,j,k,l,a=1;
for(i=1;i<=4;i++)
{
for(j=4;j>i;j--)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("%d",k);
}
for(l=i;l>1;l--)
{
printf("%d",l-1);
}
printf("\n");
}
for(i=4;i>1;i--)
{
for(j=1;j<=a;j++)
{
printf(" ");
}
for(k=1;k<i;k++)
{
printf("%d",k);
}
for(l=k-1;i>1;l--)
{
printf("%d",l-1);
}
a=a+1;
printf("\n");
}
getch();
}
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / vidyullatha
#include<stdio.h>
main()
{
int i,j,k,l;
int space=3;
int cnt = 1;
int track=1;
for(i=0;i<4;i++)
{
for(j=1;j<=space;j++)
{
printf(" ");
}
for(k=1;k<=cnt;k++)
{
printf("%d ",k);
}
for(l=k-1;l<track;l++)
{
printf("%d ",track-l);
}
space--;
cnt++;
track=track+2;
printf("\n");
}
space=1;
cnt=3;
track=5;
for(i=0;i<3;i++)
{
for(j=1;j<=space;j++)
{
printf(" ");
}
for(k=1;k<=cnt;k++)
{
printf("%d ",k);
}
for(l=k-1;l<track;l++)
{
printf("%d ",track-l);
}
space++;
cnt--;
track=track-2;
printf("\n");
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / shobha
To Print it in linear fashion:
#include <stdio.h>
main()
{
//1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1
int i =0,j =0,k=0 ;
for(i =1; i<=4; i++)
{
for (j=1;j<=i;j++ )
printf("%d ",j);
for(j=i-1;j>=1;j--)
printf("%d ",j);
}
i--;
for(k = i-1;k >= 1;k--)
{
for (j=1;j<=k;j++ )
printf("%d ",j);
for(j=k-1;j>=1;j--)
printf("%d ",j);
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sho
#include <stdio.h>
main()
{
int i =0,j =0,k=0,l=0;
for(i =1; i<=4; i++)
{
l= 4-i;
while(l-- > 0)
{
printf(" ");
}
for (j=1;j<=i;j++ )
printf("%d ",j);
for(j=i-1;j>=1;j--)
printf("%d ",j);
printf("\n");
}
i--;
for(k = i-1;k >= 1;k--)
{
l= 4-k;
while(l-- > 0)
{
printf(" ");
}
for (j=1;j<=k;j++ )
printf("%d ",j);
for(j=k-1;j>=1;j--)
printf("%d ",j);
printf("\n");
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
what is the output of the below code? main( ) { printf ( "\nOnly stupids use C?" ) ; display( ) ; } display( ) { printf ( "\nFools too use C!" ) ; main( ) ; }
What is Generic pointer? What is the purpose of Generic pointer? Where it is used?
implement general tree using link list
Explain the importance and use of each component of this string: Foo.Bar, Version=2.0.205.0, Culture=neutral, PublicKeyToken=593777ae2d274679d
wat is the meaning of c?
Explain what does a function declared as pascal do differently?
convert 0.9375 to binary
How can I read and write comma-delimited text?
What is volatile c?
If I want to initialize the array like. int a[5] = {0}; then it gives me all element 0. but if i give int a[5] = {5}; then 5 0 0 0 0 is ans. what will I do for all element 5 5 5 5 5 in a single statement???
related to rdbms query .
what is the disadvantage of using macros?