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
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 |
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 |
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 |
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 |
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 |
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 |
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 |
design and implement a program that reads floating-points numbers in a sentinel-controlled loop until the user terminates the program by entering zero.your program should determinate and print the smallest,largest and average of the supplied numbers.
What is %g in c?
Heyyy All, Just a challenge . A C program with if Else if(){ /// insert sumthing print ("in if") // insert sumting } else { ///// insert sumthing print ("in else"); //// insert sumthing } can anyone modify it so that program prints. if and else both
What does it mean when the linker says that _end is undefined?
Explain the difference between null pointer and void pointer.
Program to find the absolute value of given integer using Conditional Operators
What is function prototype?
A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor
i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none
main() { enum{red,green,blue=6,white}; pf("%d%d%d%d", red,green,blue,white); return 0; } a)0 1 6 2 b)0 1 6 7 c)Compilation error d)None of the above
What are different storage class specifiers in c?
How does the assert() function work?