From e676ac58d97a60b91cc08ccf57a87dd61a80a9ee Mon Sep 17 00:00:00 2001 From: sharansk792000 Date: Wed, 14 Oct 2020 03:09:20 +0530 Subject: [PATCH] added pgm --- C/program-63/README.md | 1 + C/program-63/program.c | 19 +++++++++++++++ C/program-68/program-68.c | 50 +++++++++++++++++++-------------------- 3 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 C/program-63/README.md create mode 100644 C/program-63/program.c diff --git a/C/program-63/README.md b/C/program-63/README.md new file mode 100644 index 00000000..20faa6e4 --- /dev/null +++ b/C/program-63/README.md @@ -0,0 +1 @@ +C program to print Pascal's Triangle diff --git a/C/program-63/program.c b/C/program-63/program.c new file mode 100644 index 00000000..29809b20 --- /dev/null +++ b/C/program-63/program.c @@ -0,0 +1,19 @@ +#include +int main() { + int rows, coef = 1, space, i, j; + printf("Enter the number of rows: "); + scanf("%d", &rows); + for (i = 0; i < rows; i++) { + for (space = 1; space <= rows - i; space++) + printf(" "); + for (j = 0; j <= i; j++) { + if (j == 0 || i == 0) + coef = 1; + else + coef = coef * (i - j + 1) / j; + printf("%4d", coef); + } + printf("\n"); + } + return 0; +} diff --git a/C/program-68/program-68.c b/C/program-68/program-68.c index 91ebbd28..fa6a2e0b 100644 --- a/C/program-68/program-68.c +++ b/C/program-68/program-68.c @@ -1,34 +1,34 @@ #include -#include +#include int main () - { - char s[50]; - int i, c = 0; - int flag = 0; +{ + char s[50]; + int i, c = 0; + int flag = 0; - printf ("Input a string\n"); - scanf ("%s", s); - while (s[c] != '\0') - c++; + printf ("Input a string\n"); + scanf ("%s", s); + while (s[c] != '\0') + c++; - for (i = 0; i < c; i++) + for (i = 0; i < c; i++) { - if(s[i] !='0' && s[i]!='1') - { - printf("error\n"); - exit(0); - } + if(s[i] !='0' && s[i]!='1') + { + printf("error\n"); + exit(0); + } - if (s[i] == '0' && s[i + 1] == '0' && s[i + 2] == '0') - { - flag = 1; - } - } - if (flag == 1) - printf ("accepted\n"); - else - printf ("not accepted\n"); - return 0; + if (s[i] == '0' && s[i + 1] == '0' && s[i + 2] == '0') + { + flag = 1; + } } + if (flag == 1) + printf ("accepted\n"); + else + printf ("not accepted\n"); + return 0; +}