Revision as of 20:14, 13 May 2024 by Admin (Created page with "One possible solution: <syntaxhighlight lang="C"> void right_side_up(int n) { int x,y; for (y= 1; y <= n; y++) { for (x= 0; x < n-y; x++) putchar(' '); for (x= (n-y); x < (n-y)+(2*y-1); x++) putchar('*'); putchar('\n'); } } </syntaxhighlight> Another solution: <syntaxhighlight lang="C"> #include<stdio.h> int main(void) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { for(int j=0;j<n-i-1;j++)...")
Exercise
ABy Admin
May 13'24
Answer
One possible solution:
void right_side_up(int n)
{
int x,y;
for (y= 1; y <= n; y++)
{
for (x= 0; x < n-y; x++)
putchar(' ');
for (x= (n-y); x < (n-y)+(2*y-1); x++)
putchar('*');
putchar('\n');
}
}
Another solution:
#include<stdio.h>
int main(void) {
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) {
for(int j=0;j<n-i-1;j++)
putchar(32);
for(int j=0;j<i*2+1;j++)
putchar(42);
putchar(10);
}
while((n=getchar())!=10);
getchar();
return 0;
}