print the following using nested for loop.
5 4 3 2 1
1 2 3 4
3 2 1
1 2
1
2 1
1 2 3
4 3 2 1
1 2 3 4 5

Answers were Sorted based on User's Feedback



print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 ..

Answer / anand.dayalan@gmail.com

#include<stdio.h>
#include<conio.h>

void main()
{
for(int i=1; i<=2; i++)
for(int j=(i==1)?1:2;j<=5;j++)
{
for(int k = (j%2==1 && i==1)? 5 + 1 -j: (j%2==0 && i==2)?
j:1; (j%2==1 && i==1)? k>=1: (j%2==0 && i==2)? k>=1:(j%2==0
&& i==1)?k<=5 + 1 -j:k<=j ;(j%2==1 && i==1)? k--: (j%2==0 &&
i==2)? k--:k++)
printf("%d", k);
printf("\n");
}
}

Is This Answer Correct ?    4 Yes 1 No

print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 ..

Answer / dally

#include<stdio.h>

int main()
{
int i,j,n=5;

for(i=n;i>=1;i--)
{
if(i%2 == 0){
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
else
{
for(j=i;j>=1;j--)
printf("%d",j);
printf("\n");
}
}
for(i=2;i<=5;i++)
{
if(i%2 != 0) {
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
else
{
for(j=i;j>=1;j--)
printf("%d",j);
printf("\n");
}
}
}

Is This Answer Correct ?    3 Yes 0 No

print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 ..

Answer / vignesh1988i

this is the correct logic..... some syntax mistakes was done
befoe ... nowq it's correct.... thank you

#include<stdio.h>
#include<conio.h>
void logic1(int,int);
void logic2();
void logic3();
void logic4();
int a=0;
void main()
{
int m;
printf("enter the number of lines :");
scanf("%d",&m);
for(int i=1;i<=(m/2+1);i++)
{
printf("\n");
if(i%2!=0)
logic1(i,m);
else
logic2();
}
for(i=1;i<=m/2;i++)
{
printf("\n");
if(i%2!=0)
logic3();
else
logic4();
}
getch();
}
void logic1(int p,int m)
{
a=(m/2+2)-p;
for(int i=a;i>=1;i--)
printf("%d",i);
}
void logic2();
{
a--;
for(int i=1;i<=a;i++)
printf("%d",i);
}
void logic3()
{
a++;
for(int i=a;i>=1;i++)
printf("%d",i);
}
void logic4()
{
a++;
for(int i=1;i<=a;i++)
printf("%d",i);
}

Is This Answer Correct ?    3 Yes 3 No

print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 ..

Answer / harsha

#include<stdio.h>
#include<conio.h>

void main()
{
int i,j;
clrscr();

for(i=5;i>1;i=i-2)
{
for(j=i;j>=1;j--)
printf("%d",j);

printf("\n");

for(j=1;j<i;j++)
printf("%d",j);

printf("\n");
}
printf("1");
for(i=2;i<=5;i=i+2)
{
printf("\n");

for(j=i;j>=1;j--)
printf("%d",j);

printf("\n");

for(j=1;j<=i+1;j++)
printf("%d",j);
}

getch();
}

Is This Answer Correct ?    0 Yes 0 No

print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 ..

Answer / vignesh1988i

i have used functions.... i got this logic.

#include<stdio.h>
#include<conio.h>
void logic1(int);
void logic2();
void logic3();
void logic4();
int a=0;
void main()
{
int m;
printf("enter the number of lines :");
scanf("%d",&m);
for(int i=1;i<=(m/2+1);i++)
{
printf("\n");
if(i%2!=0)
logic1(i);
else
logic2();
}
for(i=1;i<=m/2;i++)
{
printf("\n");
if(i%2==0)
logic3();
else
logic4();
}
getch();
}
void logic1(int p)
{
a=(m/2+2)-p;
for(int i=a;i>=1;i--)
printf("%d",i);
}
void logic2();
{
a--;
for(int i=1;i<=a;i++)
printf("%d",i);
}
void logic3()
{
a++;
for(int i=a;i>=1;i++)
printf("%d",i);
}
void logic4()
{
a++;
for(int i=1;i<=a;i++)
printf("%d",i);
}

Is This Answer Correct ?    0 Yes 3 No

print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 ..

Answer / vignesh1988i

DIFFERENT LOGIC

#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,p;
printf("enter the limit value");
scanf("%d",&m);
n=m+1;
for(int i=1;i<2*m-1;i++)
{
if(i<=m)
{
n--;
p=0;
}
else
{
n++
p=1;
}
if(i%2==p)
{
for(int j=1;j<n;j++)
printf("%d",j);
}
else
{
for(j=n;j>=1;j--)
printf("%d",j);
}
}
getch();
}

Is This Answer Correct ?    0 Yes 3 No

print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 ..

Answer / sravanthi

I DONT KNOW THE ANSWER
CAN ANY ONE TELL ME HOW TO GET OUTPUT AS
1
01
101
0101
10101.
in NESTED FOR LOOP ONLY
PLEASE ANSWER ME

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More C Interview Questions

how to print 212 as Twohundreds twelve plz provide me ans soon

1 Answers  


What is the difference between int main and void main?

0 Answers  


what is op? for(c=0;c=1000;c++) printf("%c",c);

21 Answers   Trigent,


progrem to generate the following series 1 12 123 1234 12345

6 Answers   HCL, Wipro,


main() { int a[3][4] ={1,2,3,4,5,6,7,8,9,10,11,12} ; int i, j , k=99 ; for(i=0;i<3;i++) for(j=0;j<4;j++) if(a[i][j] < k) k = a[i][j]; printf("%d", k); }

4 Answers   Vector, Wipro, Zoho,


if a person is buying coconuts of Rs10,and then sell that coconuts of Rs9,with the loss of one rupee.After that the person became a millaniore.how?

9 Answers   Wipro,


what is the use of using linked list and array?

10 Answers   Infosys, TCS,


What is signed and unsigned?

0 Answers  


What is register variable in c language?

0 Answers  


What is difference between structure and union in c?

0 Answers  


1 1 2 1 2 3 1 2 3 4 1 2 3 1 2 1 generate this output using for loop

2 Answers  


What is that continue statement??

4 Answers  


Categories