Question

Write a nested FOR loop (using two for loops & two fprintf statements to generate the...

Write a nested FOR loop (using two for loops & two fprintf statements to generate the following pattern:

*****

****

***

**

*

Homework Answers

Answer #1

Hi, Please find my implementation.

Please let me know in case of any issue.

#include <stdio.h>

int main(){

   int n;
   printf("How many rows ? ");
   scanf("%d", &n);

   int i, j;
   for(i=1; i<=n; i++){

       for(j=i; j<=n; j++){
           fprintf(stdout, "%c", '*');
       }
       fprintf(stdout, "\n");
   }

   return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python Code Use (for loops) inside another for loop (a nested loop) to do the following:...
Python Code Use (for loops) inside another for loop (a nested loop) to do the following: Print Hello 30 times followed by Bye 10 times. Do that whole thing 15 times. (for a total of 600 lines of output) #Hint: First write the code that prints 30 "Hello" and then 10 "Bye". Think of that as two separate tasks, each of which requires its own for loop. THEN, once you get that working, put all of that inside ANOTHER loop...
using matlab: Q)using nested for loops to generate a 3*3 matrix where the element value is...
using matlab: Q)using nested for loops to generate a 3*3 matrix where the element value is equal to the sum of its row and column number, except for the diagonal elements which are zeros
Write a Java program using a single multi-level nested for-loop to display the following pattern (For...
Write a Java program using a single multi-level nested for-loop to display the following pattern (For each iteration, only one character can be printed) : 1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9# 3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27# 5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop to initialize the elements (do not initialize the array in the declaration): 10  9   8 7   6   5 4 3   2
write a Nested loop in C# to print out the following output using windows form. 0...
write a Nested loop in C# to print out the following output using windows form. 0 0 1 0 2 4 0 3 6 9 0 4 8 16 32
1. Given a matrix variable "mat", write code using for loops, if statements, etc. that will...
1. Given a matrix variable "mat", write code using for loops, if statements, etc. that will accomplish the same as the following: matsum = sum(mat') Please make sure to store the result in "matsum" and dont use sum. This is what I have so far but it keeps telling me is wrong.... % mat has been initialized for you: mat = randi([-100,100],randi([15,20]),randi([15,20])); % write your statements that accomplish the code above: [r c]=size(mat); for i=1:c matsum=0; for j=1:r matsum=matsum+mat(j,i); end...
Using nested loops, write a function called primes(a,b) that takes in two positive integers a and...
Using nested loops, write a function called primes(a,b) that takes in two positive integers a and b (where a<b). Then simply RETURNS a string containing all the prime numbers between a and b (or if there are none, the string "No Primes"). You should check that a and b are valid inputs, that is, that a and b are integers such that a<b (otherwise, the function should print “No Primes”). Three sample calls of your function (in IDLE) should produce...
Write a Java code snippet with a nested for loop to print five rows of six...
Write a Java code snippet with a nested for loop to print five rows of six random integers between 5 and 10 inclusive.
Create a Java application using nested for loops to print five rows of seven randomly generated...
Create a Java application using nested for loops to print five rows of seven randomly generated integers between 1 and 9 inclusive.
Create an array named data that can store 100 integers. Write a for loop that loops...
Create an array named data that can store 100 integers. Write a for loop that loops 100 times. Inside the loop store the variable you are using to increment the loop into the current element of the array data. So the array data should have a 0 at index 0, a 1 at index 1, a 2 at index 2, ..., a 99 at index 99.