Sie sind auf Seite 1von 42

Output : 1

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *_

Program : 1
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i,j;
5. clrscr();
6. for (i=0; i<5; i++) {
7. for (j=0; j<5; j++) {
8. printf(" * ");
9. }
10. printf("\n");
11. }
12. getch();
13. }

Output : 2
*
* *
* * *
* * * *
* * * * *_

Program : 2
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i,j;
5. clrscr();
6. for (i=0; i<5; i++) {
7. for (j=0; j<=i; j++) {
8. printf(" * ");
9. }
10. printf("\n");
11. }
12. getch();
13. }

Output : 3

*
* *
* * *
* * * *
* * * * *_

Program : 3
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i,j,k;
5. clrscr();
6. for (i=1; i<=5; i++) {
7. for (j=5; j>=i; j--) {
8. printf(" ");
9. }
10. for (k=1; k<=i; k++) {
11. printf("*");
12. }
13. printf("\n");
14. }
15. getch();
16. }
Output : 4

* * * * *
* * * *
* * *
* *
*_

Program : 4
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i,j,k,samp=1;
5. clrscr();
6. for (i=5; i>=1; i--) {
7. for (k=samp; k>=0; k--) {
8. printf(" ");
9. // only 1 space
10. }
11. for (j=i; j>=1; j--) {
12. printf("*");
13. }
14. samp = samp + 1;
15. printf("\n");
16. }
17. getch();
18. }

Output : 5
* * * * *
* * * *
* * *
* *
*_

Program : 5
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i,j;
5. clrscr();
6. for (i=5; i>=1; i--) {
7. for (j=1; j<=i; j++) {
8. printf(" * ");
9. }
10. printf("\n");
11. }
12. getch();
13. }

Output : 6

*
* *
* * *
* * * *
* * * * *_

Program : 6
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i,j,k,t=0;
5. clrscr();
6. for (i=1; i<=5; i++) {
7. for (k=t; k<5; k++) {
8. printf(" ");
9. }
10. for (j=0; j< i; j++) {
11. printf(" * ");
12. t = t + 1;
13. }
14. printf("\n");
15. }
16. getch();
17. }
Output : 7

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*_

Program : 7
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i,j,k,samp=1;
5. clrscr();
6. for (i=1; i<=5; i++) {
7. for (k=samp; k<=5; k++) {
8. printf(" ");
9. }
10. for (j=0; j< i; j++) {
11. printf("*");
12. }
13. samp = samp + 1;
14. printf("\n");
15. }
16. samp = 1;
17. for (i=4; i>=1; i--) {
18. for (k=samp; k>=0; k--) {
19. printf(" ");
20. }
21. for (j=i; j>=1; j--) {
22. printf("*");
23. }
24. samp = samp + 1;
25. printf("\n");
26. }
27. getch();
28. }
Output : 8

Enter number of rows: 5

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15_

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

Output : 9
Enter number of rows: 5

0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
5 4 3 2 1 0 1 2 3 4 5_

Program : 9
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int no,i,y,x=35;
5. clrscr();
6. printf("Enter number of rows: ");
7. scanf("%d," &no);
8. for (y=0;y<=no;y++) {
9. goto(x,y+1);
10. for (i=0-y; i<=y; i++) {
11. printf(" %3d ", abs(i));
12. x=x-3;
13. }
14. }
15. getch();
16. }

Output : 10
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5_

Program : 10
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i, j=5, k, x;
5. clrscr();
6. for (i=1;i<=5;i++) {
7. for (k=1;k<=j;k++) {
8. printf(" ");
9. }
10. for (x=1;x<=i;x++) {
11. printf("%d",i);
12. printf(" ");
13. }
14. printf("\n");
15. j=j-1;
16. }
17. getch();
18. }

Output : 11
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5_

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

Output : 12
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_

Program : 12
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i,j,k;
5. clrscr();
6. for (i=1; i<=5; i++) {
7. for (j=1; j<=5-i; j++) {
8. printf(" ");
9. }
10. for (k=1; k<=2*i-1; k++) {
11. printf(" %d ",k);
12. }
13. printf("\n");
14. }
15. getch();
16. }

Output : 13
A B C D E F G G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A_

