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 does static variable mean in c?
What is the difference between procedural and declarative language?
Is c is a low level language?
What do you mean by invalid pointer arithmetic?
What are the header files used in c language?
How would you use the functions fseek(), freed(), fwrite() and ftell()?
Why doesnt long int work?
What does 4d mean in c?
Who invented b language?
write a program for the normal snake games find in most of the mobiles.
What is boolean in c?
What are the applications of c language?
What does the error message "DGROUP exceeds 64K" mean?
What is the difference between malloc calloc and realloc in c?
What is the purpose of main() function?