Revision as of 20:13, 13 May 2024 by Admin (Created page with "One possible solution: <syntaxhighlight lang="C"> #include<stdio.h> // This is the fastest way int main(void) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { for(int j=0;j<=i;j++) putchar(42); putchar(10); } for(int i=n-1;i>0;i--) { for(int j=0;j<i;j++) putchar(42); putchar(10); } while((n=getchar())!=10); getchar(); return 0; } </syntaxhighlight> or like this (all math) <syntaxhighlight lang="C"> void sideways(int n) {...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Exercise


ABy Admin
May 13'24

Answer

One possible solution:

#include<stdio.h>
// This is the fastest way
int main(void) {
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++) {
    for(int j=0;j<=i;j++)
      putchar(42);
    putchar(10);
  }
  for(int i=n-1;i>0;i--) {
    for(int j=0;j<i;j++)
      putchar(42);
    putchar(10);
  }
  while((n=getchar())!=10);
  getchar();
  return 0;
}

or like this (all math)

void sideways(int n)
{
    int i=0,j=0;
    for(i=1;i<2*n;i++){
        for(j=1;j<=(n-(abs(n-i)));j++){
	    printf("*");
	}
	printf("\n");
    }
}
00