Chapter:
1. C program to print following Pyramid:
*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*
#includeint main() { int i,n,j; int space=4; printf("Enter number of rows:\n"); fflush(stdout); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=0;j<(n-i);j++) { printf(" "); } for(j=1;j<=2*i-1;j++) { if(j%2!=0) { printf("*"); } else { printf(" "); } } printf("\n"); } for (i=n;i>=1;i--) { for (j=1;j<=(n-i);j++) { printf(" "); } for (j=1;j<=2*i-1;j++) { if (j%2!=0) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0; }
2. Program to print full pyramid using *
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
Source Code
#includeint main() { int i, j, rows, k=0; printf("Enter number of rows: "); fflush(stdout); scanf("%d", &rows); for (i=1; i<=rows; i++,k=0) { for (j=1; j<=rows-i; j++) { printf(" "); } while (k!=2*i-1) { printf("* "); k++; } printf("\n"); } return 0; }
3. C program to Print Pascal's triangle
4. C program to print following Pyramid:
*****
****
***
**
*
#includeint main() { int i,j,n; printf("Enter the number of rows:\n"); scanf("%d",&n); for(i=n-1; i>=0; i--) { for(j=0;j<=i;j++) { printf("*"); } printf("\n"); } return 0; }
5. Inverted full pyramid using *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
#includeint main() { int rows, i, j; printf("Enter number of rows: "); fflush(stdout); scanf("%d", &rows); for (i=rows; i>=1; --i) { for (j=0; j
6. C Program to Print Floyd's Triangle.
1
2 3
4 5 6
7 8 9 10
#includeint main() { int rows, i, j, number= 1; printf("Enter number of rows:\n"); fflush(stdout); scanf("%d", &rows); for (i=1; i<=rows; i++) { for (j=1; j<=i; j++) { printf("%d ", number); number++; } printf("\n"); } return 0; }
7. C program to print following Pyramid:
*
**
***
****
#includeint main() { int i,j,n; printf("Enter the number of rows:\n"); scanf("%d",&n); for(i=0; i< n; i++) { for(j=0;j<=i;j++) { printf("*"); } printf("\n"); } return 0; }
8. 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
#includeint main() { int i, j, rows, k=0, count=0, count1=0; printf("Enter number of rows: \n"); fflush(stdout); scanf("%d", &rows); for (i=1; i<=rows; i++) { for (j=1; j<=rows-i; j++) { printf(" "); count++; } while (k!=2*i-1) { if (count <= rows-1) { printf("%d ", i+k); count++; } else { count1++; printf("%d ", (i+k-2*count1)); } k++; } count1=count=k=0; printf("\n"); } return 0; }
9. Write a program in C to generate following pattern using unformatted input/output functions only. [2074-Ashwin][5]
N
eee
PPPPP
aaaaaaa
LLLLLLLLL
#includevoid main() { char ch[]="NEPAL",space=' ',next_line='\n'; int i,j,n=5,k; for (i=1;i<=n;i++) { for (j=1;j<=n-i;j++) { putchar(space); } for (j=1;j<=2*i-1;j++) { if (i%2!=0) { putchar(ch[i-1]); } else { putchar(ch[i-1]+32); } } putchar(next_line); } }
10. C program to print following Pyramid:
**********
**** ****
*** ***
** **
* *
#includeint main() { int n,i,j; int space=0; printf("Enter the number of rows:\n"); fflush(stdout); scanf("%d",&n); /*run loop (parent loop) till number of rows*/ for(i=n;i>0;i--) { /*print first set of stars*/ for(j=0;j< i;j++) { printf("*"); } for(j=0;j< space;j++) { printf(" "); } /*print second set of stars*/ for(j=0;j< i;j++) { printf("*"); } printf("\n"); space+=2; } return 0; }
All Chapters
C Programs on integers
C programs on various integers
Recursive program in c
Arrays
- c programms on arrays
- complete IOE solution on arrays
- Detailed description
- And much more
Strings in C programming
- c programms on Strings
- complete IOE solution on Strings
- Detailed description
- Each one using pointer Concepts
- And much more
Data Files
- C programming concepts of data files and data structures
- IOE C Programming Solutions
- Important Numerous C Program
Guest