Program : 13
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. int i,j,asci,spc;
5. clrscr();
6. for (i=7; i>=1; i--) {
7. for (spc=6; spc>=i; spc--) {
8. printf(" ");
9. }
10. asci=65;
11. for (j=1; j<=i; j++) {
12. printf("%2c",asci++);
13. }
14. for (j=i-1; j>=0; j--) {
15. printf("%2c",--asci);
16. }
17. printf("\n");
18. }
19. getch();
20. }

Output : 14
AAA AAB AAC ABA ABB ABC ACA ACB ACC BAA BAB BAC BBA BBB
BBC BCA BCB BCC CAA CAB CAC CBA CBB CBC CCA CCB CCC_

Program : 14
1. #include <stdio.h>
2. #include <conio.h>
3. void main() {
4. char ch1, ch2, ch3;
5. clrscr();
6. for (ch1='A' ; ch1<='C' ; ++ch1) {
7. for (ch2='A' ; ch2<='C' ; ++ch2) {
8. for (ch3='A' ; ch3<='C' ; ++ch3) {
9. printf(" %c%c%c", ch1, ch2, ch3);
10. }
11. }
12. }
13. getch();
14. }

Output : 15
11111
2222
333
44
5

Program : 15
1. #include <stdio.h>
2. int main() {
3. int i, j;
4. for (i=1;i<=5;i++) {
5. for (j=5;j>=i;j--) {
6. printf("%d",i);
7. }
8. printf("\n");
9. }
10. return 0;
11. }

Output : 16
1234567
12345
123
1

Program : 16
1. int main() {
2. int i,j;
3. for (i=7;i>=1;i-=2) {
4. for (j=1;j<=i;j++) {
5. printf("%d",j);
6. }
7. printf("\n");
8. }
9. return 0;
10. }

Output : 17
55555
45555
34555
23455
12345

Program : 17
1. int main() {
2. int i, j, k;
3. for (i=5;i>=1;i--) {
4. k = i;
5. for (j=1;j<=5;j++) {
6. if(k <= 5) {
7. printf("%d",k);
8. } else {
9. printf("5");
10. }
11. k++;
12. }
13. printf("\n");
14. }
15. return 0;
16. }
Output : 18
1
10
101
1010
10101

Program : 18
1. #include<stdio.h>
2. int main() {
3. int i,j,k;
4. for (i=1;i<=5;i++) {
5. for (j=1;j<=i;j++) {
6. printf("%d",j%2);
7. }
8. printf("\n");
9. }
10. return 0;
11. }

Output : 19
12344321
123**321
12****21
1******1

Program : 19
1. #include<stdio.h>
2.
3. int main() {
4. int i,j,k;
5. for (i=4;i>=1;i--) {
6. for (j=1;j<=4;j++) {
7. if(j<=i)
8. printf("%d",j); else
9. printf(" ");
10. }
11. for (j=4;j>=1;j--) {
12. if(j<=i)
13. printf("%d",j); else
14. printf(" ");
15. }
16. printf("\n");
17. }
18. return 0;
19. }

Output : 20
5432*
543*1
54*21
5*321
*4321
Program : 20
1. #include<stdio.h>
2.
3. int main() {
4. int i,j;
5. for (i=1;i<=5;i++) {
6. for (j=5;j>=1;j--) {
7. if(i==j)
8. printf("*"); else
9. printf("%d",j);
10. }
11. printf("\n");
12. }
13. return 0;
14. }

Output : 21
0
909
89098
7890987
678909876
56789098765
4567890987654
345678909876543
23456789098765432
1234567890987654321

Program : 21
1. #include<stdio.h>
2.
3. int main() {
4. int i,j;
5. printf("0\n");
6. for (i=9;i>=1;i--) {
7. for (j=i;j<=9;j++)
8. printf("%d",j);
9. printf("0");
10. for (j=9;j>=i;j--)
11. printf("%d",j);
12. printf("\n");
13. }
14. return 0;
15. }

Output : 22
1
21
321
4321
54321

Program : 22
1. #include<stdio.h>
2.
3. int main() {
4. int i,j,k;
5. for (i=1;i<=5;i++) {
6. for (j=5;j>=1;j--) {
7. if(j<=i)
8. printf("%d",j); else
9. printf(" ");
10. }
11. printf("\n");
12. }
13. return 0;
14. }
Output : 23
1 1
12 21
123 321
1234 4321
1234554321

