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

c++ programming .c format stdio.h No iostream. thanks!! ETHeading 1 Normal 1No S

ID: 3699642 • Letter: C

Question

c++ programming
.c format
stdio.h
No iostream.
thanks!!

ETHeading 1 Normal 1No Spa TiteSubiale Paragraph Styles alled, but first we need to close some apps. Update now Programming Assignment S Due Wednesday, April 4, 2018 at end of the day. each of the programs assigned below, upload the c file to Canvas, Assignment 8 Observe the usual guidelines regarding the initial comment section, indenting, and so on. LIn function main declare an integer artay with 7 elements. Seed the random number generator with time. To each element of the array, assign a random number between 5 and 25. Print the numbers. Create a menu of choices of values to be calculated ftom the array values: L=>Largest (maximum) of the numbers M=->Minimum of the numbers PProduct of the numbers Q Sum of square roots of each of the numbers SSum of the numbers Use a switch statement to handle the different chotces. Within each case, calculate the appropriate result Include a default for an improper choice Use for loops to calculate the appropriate array sams products, maxima minima, etc within cases Results may be printed either within the cases or after the switch Enclose the switch m.am.outer while loop so that the user may calculate another result without restatting the program.

Explanation / Answer

The code for the first program concerning the random generated array is :


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
{
    printf("The following options are availble: ");
    printf("L : To calculate the maximum number ");
    printf("M : To find the minimum number ");
    printf("P : To find product of the numbers ");
    printf("Q : TO find the sum of square root of each number ");
    printf("S : To find the sum of all numbers ");
    printf("E : To exit "); // extra case to exit the while loop
    while (1)
    {
        srand(time(0)); // to seed the random function with the current time
        int i;
        int arr[7]; // to intialize an array
        char ch;
        for (i = 0; i < 7; i++)
        {
            arr[i] = (rand() % (20)) + 5; // to store random integers in the given limit in the array
            printf("%d ", arr[i]); // to print the numbers simultaneously
        }
        printf(" ");
        printf("Enter the desired option : ");
        scanf("%c%*c", &ch); // the extra *c is to avoid the scanf problem with while loop, without it it skips the scanf every other loop
        switch (ch)
        {
        case 'L':
        {
            int max = 0;
            for (i = 0; i < 7; i++)
            {
                if (arr[i] > max)
                {
                    max = arr[i];
                }
            }
            printf("The largest number is %d ", max);
            break;
        }
        case 'M':
        {
            int min = 26;
            for (i = 0; i < 7; i++)
            {
                if (arr[i] < min)
                {
                    min = arr[i];
                }
            }
            printf("The smallest number is %d ", min);
            break;
        }
        case 'P':
        {
            long int mul = 1; // using long long so as to prevent overflow
            for (i = 0; i < 7; i++)
            {
                mul *= arr[i];
            }
            printf("The product of all the numbers is %ld ", mul);
            break;
        }
        case 'Q':
        {
            double sum = 0; // using double as sqrt() has output as double
            for (i = 0; i < 7; i++)
            {
                sum += sqrt(arr[i]);
            }
            printf("The sum of square root of each of the numbers is %lf ", sum);
            break;
        }
        case 'S':
        {
            int sum = 0;
            for (i = 0; i < 7; i++)
            {
                sum += arr[i];
            }
            printf("The sum of all the numbers is %d ", sum);
            break;
        }
        case 'E':
        {
            printf("Exited successfully "); //This has to be specified or else it will consider 'E' in the default case
            break;
        }
        default:
        {
            printf("Please enter correct value ");
        }
        }
        if (ch == 'E') // condition to exit the loop
            break;
    }
    return 0;
}

The code for the ISBN problem is as follows :


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
{
int isbn[10];
printf("Enter each digit seperately on new lines : "); // Hit enter after every single digit
int i;
for(i = 0; i < 10; i++)
{
scanf("%d", &isbn[i]);
}
printf(" ");
int factor[10];
printf("Enter the weighting factors seperately on new lines : "); // Hit enter after every input
for(i = 0;i < 10; i++)
{
scanf("%d", &factor[i]);
}
printf(" ");
int value[10];
int sum = 0;
for(i = 0;i < 10; i++)
{
value[i] = isbn[i] * factor[i]; // getting weighted values by multiplying
sum += value[i]; // computing the sum simultaneously
}
if(sum % 11 == 0) // checking if the sum of weighted values with modulo 11
{
printf("Valid ISBN number ");
}
else
{
printf("Invalid ISBN number ");
}
return 0;
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote