Question

MULIMI Umplicated than the hrst assignment. Write a program that will let the user enter an integer. If the integer is less t
2:18
0 0
Add a comment Improve this question Transcribed image text
Answer #1

As you not specified any language to code this, so first i am providing you the pseudo code of this program as if you want to code in other language then you can use this pseudo to make required function then i will provide you the c++ code of this program.

Pseudo code:

===========================================================================

function printNumberTill( N )

step 1. i = 1 repeat step 2 to 8 until we get i>N and increment i.

step 2. If i is divisible by both 3 and 5 then

step 3. print "fizzbuzz"

step 4 otherwise. if i is divisible by 3 then

step 5. print "fizz"

step 6. otherwise if i is divisible by 5 then

step 7. print "buzz"

step 7. otherwise

step 8. print i

==============================================================

I hope you understand above pseudo code.

below is my c++ code.

=================================================================

#include<iostream>

using namespace std;

// Function to print number or fizz or buzz or fizzbuzz on each line till n

void printTillN(int n){

// Iterating till i becomes equal to n

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

// checking condition is i is divisible by both or not

if(i%3==0 && i%5==0){

// printing the fizzbuzz

cout<<"fizzbuzz"<<endl;

}else if(i%3==0){ // checking condition is i is divisible by 3 or not

// printing the fizz

cout<<"fizz"<<endl;

}else if(i%5==0){ // checking condition is i is divisible by 5 or not

// printing the buzz

cout<<"buzz"<<endl;

}else{ // else we just print the number itsself

// printing the number itself

cout<<i<<endl;

}

}

}


// Driver function

int main(){

//Declaring the variable

int n;

cout<<"Enter an Integer : ";

// taking input from the user

cin>>n;

// checking if n is less than 5

if(n<5){

// then assigning 50 to n

n = 50;

}

// calling the printing function

printTillN(n);

return 0;

}

====================================================================

Screenshot of my code edior.

An output of the above code.

I hope this will help.
Leave a comment if you have any query or want to tell any suggestion
If you found it helpful Up Vote it
Thank you

Add a comment
Know the answer?
Add Answer to:
MULIMI Umplicated than the hrst assignment. Write a program that will let the user enter an...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a perl program that prompts a user for a number and checks that number against...

    Write a perl program that prompts a user for a number and checks that number against three possibilities. If the number is divisible by 3, it should print fizz, if its divisible by 5 it should print buzz, and if its divisible by 3 and 5 it should print fizzbuzz. It should do nothing if none of those conditions are met. I need help with this.

  • C++ Write a program that prompts the user to enter two positive integers: num1 and num2....

    C++ Write a program that prompts the user to enter two positive integers: num1 and num2. - Validate that num1 is less than num2 and that both numbers are positive. If any of these conditions are not met, allow the user to re-enter num1 and num2 until the input is determined valid. - For all integers from num1 through num2, print the word keyboard if the current integer is divisible by 2 and print the word mouse if the current...

  • (1) Read in a number from the user that is in the ranger 1-200. If the...

    (1) Read in a number from the user that is in the ranger 1-200. If the user inputs a number out of that range, print out:Invalid number, try again. and read in a number until a valid one is produced. (2) Print out the numbers from 1 to userInput but: If a number is divisible by 3, print Fizz instead If a number is divisible by 5, print Buzz instead If a number is divisible by both 3 and 5,...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Write a program which asks the user to enter an integer. Use switch statement to write...

    Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...

  • Exercise 9.2 Write a Python program that collects from the user a single integer. Have the...

    Exercise 9.2 Write a Python program that collects from the user a single integer. Have the program print “EVEN” if the integer is divisible by 2, and “ODD” if the integer is not divisible by two. [Use the % operator to compute the two’s modulus (remainder of division by two)] Exercise 9.3 Write a Python program that collects from the user two integers. Have the program print “Yes” if the two integers are BOTH greater than 10. Do nothing if...

  • 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters...

    5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. ​ 1 largest = None 2 smallest = None 3 while True: 4...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Write a program that prompt the user to enter 3 integers: x,y and z. Your program...

    Write a program that prompt the user to enter 3 integers: x,y and z. Your program should output the answer to the user based on the divisibility of x and y by z as follows: Input If both x and y are divisible by z Result X and y are both divisible by 2. X is divisible by z. Y is divisible by z. Both X and Y are not divisible by If x is only divisible by z If...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT