Skip to content
45 changes: 45 additions & 0 deletions C/Program-43/program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

// C program for printing the hollow triangle pattern

#include <stdio.h>

// 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;
}
1 change: 1 addition & 0 deletions C/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

14 changes: 14 additions & 0 deletions C/program-41/program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*To find sum of two numbers without using any operator*/
#include<stdio.h>

int add(int x, int y)
{
return printf("%*c%*c", x, ' ', y, ' ');
}

// Driver code
int main()
{
printf("Sum = %d", add(3, 4));
return 0;
}
48 changes: 48 additions & 0 deletions C/program-44/program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// C implementation of the approach
#include <stdio.h>

// 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;
}
37 changes: 37 additions & 0 deletions C/program-45/program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

// C program to illustrate the above given pattern of numbers.
#include<stdio.h>

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;
}
17 changes: 17 additions & 0 deletions C/program42/program42.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*C Program to print Floyd’s triangle*/
// Without using a temporary variable and with only one loop
#include<stdio.h>
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);
}