Q. Write a C program to print the following number triangle.
or
Q. Write a C program to display the following number pyramid.
1
222
33333
4444444
555555555
Ans.
/*c program for number pyramid*/
#include < stdio.h >
#include < conio.h >
int main()
{
int num,r,c,k,sp;
printf( "Enter number of rows : " );
scanf( "%d" , & num);
for(r=1; r<=num; r++)
{
for(sp=num-r; sp>0; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf( "%d" , r);
for(k=2; k<=r; k++)
printf( "%d" , r);
printf( "\n" );
}
getch();
return 0 ;
}
GenTech Foundation
Inspire the Best................
Thursday, January 7, 2016
Prymaid
Design numbers rectangle structure
Q. Write a program to generate a following numbers structure:
(Where user entered number through keyboard, for example if num=5)
55555
44444
33333
22222
11111
Ans.
/* c program for number structure*/
#include < stdio.h >
#include < conio.h >
int main()
{
int num,r,c;
printf( "Enter loop repeat number(rows): " );
scanf( "%d" , &num);
for(r=num; r>=1; r--)
{
for(c=num; c>=1; c--)
printf( "%d" ,r);
printf( "\n" );
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
55555
44444
33333
22222
11111
***********************************/
Subscribe to:
Posts (Atom)