Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programme Language should be C For this assignment, you are going to randomize 1

ID: 3860050 • Letter: P

Question

Programme Language should be C

For this assignment, you are going to randomize 10 numbers and display them. After you get your numbers, the user is going to be asked a series of questions relating to the numbers. At the end, you will calculate a grade and display it to the user. There will be 5 questions that the student will need to answer. See my example below .. Number 1 = 28 Number 2 = 73 Number 3 = 82 Number 4 = 99 Number 5 = 37 Number 6 = 18 Number 7 = 49 Number 8 = 25 Number 9 = 89 Number 10 = 76 What is the sum of numbers 1 through 10? 456 You are incorrect. The correct answer is 576 What is the Largest of all the numbers? 4 You are incorrect. The correct answer is 99 How many of the numbers are even? 3 You are incorrect. The correct answer is 4 What is the product of these even numbers? 432 You are incorrect. The correct answer is 3140928 What is the difference between the sum of the first 5 and the sun of t he last 5? 4 You are incorrect. The correct answer is 62

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>   
#include <time.h>
int main()
{
int i;
double average;
char grade ;
int sum = 0,evenCount = 0, large;
int first5Sum = 0, last5Sum = 0;
int correct = 0;
int compareValue;
int product = 1;
int result;
char questions[5][100] = {"What is the sum of numbers 1 throough 10? ","What is the largest of all the numbers? ","How many of the numbers are even? ","What is the product of these even numbers? ","What is the difference between the sum of first 5 and the sum of the last 5? "};
int numbers[10];
srand (time(NULL));
for(i=0;i<10;i++){
numbers[i]= rand() % 100 + 1;
}
large=numbers[0];
for(i=0;i<10;i++){
sum = sum + numbers[i];
product=product*numbers[i];
if(numbers[i]%2 == 0){
evenCount++;
}
if(large < numbers[i]) {
large=numbers[i];
}
if(i<5){
first5Sum+=numbers[i];
} else {
last5Sum+=numbers[i];
}
printf("Number %d: %d ", (i+1),numbers[i]);
}
for(i=0;i<5;i++){
printf("%s", questions[i]);
scanf("%ld", &result);
if(i==0) {
compareValue= sum;
} else if(i==1) {
compareValue= large;
} else if(i==2) {
compareValue= evenCount;
} else if(i==3) {
compareValue= product;
} else{
compareValue= first5Sum-last5Sum;
}
if(result == compareValue) {
correct++;
printf("You are right ");
} else {
printf("You are incorrect. The correct answer is %d ",compareValue);
}
}
average = (correct*100)/(double)5;
if(average >= 90) {
grade='A';
} else if(average >= 80 && average<90){
grade ='B';
} else if(average >= 70 && average<80){
grade ='C';
} else if(average >= 60 && average<70){
grade ='D';
} else {
grade='F';
}
printf("You have earned %lf percentage on these questions. Your have received an %c in the class. ",average, grade);

return 0;
}

Output:

sh-4.2$ main                                                                                                                                                                                          

Number 1: 100                                                                                                                                                                                         

Number 2: 41                                                                                                                                                                                          

Number 3: 42                                                                                                                                                                                          

Number 4: 41                                                                                                                                                                                          

Number 5: 17                                                                                                                                                                                          

Number 6: 98                                                                                                                                                                                          

Number 7: 30                                                                                                                                                                                          

Number 8: 12                                                                                                                                                                                          

Number 9: 62                                                                                                                                                                                          

Number 10: 18                                                                                                                                                                                         

What is the sum of numbers 1 throough 10? 66                                                                                                                                                          

You are incorrect. The correct answer is 461                                                                                                                                                          

What is the largest of all the numbers? 77                                                                                                                                                            

You are incorrect. The correct answer is 100                                                                                                                                                          

How many of the numbers are even? 2                                                                                                                                                                   

You are incorrect. The correct answer is 7                                                                                                                                                            

What is the product of these even numbers? 456                                                                                                                                                        

You are incorrect. The correct answer is -455770624                                                                                                                                                   

What is the difference between the sum of first 5 and the sum of the last 5? 99                                                                                                                       

You are incorrect. The correct answer is 21                                                                                                                                                           

You have earned 0.000000 percentage on these questions. Your have received an F in the class.