Question

In: Computer Science

write a program that uses exactly four for loops to print the sequence of letters below...

write a program that uses exactly four for loops to print the sequence of letters below

A A A A A A A A A A B B B B B B B C C C C C C E E E E E

Solutions

Expert Solution

Here we want to write a program that uses exactly four for loops to print the given sequence,

A A A A A A A A A A B B B B B B B C C C C C C E E E E E

This sequence contains 10 A's followed by 7 B's followed by 6 C's followed by 5 E's.

C program to print the given sequence with four for loop and explanation

#include <stdio.h> /* Include header file for access standard input output built in functions */

int main()   /* Execution of the program begins here */
{   
for(int i=0;i<10;i++)   /* First for loop ,initialize i as integer and check i<10 and update i by 1 for each loop .(this for loop condition true until i=9*/
{
printf("A "); /* print letter A if the for loop condition is satisfy */
}
for(int i=0;i<7;i++) /* second for loop ,initialize i as integer and check i<7 and update i by 1 for each loop .(this for loop condition is true until i=6 */
{
printf("B ");/* print letter B if the for loop condition is satisfy */
}
for(int i=0;i<6;i++)/* third for loop ,initialize i as integer and check i<6 and update i by 1 for each loop .(this for loop condition true until i=5*/
{
printf("C ");/* print letter C if the for loop condition is satisfy */
}
for(int i=0;i<5;i++)/* fourth for loop ,initialize i as integer and check i<5 and update i by 1 for each loop .(this for loop condition true until i=4*/
{
printf("E ");/* print letter E if the for loop condition is satisfy */
}
} /* End of main function*/

C++ program to print the given sequence with four for loop

#include <iostream>

using namespace std;

int main()
{
for(int i=0;i<10;i++)
{
cout<<"A ";
  
}
for(int i=0;i<7;i++)
{
cout<<"B ";
  
}
for(int i=0;i<6;i++)
{
cout<<"C ";
  
}
for(int i=0;i<5;i++)
{
cout<<"E ";
  
}
    return 0;
}

Python program to print the given sequence with four for loop

for i in range(10): # for loop executes from 0-9.that is range(10) will give numbers from 0-9.
print("A",end=" ")  # print letter A ,print letters in same line using end equal to space.
for i in range(7):   # for loop executes from 0-6.that is range(7) will give numbers from 0-6.
print("B",end=" ") # print letter B,print letters in same line using end equal to space.
for i in range(6):   # for loop executes from 0-5.that is range(6) will give numbers from 0-5.
print("C",end=" ") # print letter C ,print letters in same line using end equal to space.
for i in range(5):   # for loop executes from 0-4.that is range(4) will give numbers from 0-4.
print("E",end=" ") # print letter E ,print letters in same line using end equal to space.

output


Related Solutions

Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
Write a program that uses a for loop to print One of the months of the...
Write a program that uses a for loop to print One of the months of the year is January One of the months of the year is February ...
Write a program in java which is in main and uses no classes, methods, loops or...
Write a program in java which is in main and uses no classes, methods, loops or if statements Ask the user to enter their first name Ask the user to enter their last name Print their initials followed by periods (ie. Clark Kent = C. K.) Print the number of letters in their last name
C++. Write a program that uses for loops to perform the following steps: a. Prompt the...
C++. Write a program that uses for loops to perform the following steps: a. Prompt the user to input two positive integers. variables: firstNum and secondNum (firstNum must be less than secondNum). Validate the user's input; prompt the user again if firstNum is not less than secondNum (use for loop). b. Output all odd numbers between firstNum and secondNum. (use for loop). c. Output the sum of all even numbers between firstNum and secondNum. (use for loop). d. Output the...
IN C++ Write a program that uses nested loops to collect data and calculate the average...
IN C++ Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the ­­program should display the...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number...
Write a program with class name ForLoops that uses for loops to perform the following steps:1....
Write a program with class name ForLoops that uses for loops to perform the following steps:1. Prompt the user to input two positive integers: firstNum and secondNum (firstNum must be smallerthan secondNum).2. Output all the even numbers between firstNum and secondNum inclusive.3. Output the sum of all the even numbers between firstNum and secondNum inclusive.4. Output all the odd numbers between firstNum and secondNum inclusive.5. Output the sum of all the odd numbers between firstNum and secondNum inclusive. Java programming
Write a Java program using jGRASP directions are as follows: Uses a while loop to print...
Write a Java program using jGRASP directions are as follows: 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...
Write a C++ program to print all the perfect numbers below a certain given number. A...
Write a C++ program to print all the perfect numbers below a certain given number. A perfect number is a number that that is equal too the sum of it's divisors other than itself . For example, 6 and 28 are all perfect numbers. 6 = ( 1+2 +3) 28 = (1+2+4+7+14) Make sure your program conforms to the following requirements: 1. Accept the upper limit from the user (as an integer). 2. Make sure the number is positive (at...
In a c programming Write a program that converts upper case letters to lower case letters...
In a c programming Write a program that converts upper case letters to lower case letters or vice versa: Enter a sentence: What a GREAT movie is! Converted sentence: wHAT_A_great_MOVIE_IS_ Convert all non-alphabetical letters to ‘_’
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT