What's new

Help Pa help for loop

Xyrrk

Eternal Poster
Established
Write a C program the will ask the user to enter an integer value between 5 and 10. Then print the character ‘@’ in this order:



If the value inputted is 6, the output will be:

@@@@@@ @@@@@@

@@@@@ @@@@@

@@@@ @@@@

@@@ @@@

@@ @@

@ @
 
C:
#include <stdio.h>
int main() {
   int i, j, rows;
   printf("Enter the number of rows: ");
   scanf("%d", &rows);
   for (i = rows; i >= 1; --i) {
      for (j = 1; j <= i; ++j) {
         printf("@");
      }
      printf(" ");
      for (j = 1; j <= i; ++j) {
         printf("@");
      }
      printf("\n\n");
   }
   return 0;
}
 

Similar threads

Back
Top