Question

Print the following pattern.in c language only using for loop only and please comment each step...

Print the following pattern.in c language only using for loop only and please comment each step to make it understandable
5 5
5 4 4 5
5 4 3 3 4 5
5 4 3 2 2 3 4 5
5 4 3 2 1 1 2 3 4 5

Homework Answers

Answer #1

CODE IN C:

#include<stdio.h>
int main()
{
int n;
printf("Enter the value of n : "); //the pattern is divide dinto two patternS: the first is 5 54 543 5432 54321 and second is 5 45 345 2345 12345
scanf("%d",&n);
for(int i =n;i>=1;i--)
{
for(int j=n;j>=i;j--) //this loop is to print the first pattern
{
printf("%d",j);
}
for(int k=i;k<=5;k++)//this loop is to print the second pattern
{
printf("%d",k);
}

printf("\n");
}

}

First pattern is

5

5 4

5 4 3

5 4 3 2

5 4 3 2 1

Second pattern is

5

4 5

3 4 5

2 3 4 5

1 2 3 4 5


OUTPUT SNIPPET:

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
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
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
Python Language ONLY! Python Language ONLY! Python Language ONLY! When doing this try to use a...
Python Language ONLY! Python Language ONLY! Python Language ONLY! When doing this try to use a level one skill python, like as if you just learned this don't use anything advanced if you can please. Write a for loop (only one for loop) that computes the total of the following series of numbers: (20/1)+(19/2)+(18/3)+(17/4)+.....+(1/20)
Without using move or li, write MIPS assembly language using MARS simulator to print a half...
Without using move or li, write MIPS assembly language using MARS simulator to print a half pyramid depending on a value n of a user input. Such that if n = 5 were entered the following would be printed: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other my name's Aya amro
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: intQ1_for() intQ1_while() intQ1_do() To compute the sum of all numbers that are multiples of 4, between 30 and 1000, in 3 different ways: with a for loop, a while loop and a do-while loop, accordingly. After each loop print the value. Return the total sum at the end of each...
[C++ Language] Describe how the following call by reference works. Make a comment for each line....
[C++ Language] Describe how the following call by reference works. Make a comment for each line. void pxc(int& c, int& d) {     int k = c;     c = d;     d = k; }    int main() {     int a = 15, b = 100;     pxc(a, b); }
Write a program on C++ to calculate and print the factorial of a number using a...
Write a program on C++ to calculate and print the factorial of a number using a for loop. The factorial of a number is the product of all integers up to and including that number, so the factorial of 4 is 4*3*2*1= 24.
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display...
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display 5 lines of smiley faces. The following would be the output of your program: Note: Sample program is in the "Important Documents", Module 6 folder) Hello:                          Bye!