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 |
Are there namespaces in c?
Would you rather wait for the results of a quicksort, a linear search, or a bubble sort on a 200000 element array? 1) Quicksort 2) Linear Search 3) Bubble Sort
what is difference between array,strutter,union and pointers
3 Answers CTS, Lovely Professional University, Mannar Company,
What math functions are available for integers? For floating point?
program for following output using for loop? 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
What will happen when freeing memory twice
Explain what is the most efficient way to store flag values?
What is the use of a ‘