Program : 23
1. #include<stdio.h>
2.
3. int main() {
4. int i,j,k;
5. for (i=1;i<=5;i++) {
6. for (j=1;j<=5;j++) {
7. if(j<=i)
8. printf("%d",j); else
9. printf(" ");
10. }
11. for (j=5;j>=1;j--) {
12. if(j<=i)
13. printf("%d",j); else
14. printf(" ");
15. }
16. printf("\n");
17. }
18. return 0;
19. }

Output : 24
1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1

Program : 24
1. #include<stdio.h>
2.
3. int main() {
4. int i,j;
5. for (i=1;i<=4;i++) {
6. for (j=1;j<=i;j++) {
7. if(j<i)
8. printf("%d*",i); else
9. printf("%d",i);
10. }
11. printf(" \n");
12. }
13. for (i=4;i>=1;i--) {
14. for (j=1;j<=i;j++) {
15. if(j<i)
16. printf("%d*",i); else
17. printf("%d",i);
18. }
19. printf(" \n");
20. }
21. return 0;
22. }

Output : 25
1
232
45654
78910987

Program : 25
1. #include<stdio.h>
2.
3. int main() {
4. int i,j,k=1,l=1,n=4;
5. for (i=1;i<=n;i++) {
6. l=k;
7. for (j=1;j<=i;j++)
8. printf("%d",l++);
9. k=l--;
10. for (j=1;j<i;j++)
11. printf("%d",--l);
12. printf("\n");
13. }
14. return 0;
15. }

Output : 26
11
12 13
13 14 15
14 15 16 17

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

Output : 27
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Program : 27
1. #include<stdio.h>
2.
3. int main() {
4. int i,j,k;
5. k=1;
6. for (i=1;i<=5;i++) {
7. for (j=5;j>=1;j--) {
8. if(j > i)
9. printf(" "); else
10. printf("%3d",k++);
11. }
12. printf("\n");
13. }
14. return 0;
15. }

Output : 28
1
212
32123
4321234

Program : 28
1. #include<stdio.h>
2.
3. int main() {
4. int i,j;
5. for (i=1;i<=4;i++) {
6. for (j=i;j>1;j--)
7. printf("%d",j);
8. for (j=1;j<=i;j++)
9. printf("%d",j);
10. printf("\n");
11. }
12. return 0;
13. }
Output : 29
1 2 3 4 5
6 7 8 9
10 11 12
13 14
15

Program : 29
1. #include<stdio.h>
2.
3. int main() {
4. int i,j,k;
5. k=1;
6. for (i=1;i<=5;i++) {
7. for (j=5;j>=i;j--) {
8. printf("%3d",k++);
9. }
10. printf("\n");
11. }
12. return 0;
13. }

Output : 30
1
23
345
4567
56789
Program : 30
1. #include<stdio.h>
2.
3. int main() {
4. int i,j,k;
5. for (i=1;i<=5;i++) {
6. j=i;
7. for (k=1;k<=i;k++) {
8. printf("%d",j++);
9. }
10. printf("\n");
11. }
12. return 0;
13. }

Output : 31
11111
0000
111
00
1

Program : 31
1. #include <stdio.h>
2.
3. int main() {
4. int i, j;
5. for (i=5;i>=1;i--) {
6. for (j=1;j<=i;j++) {
7. printf("%d",i%2);
8. }
9. printf("\n");
10. }
11. return 0;
12. }
Output : 32
1234
2341
3421
4321

Program : 32
1. #include <stdio.h>
2.
3. int main() {
4. int i,j,k;
5. for (i=1;i<=4;i++) {
6. k = i-1;
7. for (j=i;j&lti+4;j++) {
8. if(j<=4) {
9. printf("%d",j);
10. } else {
11. printf("%d",k--);
12. }
13. }
14. printf("\n");
15. }
16. return 0;
17. }

Output : 33
11111
1 1
1 1
1 1
11111

Program : 33
1. #include<stdio.h>
2.
3. int main() {
4. int i,j;
5. for (i=1;i<=5;i++) {
6. for (j=1;j<=5;j++) {
7. if(j==5 || j==1 || i==1 || i==5)
8. printf("1"); else
9. printf(" ");
10. }
11. printf("\n");
12. }
13. return 0;
14. }

Output : 34
1
4 9 16
25 36 49 64 81
100 121 144 169 196 225 256
289 324 361 400 441 484 529 576 625

