Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)
12345
1234
123
12
1
Ans.
/*c program for number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(; num>=1; num--)
for(; num>=1; num--)
{
for(c=1; c<=num; c++)
printf("%d",c);
printf("\n");
}
getch();
getch();
return 0;
}
/****************OUTPUT***********
Enter loop repeat number(rows): 5
********************************/
/****************OUTPUT***********
Enter loop repeat number(rows): 5
12345
1234
123
12
1
********************************/
Use this,
ReplyDelete#include
#include
#include
void main()
{
int a,b=0,c=0,d=0;
clrscr();
scanf("%d",&a);
while(a>10)
{
b=a%10;
c=a-b;
d=c/10;
printf("%d\n",d);
a=d;
}
getch();
}
wap to print
ReplyDelete12345
1234
123
12
1
#include
int main()
{
int i,j,n=1;
for(i=1; i<=5; i++)
{
for(j=1;j<=6-i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}