void letters(char c)
// c is one of the characters 'A' through 'Z'.
// The function needs to print a pattern of letters as follows:
// 1. If the parameter c is 'A', then the output is 'A'.
// 2. For other values of c, the output consists of three parts:
// -- the output for the previous letter (c-1);
// -- followed by the letter c itself;
// -- followed by a second copy of the output for the previous letter (c-1).
// There is no '\n' printed at the end of the output.
/* Example output:
letters('D') will print:
ABACABADABACABA
*/
The program that I have written is
#include<stdio.h>
#include<stdlib.h>
char pat(char);
int main()
{
char n,a;
printf("Please enter a capital English character A-Z:");
scanf("%c",&n);
if(n>=65 && n<=90)
{
a=pat(n);
printf("%c%c%c",a,n,a);
}
else
printf("Invalid selection");
system("pause");
return 0;
}
char pat(char n)
{
if (n==65)
return n;
else
{
return pat(n-1) ;
}
}
But the output is wrong. How to fix the program?