Program : 34
1. #include<stdio.h>
2.
3. int main() {
4. int i, j, k=1;
5. for (i=1;i<=5;i++) {
6. for (j=i;j<5;j++) {
7. printf(" ");
8. }
9. for (j=1;j<(i*2);j++) {
10. printf("%3d ",k*k);
11. k++;
12. }
13. printf("\n");
14. }
15. return 0;
16. }

Output : 35
1
123
12345
1234567
123456789
1234567
12345
123
1

Program : 35
1. #include<stdio.h>
2.
3. int main() {
4. int i, j, k;
5. for (i=1;i<=5;i++) {
6. for (j=i;j<5;j++) {
7. printf(" ");
8. }
9. for (k=1;k<(i*2);k++) {
10. printf("%d",k);
11. }
12. printf("\n");
13. }
14. for (i=4;i>=1;i--) {
15. for (j=5;j>i;j--) {
16. printf(" ");
17. }
18. for (k=1;k<(i*2);k++) {
19. printf("%d",k);
20. }
21. printf("\n");
22. }
23. return 0;
24. }

Output : 36
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Program : 36
1. #include<stdio.h>
2.
3. int main() {
4. int i,j;
5. for (i=1;i<=5;i++) {
6. for (j=5;j>i;j--) {
7. printf(" ");
8. }
9. for (j=1;j<=i;j++) {
10. printf("%d ",j);
11. }
12. printf("\n");
13. }
14. return 0;
15. }

Output : 37
*000*000*
0*00*00*0
00*0*0*00
000***000

Program : 37
1. #include <stdio.h>
2.
3. int main() {
4. int i,j,k;
5. for (i=1;i<=4;i++) {
6. for (j=1;j<=9;j++) {
7. if(j==i || j==5 || 10-j==i)
8. printf("*"); else
9. printf("0");
10. }
11. printf("\n");
12. }
13. return 0;
14. }
Output : 38
4444444
4333334
4322234
4321234
4322234
4333334
4444444

Program : 38
1. #include <stdio.h>
2.
3. int main() {
4. int i,j,k;
5. for (i=4;i>=1;i--) {
6. for (j=4;j>=i;j--)
7. printf("%d",j);
8. for (j=1;j<(i*2)-1;j++)
9. printf("%d",i);
10. for (j=i+1;j<=4;j++)
11. printf("%d",j);
12. printf("\n");
13. }
14. for (i=2;i<=4;i++) {
15. for (j=4;j>=i;j--)
16. printf("%d",j);
17. for (j=1;j<(i*2)-1;j++)
18. printf("%d",i);
19. for (j=i+1;j<=4;j++)
20. printf("%d",j);
21. printf("\n");
22. }
23. return 0;
24. }
Output : 39
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
10 20 30 40 50 60 70 80 90 100

Program : 39
1. #include <stdio.h>
2.
3. int main() {
4. int i,j;
5. for (i=1;i<=10;i++) {
6. for (j=1;j<=i;j++) {
7. printf("%d ",i*j);
8. }
9. printf("\n");
10. }
11. return 0;
12. }
Output : 40
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

Program : 40
1. #include <stdio.h>
2.
3. long fact(int);
4. int main() {
5. int i, j;
6. for (i=0;i<5;i++) {
7. for (j=0;j<=i;j++) {
8. printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
9. }
10. printf("\n");
11. }
12. return 0;
13. }
14. long fact(int n) {
15. int i;
16. long f = 1;
17. for (i=1;i<=n;i++)
18. f = f*i;
19. return f;
20. }

Output : 41
E
DE
CDE
BCDE
ABCDE
Program : 41
1. #include <stdio.h>
2. int main() {
3. int i, j;
4. for (i=5;i>=1;i--) {
5. for (j=i;j<=5;j++) {
6. printf("%c",'A' + j-1);
7. }
8. printf("\n");
9. }
10. return 0;
11. }

Output : 42
ABCDE
BCDE
CDE
DE
E

Program : 42
1. #include <stdio.h>
2. int main() {
3. int i, j;
4. for (i=1;i<=5;i++) {
5. for (j=i;j<=5;j++) {
6. printf("%c", 'A'-1 + j);
7. }
8. printf("\n");
9. }
10. return 0;
11. }
Output : 43
EDCBA
EDCB
EDC
ED
E

