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


Please Help Members By Posting Answers For Below Questions

What is the use of a static variable in c?

801


Is there anything like an ifdef for typedefs?

910


What does #pragma once mean?

931


How can I implement sets or arrays of bits?

822


What is a stream?

884


Why does everyone say not to use scanf? What should I use instead?

1084


What does return 1 means in c?

819


Tell us two differences between new () and malloc ()?

845


What is hash table in c?

783


What is difference between structure and union?

877


diff between exptected result and requirement?

1817


What is the use of header files?

833


What is #line in c?

779


main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }

1174


What is the easiest sorting method to use?

837