Professional Documents
Culture Documents
Programs To Print Triangles Using, Numbers and Characters
Programs To Print Triangles Using, Numbers and Characters
**
***
****
*****
Source Code
1. #include <stdio.h>
2. int main()
3. {
4. int i, j, rows;
5.
7. scanf("%d",&rows);
8.
10. {
12. {
14. }
15. printf("\n");
16. }
17. return 0;
18. }
Example 2: Program to print half pyramid a using numbers
12
123
1234
12345
Source Code
1. #include <stdio.h>
2. int main()
3. {
4. int i, j, rows;
5.
7. scanf("%d",&rows);
8.
10. {
12. {
14. }
15. printf("\n");
16. }
17. return 0;
18. }
Example 3: Program to print half pyramid using alphabets
BB
CCC
DDDD
EEEEE
Source Code
1. #include <stdio.h>
2. int main()
3. {
4. int i, j;
6.
7. printf("Enter the uppercase character you want to print in last row: ");
8. scanf("%c",&input);
9.
11. {
12. for(j=1;j<=i;++j)
13. {
15. }
16. ++alphabet;
17.
18. printf("\n");
19. }
20. return 0;
21. }
*****
****
***
**
Source Code
1. #include <stdio.h>
2. int main()
3. {
4. int i, j, rows;
5.
7. scanf("%d",&rows);
8.
10. {
12. {
14. }
15. printf("\n");
16. }
17.
18. return 0;
19. }
12345
1234
123
12
Source Code
1. #include <stdio.h>
2. int main()
3. {
4. int i, j, rows;
5.
7. scanf("%d",&rows);
8.
10. {
12. {
14. }
15. printf("\n");
16. }
17.
18. return 0;
19. }
***
*****
*******
*********
Source Code
1. #include <stdio.h>
2. int main()
3. {
5.
7. scanf("%d",&rows);
8.
10. {
12. {
14. }
15.
19. ++k;
20. }
21.
22. printf("\n");
23. }
24.
25. return 0;
26. }
232
34543
4567654
567898765
Source Code
1. #include <stdio.h>
2. int main()
3. {
5.
7. scanf("%d",&rows);
8.
9. for(i=1; i<=rows; ++i)
10. {
12. {
14. ++count;
15. }
16.
18. {
20. {
22. ++count;
23. }
24. else
25. {
26. ++count1;
28. }
29. ++k;
30. }
32.
33. printf("\n");
34. }
35. return 0;
36. }
*********
*******
*****
***
Source Code
1. #include<stdio.h>
2. int main()
3. {
5.
7. scanf("%d",&rows);
8.
10. {
13.
16.
19.
20. printf("\n");
21. }
22.
23. return 0;
24. }
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Source Code
1. #include <stdio.h>
2. int main()
3. {
5.
7. scanf("%d",&rows);
8.
10. {
11. for(space=1; space <= rows-i; space++)
13.
15. {
17. coef = 1;
18. else
20.
22. }
23. printf("\n");
24. }
25.
26. return 0;
27. }
23
456
7 8 9 10
Source Code
1. #include <stdio.h>
2. int main()
3. {
4. int rows, i, j, number= 1;
5.
7. scanf("%d",&rows);
8.
10. {
12. {
14. ++number;
15. }
16.
17. printf("\n");
18. }
19.
20. return 0;
21. }