Question

GLOBAL A Mare out of bodo Question 2 Hagestion Write a C++ program to generate two random integers x and y in the range 10 to

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<bits/stdc++.h>
using namespace std;
int main(){
int x,y,n,i,j;
int a=rand()%31+10; //generating random numbers rand()%31 gives numbers from 0 to 30
int b=rand()%31+10; //so 10 added for ranging from 10 to 40
if(a<b){ x=a; y=b;}
else{ x=b; y=a; }
cout<<"x : "<<x<<endl; cout<<"y : "<<y<<endl;
while(1){
cout<<"Enter option, press 5 for exit : "; cin>>n;
if(n==5) break;
else if(n==1){ //check no of perfect no from 1 to x
int c1=0;
for(j=1;j<=x;j++){
int sum1=0;
for (i=1;i<=j;i++)
if (j%i==0) sum1+=i;
if(j==sum1) c1++;
}
cout<<"Percentage of perfect no from 1 to "<<x<<" is : "<<(c1*100.0/x)<<endl;
}
else if(n==2){ //no of odd divisors of x
int sum2=0,c2=0;
for (i=1;i<=x;i++) {
if (n%i==0 && i%2==1){
sum2+=i;
c2++;
}
}
cout<<"Average of odd divisors of "<<x<<" : "<<(1.0*sum2/c2)<<endl;
}
else if(n==3){ //calculate sum of series
double sum3=0;
for(i=1;i<=x;i++) sum3+=1.0*x/pow(y,x);
cout<<"Sum of the series is : "<<sum3<<endl;
}
else if(n==4){ // no of palindrome no between x to y and their sum
int c=0,sum4=0;
for(i=x;i<=y;i++)
if(i%10== i/10){
c++;
sum4+=i;
}
cout<<"Total "<<c<<" numbers are palindrome and sum of palindrome numbers is "<<sum4<<endl;
}
else{
cout<<"Entered wrong option."<<endl;
}
}
return 0;
}

WN } } 1 #include<bits/stdc++.h> 2 using namespace std; 3- int main(ok 4 int x,y,n,i,j; 5 int a=rand()%31+10; //generating ra

x : 15 Y : 20 Enter option, press 5 for exit : 1 Percentage of perfect no from 1 to 15 is : 6.66667 Enter option, press 5 for

Add a comment
Know the answer?
Add Answer to:
GLOBAL A Mare out of bodo Question 2 Hagestion Write a C++ program to generate two...
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 program that displays this to the user. "Hot Beverage Menu" "A: Coffee $1.00", "B:...

    Write a program that displays this to the user. "Hot Beverage Menu" "A: Coffee $1.00", "B: Tea $ 0.75", "C: Hot Chocolate $1.25", "D: Cappuccino S2.50", "E: Exit Menu" Prompt the user to make a selection. Determine which item the user entered. Use a do-while loop that keeps repeating till the user selects E from the Menu. If the user has selected a valid beverage, prompt the user for how many cups they would like, and print out how much...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • extra credit 1 Write a program that will display the following menu and prompt the user...

    extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...

  • Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and,...

    Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and, on the output, writes the sum of the divisors of n (other than itself). For integers less than or equal to 1 it should print 0. For example, the input -3 0 1 4 5 6 12 should generate the output 0 0 0 3 1 6 16 Explanation of output: The input -3 is less than 1, output is 0. The input 0...

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

  • Part A) Write a C++ program that calculates the area under a curve. Here is the...

    Part A) Write a C++ program that calculates the area under a curve. Here is the equation: f(x) = x^2 +1.5x +4 You must prompt the user for the beginning and the ending x values. You are to assume, but not check, that the user will put in whole positive numbers. The units are inches. The program input/output should look something like this: This program calculates the area under a curve between two points on the x axis. The equation...

  • Using C++ Requirements Note: “deque” STL container is not allowed, for the simplicity for graders. Queue Queue is a firs...

    Using C++ Requirements Note: “deque” STL container is not allowed, for the simplicity for graders. Queue Queue is a first-in-first-out (FIFO) data structure. For the Queue container, we will implement a program that simulates a buffer. The simulation needs a function that randomly generate number. And the buffer simulation starts with no value in the buffer. At the start of simulation, the menu should ask user: how many rounds will be simulated. the percentage chance to put a randomly generated...

  • Programming Fundamental (C++) Lab C++ Lab Ra'fat Amareh Faculty of Engineering and Information Technology Assignment Write...

    Programming Fundamental (C++) Lab C++ Lab Ra'fat Amareh Faculty of Engineering and Information Technology Assignment Write a C++ program that performs the following: Prints on screen a selection menu as follow: a. Sin (x), Series b. Sum odd digit, Print Digits, Print Shape c. Array d. Exit If user presses a or A, the following sub menu should be displayed 1- Sin (x) (Program should solve the following series x - x'/3! + x®/5! – x/7...x"m!) 2- F (Program should...

  • Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds...

    Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds the sum and average of a series of numbers he program should first prompt the user to enter total numbers of numbers are to be summed and averaged. It should then as for input for each of the numbers, add them, and print the total of the numbers and their average 2. Write a progra m that finds the area of a circle. The...

  • Please make a JAVA program for the following using switch structures Write a program that simulates...

    Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...

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