diff --git a/C/Program-43/program.c b/C/Program-43/program.c new file mode 100644 index 00000000..35e5b447 --- /dev/null +++ b/C/Program-43/program.c @@ -0,0 +1,45 @@ + +// C program for printing the hollow triangle pattern + +#include + +// Function for printing pattern +void pattern(int N) +{ + int i, j, k = 0, space = 1, rows = N; + + // For printing stars + for (i = rows; i >= 1; i--) { + for (j = 1; j <= i; j++) { + printf("*"); + } + if (i != rows) { + // for printing space + for (k = 1; k <= space; k++) { + printf(" "); + } + + // increment by 2 + space = space + 2; + } + for (j = i; j >= 1; j--) { + if (j != rows) + printf("*"); + } + printf("\n"); + } + printf("\n"); +} + +// Driver code +int main() +{ + + // Get N + int N = 6; + + // Print the pattern + pattern(N); + + return 0; +} diff --git a/C/README.md b/C/README.md index 85265768..4b192d35 100644 --- a/C/README.md +++ b/C/README.md @@ -42,4 +42,5 @@ | Program-38 | Program to find the factorial of a number using recursion | | Program-39 | Program to find the GCD of a number using recursion | | Program-40 | Program to find the ackerman of given two numbers| +| Program-41 | Program to find sum of two numbers without using any operator | diff --git a/C/program-41/program.c b/C/program-41/program.c new file mode 100644 index 00000000..2cd3cd17 --- /dev/null +++ b/C/program-41/program.c @@ -0,0 +1,14 @@ +/*To find sum of two numbers without using any operator*/ +#include + +int add(int x, int y) +{ + return printf("%*c%*c", x, ' ', y, ' '); +} + +// Driver code +int main() +{ + printf("Sum = %d", add(3, 4)); + return 0; +} diff --git a/C/program-44/program.c b/C/program-44/program.c new file mode 100644 index 00000000..24dbbcb7 --- /dev/null +++ b/C/program-44/program.c @@ -0,0 +1,48 @@ +// C implementation of the approach +#include + +// Function to print the desired +// Alphabet Z Pattern +void alphabet_Z_Pattern(int N) +{ + int index, side_index, size; + + // Declaring the values of Right, + // Left and Diagonal values + int Top = 1, Bottom = 1, Diagonal = N - 1; + + // Loop for printing the first row + for (index = 0; index < N; index++) + printf("%d ", Top++); + + printf("\n"); + + // Main Loop for the rows from (2 to n-1) + for (index = 1; index < N - 1; index++) { + + // Spaces for the diagonals + for (side_index = 0; side_index < 2 * (N - index - 1); + side_index++) + printf(" "); + + // Printing the diagonal values + printf("%d", Diagonal--); + + printf("\n"); + } + + // Loop for printing the last row + for (index = 0; index < N; index++) + printf("%d ", Bottom++); +} + +// Driver Code +int main() +{ + // Size of the Pattern + int N = 5; + + alphabet_Z_Pattern(N); + + return 0; +} diff --git a/C/program-45/program.c b/C/program-45/program.c new file mode 100644 index 00000000..a19e4af8 --- /dev/null +++ b/C/program-45/program.c @@ -0,0 +1,37 @@ + +// C program to illustrate the above given pattern of numbers. +#include + +int main() +{ + int n = 5, i, j, num = 1, gap; + + gap = n - 1; + + for ( j = 1 ; j <= n ; j++ ) + { + num = j; + + for ( i = 1 ; i <= gap ; i++ ) + printf(" "); + + gap --; + + for ( i = 1 ; i <= j ; i++ ) + { + printf("%d", num); + num++; + } + num--; + num--; + for ( i = 1 ; i < j ; i++) + { + printf("%d", num); + num--; + } + printf("\n"); + + } + + return 0; +} diff --git a/C/program42/program42.c b/C/program42/program42.c new file mode 100644 index 00000000..5a6154b0 --- /dev/null +++ b/C/program42/program42.c @@ -0,0 +1,17 @@ +/*C Program to print Floyd’s triangle*/ +// Without using a temporary variable and with only one loop +#include +void floyd(n){ + int i,j=1; + for (i=1;i<=(n*(n+1))/2;i++){ + printf("%d ",i); + if(i==(j*(j+1))/2){ + printf("\n"); + j++; + } + } +} + +int main(){ + floyd(6); +}