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


Please Help Members By Posting Answers For Below Questions

What does static variable mean in c?

646


What is the difference between procedural and declarative language?

643


Is c is a low level language?

559


What do you mean by invalid pointer arithmetic?

637


What are the header files used in c language?

583






How would you use the functions fseek(), freed(), fwrite() and ftell()?

699


Why doesnt long int work?

606


What does 4d mean in c?

938


Who invented b language?

911


write a program for the normal snake games find in most of the mobiles.

1783


What is boolean in c?

603


What are the applications of c language?

621


What does the error message "DGROUP exceeds 64K" mean?

723


What is the difference between malloc calloc and realloc in c?

643


What is the purpose of main() function?

648