Program : 43
1. #include <stdio.h>
2. int main() {
3. int i, j;
4. for (i=1;i<=5;i++) {
5. for (j=5;j>=i;j--) {
6. printf("%c",'A'-1 + j);
7. }
8. printf("\n");
9. }
10. return 0;
11. }

Output : 44
EDCBA
DCBA
CBA
BA
A

Program : 44
1. #include <stdio.h>
2. int main() {
3. int i, j;
4. for (i=5;i>=1;i--) {
5. for (j=i;j>=1;j--) {
6. printf("%c",'A'-1 + j);
7. }
8. printf("\n");
9. }
10. return 0;
11. }

Output : 45
EEEEE
DDDD
CCC
BB
A

Program : 45
1. #include <stdio.h>
2. int main() {
3. int i, j;
4. for (i=5;i>=1;i--) {
5. for (j=1;j<=i;j++) {
6. printf("%c",'A'-1 + i);
7. }
8. printf("\n");
9. }
10. return 0;
11. }

Output : 46
AAAAA
BBBB
CCC
DD
E

Program : 46
1. #include <stdio.h>
2. int main() {
3. int i, j;
4. for (i=1;i<=5;i++) {
5. for (j=5;j>=i;j--) {
6. printf("%c",'A'-1 + i);
7. }
8. printf("\n");
9. }
10. return 0;
11. }
Output : 47
A
AB
ABC
ABCD
ABCDE

Program : 47
1. #include <stdio.h>
2. int main() {
3. int i, j;
4. for (i=1;i<=5;i++) {
5. for (j=1;j<=i;j++) {
6. printf("%c",'A' + j-1);
7. }
8. printf("\n");
9. }
10. return 0;
11. }

Output : 48
E
DE
CDE
BCDE
ABCDE

Program : 48
1. #include <stdio.h>
2. int main() {
3. int i, j;
4. for (i=5;i>=1;i--) {
5. for (j=i;j<=5;j++) {
6. printf("%c",'A' + j-1);
7. }
8. printf("\n");
9. }
10. return 0;
11. }

Output : 49
1
1 2
3 5 8
13 21 34 55
89 144 233 377 610

Program : 49
1. #include<stdio.h>
2.
3. int fib(int);
4. int main() {
5. int i,j,k=1;
6. for (i=1;i<=5;i++) {
7. for (j=1;j<=i;j++) {
8. printf("%d ",fib(k++));
9. }
10. printf("\n");
11. }
12. return 0;
13. }
14. int fib(int n) {
15. if(n<=1)
16. return n;
17. return(fib(n-1)+fib(n-2));
18. }

Output : 50
11111
10001
10001
10001
11111

Program : 50
1. #include<stdio.h>
2.
3. int main() {
4. int i,j;
5. for (i=1;i<=5;i++) {
6. for (j=1;j<=5;j++) {
7. if(j==5 || j==1 || i==1 || i==5)
8. printf("1"); else
9. printf("0");
10. }
11. printf("\n");
12. }
13. return 0;
14. }
Program
1. #include<stdio.h>
2.
3. int main(){
4.
5. int i,j,r,k=1;
6.
7. printf("Enter the range: ");
8. scanf("%d",&r);
9.
10. printf("FLOYD'S TRIANGLE\n\n");
11. for(i=1;i<=r;i++){
12. for(j=1;j<=i;j++,k++)
13. printf(" %d",k);
14. printf("\n");
15. }
16.
17. return 0;
18. }
19.

Result
Enter the range: 10
FLOYD'S TRIANGLE

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55

Program
1. #include<stdio.h>
2.
3. long fact(int);
4. int main(){
5. int line,i,j;
6.
7. printf("Enter the no. of lines: ");
8. scanf("%d",&line);
9.
10. for(i=0;i<line;i++){
11. for(j=0;j<line-i-1;j++)
12. printf(" ");
13.
14. for(j=0;j<=i;j++)
15. printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
16. printf("\n");
17. }
18. return 0;
19. }
20.
21. long fact(int num){
22. long f=1;
23. int i=1;
24. while(i<=num){
25. f=f*i;
26. i++;
27. }
28. return f;
29. }
30.

Result
Enter the no. of lines: 8
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1

Das könnte Ihnen auch gefallen