1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1
generate this output using for loop
Answer Posted / narasimharao
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,n;
printf("Enter n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=i;k<n;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("%d",j);
for(k=i;k<i+1;k++)
{
printf(" ");
}
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(k=i;k<n;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("%d",j);
for(k=i;k<i+1;k++)
{
printf(" ");
}
}
printf("\n");
}
getch();
}
| Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
What is a null pointer in c?
Which is better malloc or calloc?
What are qualifiers?
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant
What is dynamic variable in c?
How can I do graphics in c?
What are linker error?
What is typedef example?
How do you write a program which produces its own source code as output?
What does == mean in texting?
What is property type c?
What is a header file?
how to count no of words,characters,lines in a paragraph.
using only #include
What are different types of operators?