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

Do you know the difference between exit() and _exit() function in c?

610


Why we use break in c?

553


What is call by reference in functions?

571


What is the meaning of ?

623


An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode

610






What are the application of c?

651


What are comments and how do you insert it in a C program?

743


How many loops are there in c?

583


#include { printf("Hello"); } how compile time affects when we add additional header file .

1425


How is a structure member accessed?

586


What is the difference between new and malloc functions?

581


What is the 'named constructor idiom'?

641


What is the size of enum in c?

624


What is the purpose of & in scanf?

599


Explain bitwise shift operators?

633