current position:Home>C language function problem,.?!

C language function problem,.?!

2022-02-03 01:22:15 CSDN Q & A

This problem requires the realization of function output n Line character pyramid .

Function interface definition :
void CharPyramid( int n, char ch);
among n and ch Is the parameter passed in by the user ,n by [1, 9] The positive integer . The function is required to print... In the format shown in the example n Line by character ch A pyramid of characters . Notice that there is a space after each character .

Sample referee test procedure :
#include <stdio.h>

void CharPyramid( int n, char ch );

int main()
{
int n;
char ch;

scanf("%d %c", &n, &ch);CharPyramid(n, ch);return 0;

}

/* Please fill in the answer here */
sample input :
4 G
No blank lines at the end
sample output :
Here is the corresponding output . for example :

G
G G
G G G
G G G G
No blank lines at the end




Refer to the answer 1:

void CharPyramid( int n, char ch ){
for(int i=1;i<=n;i++){
for(int j=1;j<=n-i;j++) printf(" ");
for(int j=1;j<=i;j++) {printf("%c",ch);printf(" ");}
printf("\n");
}
}




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030122142996.html

Random recommended