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
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 |
Post New Answer View All Answers
What are global variables and how do you declare them?
How do you do dynamic memory allocation in C applications?
how can f be used for both float and double arguments in printf? Are not they different types?
shorting algorithmS
Explain how can type-insensitive macros be created?
What is the process to generate random numbers in c programming language?
What is dynamic dispatch in c++?
How to throw some light on the b tree?
What is file in c preprocessor?
int i=10; printf("%d %d %d", i, i=20, i);
Differentiate between new and malloc(), delete and free() ?
Difference between linking and loading?
What is preprocessor with example?
Is c++ based on c?
Are there any problems with performing mathematical operations on different variable types?