Write the code that will compute the sum of the first n positive integer that ar
ID: 3682642 • Letter: W
Question
Write the code that will compute the sum of the first n positive integer that are multiply by 7 for ex if n is 4 you should Compute 7+14+21+28 which would have a sum of 70 read the value for n from the user and display the sum to the screen with a apply
Write a method called validation parking code that accept a character represent the parking permit type(for employee and student)
Write a program to read a list of non negative integers and to display the largest integer ,the smallest integer and the average of all the integers. The user indicates the end of the input by entering a negative sentinel value that is not used in finding the largest,smallest,and average values.this average should be a value of type double so that it is computed with a fractional part
Write a program that simulates the magic 8 ball game .Upon running the program,generate a random number such that one of following 8 response is output:
It is certain
It is decidedly so
Most likely
Signs point to yes
Reply hazy,try again
Ask again Later
Don’t count on it
My sources say no
There should be an equal chance for any chance for any one of the eight responses to come up.The program should ask the user if he or she would like to repeat the program and loop if the user opts to repeat.You can use this formula :
Int num=(int)(math.random() *8)+1;
Explanation / Answer
(1)
#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
int ans=7*((n)*(n+1))/2;
cout<<"Sum of first n numbers which are multiples of 7 are: "<<ans<<endl;
return 0;
}
(2)
void validation(char ch){
if(ch=='s')
cout<<"Parking type for Student"<<endl;
else if(ch=='e')
cout<<"Parking type for employee"<<endl;
else
cout<<"Invalid parking"<<endl;
}
(3)
#include <iostream>
#include <vector>
using namespace std;
int main(){
double avg;
int max,min,i,temp,sum;
vector<int> vec;
cin>>temp;
while(temp>=0){
vec.push_back(temp);
cin>>temp;
}
for(i=0;i<vec.size();++i){
sum=sum+vec[i];
if(i==0){
min=vec[i];
max=vec[i];
}
else{
if(vec[i]<min)
min=vec[i];
if(vec[i]>max)
max=vec[i];
}
}
cout<<"Smallest number is: "<<min<<endl;
cout<<"Largest number is: "<<max<<endl;
cout<<"Average of the numbers is: "<<(double)(sum)/(double)(vec.size())<<endl;
return 0;
}
(4)
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(){
while(true){
cout<<"Do you want to simulate magic 8 ball game? "<<endl;
cout<<"Enter 1 to continue"<<endl;
cout<<"Enter any other key to quit"<<endl;
int enter;
cin>>enter;
if(enter==1){
srand (time(NULL));
int rand1 = rand() % 8 + 1;
if(rand1==1)
cout<<"It is certain"<<endl;
else if(rand1==2)
cout<<"It is decidedly so"<<endl;
else if(rand1==3)
cout<<"Most likely"<<endl;
else if(rand1==4)
cout<<"Signs point to yes"<<endl;
else if(rand1==5)
cout<<"Reply hazy,try again"<<endl;
else if(rand1==6)
cout<<"Ask again Later "<<endl;
else if(rand1==7)
cout<<"Don’t count on it"<<endl;
else if(rand1==8)
cout<<"My sources say no"<<endl;
}
else
break;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.