Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)
123454321
2345432
34543
454
5
Ans.
/* c program for number structure */
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c,sp;
printf("Enter loop repeat number : ");
scanf("%d",&num);
for(r=1; r<=num; r++)
{
for(sp=r; sp>1; sp--)
printf(" ");
for(c=r; c<=num; c++)
printf("%d",c);
for(c=num-1; c>=r; c--)
printf("%d",c);
printf("\n");
}
getch():
return 0;
}
case1:
Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)
123454321
1234321
12321
121
1
Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r=1,c,sp,x;
printf("Enter loop repeat number(rows):");
scanf("%d",&num);
for(; num>=1; num--,r++)
{
for(sp=r; sp>1; sp--)
printf(" ");
for(c=1; c<=num; c++)
printf("%d",c);
for(x=num-1; x>=1; x--)
printf("%d",x);
printf("\n");
}
getch();
return 0;
}
case2:
17. Design numbers tringle pyramid
Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)
1
121
12321
1234321
123454321
Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c,sp,x;
printf("Enter loop repeat number(rows):");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("%d",c);
for(x=r-1; x>=1; x--)
printf("%d",x);
printf("\n");
}
getch():
return 0;
}
/****************OUTPUT***************
Enter loop repeat number(rows): 5
1
121
12321
1234321
123454321
case3:
16. Design numbers tringle pyramid
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 pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r=1,c,sp;
printf("Enter loop repeat number(rows):");
scanf("%d",&num);
for(; num>=1; num--,r++)
{
for(sp=r; sp>1; sp--)
printf(" ");
for(c=1; c<=num; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/****************OUTPUT***********
Enter loop repeat number(rows): 5
12345
1234
123
12
1
********************************/
case4:
15. Design numbers tringle pyramid
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(c=1; c<=num; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/****************OUTPUT***********
Enter loop repeat number(rows): 5
12345
1234
123
12
1
********************************/
case5:
14. Design numbers tringle pyramid
Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)
1
21
321
4321
54321
Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,c,r;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(c=r; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5
1
21
321
4321
54321
************************************/
case6:
13. Design numbers tringle pyramid
Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)
54321
4321
321
21
1
Ans.
/*c program for number triangle pyramid*/
#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(c=num; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5
54321
4321
321
21
1
************************************/
case7:
12. Design numbers tringle pyramid
Q. Write a program to generate a following numbers triangle:
(Where user entered number through keyboard, for example if num=5).
1
12
123
1234
12345
Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c,sp;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5
1
12
123
1234
12345
************************************/
case8:
11.Design numbers tringle pyramid
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 pyramid*/
#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(c=1; c<=num; c++)
printf("%d",c);
printf("\n");
}
return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5
12345
1234
123
12
1
*********************************/
case9:
9.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)
11111
22222
33333
44444
55555
Ans.
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(c=num; c>=1; c--)
printf("%d",r);
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5
11111
22222
33333
44444
55555
************************************/
case10:
10. Design numbers tringle pyramid
Q. Write a program to generate a following numbers triangle:
(Where user entered number through keyboard, for example if num=5)
1
12
123
1234
12345
Ans.
/* c program for number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
1
12
123
1234
12345
***********************************/
case11:
8.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
***********************************/
case12:
7.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)
54321
54321
54321
54321
54321
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(c=5; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
54321
54321
54321
54321
54321
***********************************/
case13:
6.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)
12345
12345
12345
12345
12345
Ans.
/* c program for number rectangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(c=1; c<=num; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
12345
12345
12345
12345
12345
***********************************/
case14:
4.Design triangle pyramid
Q. Write a program to generate a following #'s triangle?
#
##
###
####
#####
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(c=1; c<=r; c++)
printf("#");
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
#
##
###
####
#####
***********************************/
case15:
5.Design triangle pyramid
Q. Write a program to generate a following @'s triangle?
@
@@
@@ @
@@@@
@@ @@ @
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c,sp;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("@");
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
@
@@
@@@
@@@@
@@@@@
***********************************/
case16:
3.Design triangle pyramid
Q. Write a program to generate a following @'s triangle?
@@ @@ @
@@ @@
@@ @
@@
@
Ans.
/* c program for symbol 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(c=1; c<=num; c++)
printf("@");
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
@@@@@
@@@@
@@@
@@
@
***********************************/
case17:
2. Design triangle pyramid
Q. Write a program to generate a following #'s triangle?
#####
####
###
##
#
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r=1,c,sp;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(; num>=1; num--,r++)
{
for(sp=r; sp>1; sp--)
printf(" ");
for(c=1; c<=num; c++)
printf("#");
printf("\n");
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
#####
####
###
##
#
***********************************/
case18:
1. Design rectangle pyramid
Q. Write a program to generate a following structure?
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
Ans.
/* c program for symbol structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
{
for(c=1; c<=num; c++)
printf("@");
printf("\n");
}
getch();
return 0;
}
/************* OUTPUT **************
Enter loop repeat number(rows): 5
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
***********************************/
case19:
Q. Write a c program for following number structure :
1
22
333
4444
55555
4444
333
22
1
Ans.
/*c program for above triangle structure using while*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,r=1,c;
printf("Enter triangle number : ");
scanf("%d",&num);
while(num >= r)
{
c=1;
while(c <= r)
{
printf("%d",r);
c++;
}
printf("\n");
r++;
}
n=num-1;
while(n >= 1)
{
c=1;
while(c <= n)
{
printf("%d",n);
c++;
}
printf("\n");
n--;
}
getch();
return 0;
}
OR
/*c program for above number triangle using for loop*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,r,c;
printf("Enter triangle number : ");
scanf("%d",&num);
for(r=1; r<=num; r++)
{
for(c=1; c<=r; c++)
printf("%d",r);
printf("\n");
}
for(n=num-1; n>=1; n--)
{
for(c=1; c<=n; c++)
printf("%d",n);
printf("\n");
}
return 0;
}
Output :-
Enter triangle number :5
1
22
333
4444
55555
4444
333
22
1
case20:
Pyramid triangle
Q. Write a C program for following structure:
9
0 1
2 3 4
5 6 7 8
9 0 1 2 3
Ans.
/*c program for triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int i,c,r,x=0,n=4;
printf("9\n");
for(r=1; n>=r; r++)
{
for(c=0; c<=r; c++,x++)
{
if(x<10)
printf("%d ",x);
else
{
for(i=0; i<=3; i++)
printf("%d ",i);
break;
}
}
printf("\n");
}
getch();
return 0;
}
case21;
Q. Write a C program to print the following number triangle:
1
12
123
1234
12345
1234
123
12
1
Ans.
/*c program for print the number pyramid as specific given design*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,n;
printf("Enter loop repeat number(rows): ");
scanf("%d", &n);
for(r=1; r<=n; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
printf("\n");
}
for(r=n; r>1; r--,n--)
{
for(c=1; c<n; c++)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
case22:
Q. Write a C program to print the following number structure:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
Ans.
/*c program for print the following number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,sp,n=6;
for(r=1; r<=6; r++)
{
for(sp=1; sp<=n; sp++)
printf(" ");
for(c=1; c<=r; c++)
{
printf("%d",r);
printf(" ");
}
printf("\n");
n=n-1;
}
getch();
return 0;
}
case23:
Q. Write a C program to print the following number triangle or number structure:
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9
Ans.
/*c program for above number triangle codes*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,sp,num;
printf("Enter loop repeat number(rows): ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=1; sp<=num-r; sp++)
printf(" "); //it is 2 blank space
for(c=1; c<=2*r-1; c++)
printf(" %d",c);
printf("\n");
}
getch();
return 0;
}
case24:
Q. Write a C program to print the following number structure:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
Ans.
/*c program to print the above number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,sp,num;
printf("Enter loop repeat number(rows): ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=num; sp>=r; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf(" %d", c);
printf("\n");
}
getch();
return 0;
}
case25:
Q. Write a C program to display the following number structure:
1234554321
1234__4321
123____321
12______21
1________1
Ans.
/* c program for number rectangle or number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,c,sp,r=1;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
printf("\n");
for(; num>=1; num--,r++)
{
for(c=1; c<=num; c++)
printf("%d",c);
for(sp=r; sp>1; sp--)
printf("_");
for(sp=r; sp>1; sp--)
printf("_");
for(c=num; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
case26:
Q. Write a C program to print the following number triangle or structure:
1
21
321
4321
54321
Ans.
/*c program code for number pyramid*/
#include<stdio.h>
int main()
{
int num,r,c,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=r; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
case27:
Q. Write a C program to print the following number pyramid:
54321
4321
321
21
1
Ans.
/*c program code for number triangle*/
#include<stdio.h>
int main()
{
int num,r,c,sp;
printf("Enter number of rows: ");
scanf("%d", &num);
for(r=1; r<=5; r++,num--)
{
for(sp=r; sp>1; sp--)
printf(" ");
for(c=num; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGet this output using simple loops. Here no of iterations are
ReplyDeleteimportant.
zyxwvwxyz
zyxwxyz
zyxyz
zyz
z
void main()
Delete{
int i,j;
clrscr();
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
printf("%c ",123-j);
for(j-=2;j>=1;j--)
printf("%c ",123-j);
printf("\n");
}
getch();
}
Pls send me a code
DeleteThis comment has been removed by the author.
ReplyDeletei need to get 1
ReplyDelete12
123
please help me
123456789987654321
ReplyDelete12345678 87654321
1234567 7654321
123456 654321
12345 54321
1234 4321
123 321
12 21
1 1