Final Workshop 5 . can you please help me out with this i would like the codes i
ID: 3580301 • Letter: F
Question
Final Workshop 5 . can you please help me out with this i would like the codes in C++ and Python but C++ most importantly and all questions in the same program.
1. Write a loop that prints the numbers 1 through 20 as a countdown;that is, print the
numbers 1 through 20 in reverse order. The number should be on the same line separated
by a space.
2. Create a variable and assign it a number between 1 and 100 inclusively. Next, have the
user guess the number. Make the user continuely guess the number until the user guesses
correctly. Once the user guesses correctly, display the message You got it!".
3. Write a loop that stores integers into a(n) array/list consisting of 100 elements. Each
element should be assigned the sum of consective integers upto its position. For example,
the rst element woul be assigned 1, the second will be assigned 1 + 2 = 3, the third will
be assigned 1+2+3 = 6 and so on. Afterwards, use another loop to display the elements
of the array/list on separate lines.
Explanation / Answer
1) Write a loop that prints the numbers 1 through 20 as a countdown;that is, print the
numbers 1 through 20 in reverse order. The number should be on the same line separated
#include <iostream>
using namespace std;
int main() {
int x,i,value;
for(i=1;i<=20;i++){
value= 20-(i-1);
cout<<value<<" ";
}
return 0;
}
2. Create a variable and assign it a number between 1 and 100 inclusively. Next, have the
user guess the number. Make the user continuely guess the number until the user guesses
correctly. Once the user guesses correctly, display the message You got it!".
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
int value,num;
int i;
for(i=1;i<=100;i++) {
value = rand() % 100 + 1;
cout<<"Enter the number:";
cin>>num;
if(num==value){
cout<<"You got it!";
break;
}
}
cout<<value;
return 0;
}
3. Write a loop that stores integers into a(n) array/list consisting of 100 elements. Each
element should be assigned the sum of consective integers upto its position. For example,
the rst element woul be assigned 1, the second will be assigned 1 + 2 = 3, the third will
be assigned 1+2+3 = 6 and so on. Afterwards, use another loop to display the elements
of the array/list on separate lines.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
int value;
int i;
int arr[100];
for(i=1;i<=100;i++) {
int j=1,sum=0;
while(i>=j) {
sum=sum+j;
j++;
}
arr[i-1] = sum;
}
for(i=0;i<100;i++) {
cout<<arr[i]<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.