w3ajay

tally tutorial point, ms word 2013, ms excel 2013, ms powerpoint 2010,ccc question with answer in hindi 2021, Tally Prime in hindi , tally prime,Python,in python,programming in python,python

Monday, December 16, 2019

code for pyramid in c language in Hindi

code for pyramid in c language in Hindi

Program to print half pyramid using *



*
* *
* * *
* * * *
* * * * *
  1. #include<stdio.h>
  2. #include<stdio.h>
  3. int main() {
  4. int i, j, rows;
  5. clrscr();
  6. printf("Enter number of rows: ");
  7. scanf("%d", &rows);
  8. for (i=1; i<=rows; ++i)
  9. {
  10. for (j=1; j<=i; ++j)
  11. {
  12. printf("* ");
  13. }
  14. printf("\n");
  15. }
  16. getch();
  17. }

Program to print half pyramid a using numbers

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Source Code
  1. #include<stdio.h>
  2. int main() {
  3. int i,j,rows;
  4. printf("Enter number of rows: ");
  5. scanf("%d", &rows);
  6. for (i=1; i<=rows; ++i) {
  7. for (j=1; j<=i; ++j)
  8. { printf("%d ",j); }
  9. printf("\n");
  10. }
  11. return 0;
  12. }

Program to print half pyramid using alphabets

A
B B
C C C
D D D D
E E E E E
Source Code
  1. #include<stdio.h>
  2. int main() {
  3. int i, j;
  4. char input, alphabet='A';
  5. printf("Enter the uppercase character you want to print in last row: ");
  6. scanf("%c", &input);
  7. for (i=1; i<=(input-'A'+1); ++i) {
  8. for (j=1; j<=i; ++j)
  9. { printf("%c", alphabet); }
  10. ++alphabet;
  11. printf("\n");
  12. }
  13. return 0;
  14. }

Programs to print inverted half pyramid using * and numbers

Inverted half pyramid using *

* * * * *
* * * *
* * * 
* *
*
Source Code
  1. #include<stdio.h>
  2. int main() {
  3. int i, j, rows;
  4. printf("Enter number of rows: ");
  5. scanf("%d", &rows);
  6. for (i=rows; i>=1; --i) {
  7. for (j=1; j<=i; ++j)
  8. { printf("* "); }
  9. printf("\n");
  10. }
  11. return 0;
  12. }

Inverted half pyramid using numbers

1 2 3 4 5
1 2 3 4 
1 2 3
1 2
1
Source Code
  1. #include<stdio.h>
  2. int main() {
  3. int i ,j, rows;
  4. printf("Enter number of rows: ");
  5. scanf("%d", &rows);
  6. for (i=rows; i>=1; --i) {
  7. for (j=1; j<=i; ++j)
  8. { printf("%d ",j); }
  9. printf("\n");
  10. }
  11. return 0;
  12. }

Programs to display pyramid and inverted pyramid using * and digits

Program to print full pyramid using *

        *
      * * *
    * * * * *
  * * * * * * *
* * * * * * * * *
Source Code
  1. #include<stdio.h>
  2. int main() {
  3. int i, space, rows, k=0;
  4. printf("Enter number of rows: ");
  5. scanf("%d", &rows);
  6. for (i=1; i<=rows; ++i,k=0) {
  7. for (space=1; space<=rows-i; ++space)
  8. { printf(" "); }
  9. while (k!=2*i-1) {
  10. printf("* ");
  11. ++k;
  12. }
  13. printf("\n");
  14. }
  15. return 0;
  16. }

Program to print pyramid using numbers

        1
      2 3 2
    3 4 5 4 3
  4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
Source Code
  1. #include<stdio.h>
  2. int main() {
  3. int i, space, rows, k=0, count=0, count1=0;
  4. printf("Enter number of rows: ");
  5. scanf("%d", &rows);
  6. for (i=1; i<=rows; ++i) {
  7. for (space=1; space<=rows-i; ++space) {
  8. printf(" ");
  9. ++count;
  10. }
  11. while (k!=2*i-1) {
  12. if (count <= rows-1)
  13. { printf("%d ", i+k);
  14. ++count;
  15. }
  16. else {
  17. ++count1;
  18. printf("%d ", (i+k-2*count1));
  19. }
  20. ++k;
  21. }
  22. count1=count=k=0;
  23. printf("\n");
  24. }
  25. return 0;
  26. }

Inverted full pyramid using *

* * * * * * * * *
  * * * * * * *
    * * * * *
      * * *
        *
Source Code
  1. #include<stdio.h>
  2. int main() {
  3. int rows, i, j, space;
  4. printf("Enter number of rows: ");
  5. scanf("%d", &rows);
  6. for (i=rows; i>=1; --i) {
  7. for (space=0; space<rows-i; ++space)
  8. printf(" ");
  9. for (j=i; j<=2*i-1; ++j)
  10. printf("* ");
  11. for (j=0; j<i-1; ++j)
  12. printf("* ");
  13. printf("\n");
  14. }
  15. return 0;
  16. }

Print Pascal's triangle

           1
         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. int rows, coef=1, space, i, j;
  4. printf("Enter number of rows: ");
  5. scanf("%d", &rows);
  6. for (i=0; i<rows; i++) {
  7. for (space=1; space <= rows-i; space++)
  8. printf(" ");
  9. for (j=0; j<=i; j++) {
  10. if (j==0 || i==0)
  11. coef = 1;
  12. else
  13. coef=coef*(i-j+1)/j;
  14. printf("%4d", coef);
  15. }
  16. printf("\n");
  17. }
  18. return 0;
  19. }

Print Floyd's Triangle.

1
2 3
4 5 6
7 8 9 10
Source Code
  1. #include<stdio.h>
  2. int main() {
  3. int rows, i, j, number= 1;
  4. printf("Enter number of rows: ");
  5. scanf("%d", &rows);
  6. for (i=1; i<=rows; i++) {
  7. for (j=1; j<=i; ++j)
  8. { printf("%d ", number);
  9. ++number;
  10. }
  11. printf("\n");
  12. }
  13. return 0;
  14. }

No comments:

Post a Comment

for more information please share like comment and subscribe