My code has 3 functions doing 3 different works. First one just prints "Hello!", second one takes an integer input from the user and returns its square and the third one takes a character input from the user and makes a triangular pattern out of it. But when I execute the code the first two functions work well and the third one doesn't. Although, when I execute the third function separately, it works well. What could be the problem? Here is the code :
#include <stdio.h>
void greet()
{
printf("Hello !\n");
}
int square()
{
int n;
printf("Enter a number to be squared:\n");
scanf("%d",&n);
return n*n;
}
void pattern(char ch)
{
printf("Enter a Character:\n");
scanf("%c",&ch);
for (int i=10;i>0;i--)
{
for (int j=0;j<i;j++)
{
printf("%c",ch);
}
printf("\n");
}
}
int main()
{
int num;
char c;
greet();
num=square();
printf("%d\n",num);
pattern(c);
return 0;
}