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



SIR PLS TELL ME THE CODE IN C LANGUAGE TO PRINT THE FOLLOWING SERIES 1 1 2 1 ..

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

SIR PLS TELL ME THE CODE IN C LANGUAGE TO PRINT THE FOLLOWING SERIES 1 1 2 1 ..

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

SIR PLS TELL ME THE CODE IN C LANGUAGE TO PRINT THE FOLLOWING SERIES 1 1 2 1 ..

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

SIR PLS TELL ME THE CODE IN C LANGUAGE TO PRINT THE FOLLOWING SERIES 1 1 2 1 ..

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

Post New Answer

More C Interview Questions

Can a pointer point to null?

0 Answers  


What is use of #include in c?

0 Answers  


Explain what is wrong with this program statement?

0 Answers  


how to write a prog in c to convert decimal number into binary by using recursen function,

1 Answers  


I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

0 Answers  






What is the difference between %d and %*d in C

3 Answers  


34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?

3 Answers  


What is scope and lifetime of a variable in c?

0 Answers  


Difference between Shallow copy and Deep copy?

0 Answers  


What is scope rule of function in c?

0 Answers  


what is the little endian and big endian?

1 Answers  


What is the difference b/w Structure & Union?

3 Answers  


Categories