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
Answer Posted / 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 |
Post New Answer View All Answers
What is the use of a static variable in c?
Is there anything like an ifdef for typedefs?
What does #pragma once mean?
How can I implement sets or arrays of bits?
What is a stream?
Why does everyone say not to use scanf? What should I use instead?
What does return 1 means in c?
Tell us two differences between new () and malloc ()?
What is hash table in c?
What is difference between structure and union?
diff between exptected result and requirement?
What is the use of header files?
What is #line in c?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
What is the easiest sorting method to use?