Create pattern_using_functions.c

This commit is contained in:
anjalisoni12 2023-10-14 02:08:05 +05:30 committed by GitHub
parent 7fe68d9f05
commit bd18deb47c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

49
pattern_using_functions.c Normal file
View file

@ -0,0 +1,49 @@
// 1
// 1 2 1
// 1 2 3 2 1
// 1 2 3 4 3 2 1
#include <stdio.h>
void primeNum(int n)
{
for (int i = 1; i <= n; i++)
{
printf("%d ", i);
}
}
void primeNumReverse(int n)
{
for (int i = n; i >= 1; i--)
{
printf("%d ", i);
}
}
void spaces(int n)
{
for (int j = n - 1; j >= 0; j--)
{
printf(" ");
}
}
int main()
{
int n = 5;
spaces(4);
primeNum(1);
primeNumReverse(0);
printf("\n");
spaces(3);
primeNum(2);
primeNumReverse(1);
printf("\n");
spaces(2);
primeNum(3);
primeNumReverse(2);
printf("\n");
spaces(1);
primeNum(4);
primeNumReverse(3);
printf("\n");
}