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
Write a c program to build a heap method using Pointer to function and pointer to structure ?
Difference between pass by reference and pass by value?
What is a function in c?
Are the expressions * ptr ++ and ++ * ptr same?
What does malloc () calloc () realloc () free () do?
How can I copy just a portion of a string?
What is the purpose of void pointer?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
What is "Hungarian Notation"?
provide an example of the Group by clause, when would you use this clause
What are the features of c language?
Why do we use main function?
What are the c keywords?
What is wrong with this program statement? void = 10;
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.