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
Calculate and print the area and volume of a cone inside a While  loop that goes from...
Calculate and print the area and volume of a cone inside a While  loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5) Note: Your loop variable will need to be a double data type Use two decimal places on all numbers that are double data type. This will be a table with 3 columns. Use r as the loop counter and as the radius. Let...
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
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 The first letter A and the last letter O
Write a program (C language) that will read the number of a month and will print...
Write a program (C language) that will read the number of a month and will print the number of days in the month. Ignore leap years. Use 28 days for February. Have the program runs in a continuous loop, allowing the user to enter a month number, see that number of days, and repeat. Use month number = 0 to exit the loop and the program. Program must meet the following criteria: 1.Your name and the name of the program...
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...
[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); }
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT