Question

In: Computer Science

C Programming- How would the whole part 1 be coded with multiple loops? Part 1: You...

C Programming- How would the whole part 1 be coded with multiple loops?

Part 1:

You can do A, B, and C in one program with multiple loops (not nested) or each one in a small program, it doesn’t matter.

A. Create a loop that will output all the positive multiples of 9 that are less than 99.

9 18 27 36 45        ….

B. Create a loop that will output all the positive numbers less than 200 that are evenly divisible by both 2 and 7.

14        28        42        …

C. Create a loop that will calculate the sum of the positive multiples of 8 that are between 100 and 500. Output the sum.

Part 2:

You’re the teacher now! You need to count how many passing grades are entered. We don’t know how many grades there will be. Use a sentinel controlled while loop that will ask the user to enter student grades until a value of -1 is entered. Use a counter variable to count all the grades that are passing grades, where 70 is the minimum passing grade (I know, you’re a tough grader!) If there are any grades that are out of the valid range (0 through 100), present an error message to the user, and do not count that grade as passing (or valid). We also would like to see what percentage of the valid grades are passing.

Create 3 test cases. Use this as one of them:

Grades Entered:                                 Expected Results

45

90

70

87

123                                                      That is not a valid grade!

100

-1                                                         You entered 4 passing grades.

                                                            80.0% of the valid grades are passing.

Create two more sets of test data of your own, and include screenshots of your program running them. Demonstrate all program functionality.

Solutions

Expert Solution

Solution

Part 1

code

#include <stdio.h>

int main()
{
//part A
//print multiples of 8 less than 99
printf("print multiples of 8 less than 99\n");
for(int i=1;i<99;i++)
if(i%9==0)
printf("%d ",i);
printf("\n");
//part B
//print all the positive numbers less than 200 that are evenly divisible by both 2 and 7
printf("Output all the positive numbers less than 200 that are evenly divisible by both 2 and 7\n");
for(int i=1;i<200;i++)
if(i%2==0 && i%7==0)
printf("%d ",i);
//part C
//Calculate the sum of the positive multiples of 8 that are between 100 and 500
printf("\nsum of the positive multiples of 8 that are between 100 and 500\n");
int sum=0 ;   
for(int i=100;i<=500;i++)
if(i%8==0)
sum=sum+i;
printf("Sum=%d",sum);


return 0;
}

Screenshot

Output

---

Part 2

Code

#include <stdlib.h>
#include <stdio.h>

int main() {
   int grade = 0;
   double passPercent, countgrades = 0, countpassinggrades = 0,countvalidgrades=0;

   while (grade != -1) {
       printf("Enter the test grades of the class (-1 to quit): ");
       scanf("%d", &grade);
      
  
           countgrades = countgrades + 1;
if (grade >= 0 && grade<=100) {
           countvalidgrades = countvalidgrades + 1;
       }

       if (grade >= 70 && !(grade < 0 || grade > 100)) {
           countpassinggrades = countpassinggrades + 1;
       }

       if (grade < 0 && !(grade == -1) || grade > 100) {
           printf("That is not a valid grade!. \n");
       }
   }

   passPercent = (countpassinggrades / countvalidgrades) * 100.00;
   printf("You entered %.0lf passing grades \n", countpassinggrades);
  
   printf("The percentage of passing grades is: %.1lf \n", passPercent);

return 0;
}

Screenshot

Output

---

all the best


Related Solutions

Part II: Programming Questions NOTE: CODING LANGUAGE IS C# PQ1. How would you declare the following...
Part II: Programming Questions NOTE: CODING LANGUAGE IS C# PQ1. How would you declare the following scalar and non-scalar (vector) variables? counter, an integer sum, a decimal number average, a decimal number grades, an array of 32 decimal numbers PQ2. How would you initialize the array above with numbers between 0.0 and 4.0 representing the grades of all courses a senior has received in the four years of college? Instead of initializing the array above, how would you, in a...
C++ programming interest using for loops. I'm fairly new to C++ programming. I really don't get...
C++ programming interest using for loops. I'm fairly new to C++ programming. I really don't get for loops, and wanted help with this question. How do I go about it? 1a. Write a program to ask the user for the starting balance of their savings account, what interest rate they are earning, and how many years they are planning to keep the account open. To calculate the new balance, including compounded interest: use a for loop to loop through the...
C Programming Please write a single function and not the whole program Can you please provide...
C Programming Please write a single function and not the whole program Can you please provide comments and explanations for all questions. Thank you Write a single function for the following: void split_date(int day_of_year, int year, int *month, int *day);             day_of_year is an integer between 1 and 366, specifying a particular day within the year designated by the parameter year. Month and day point to variables in which the function will store the equivalent month (1 – 12) and day...
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output. Assignment: It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory. You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more...
C programming Rewrite the following function using no loops, and only tail call recursion double question5...
C programming Rewrite the following function using no loops, and only tail call recursion double question5 (int in) { int i; int result; for (result = rand(), i = 0; i < in; i += 3) { result /= i; result += rand(); } return result; }
Linear Programming The Whole Food Nutrition Centre uses three bulk grains, A, B, and C, to...
Linear Programming The Whole Food Nutrition Centre uses three bulk grains, A, B, and C, to blend a natural cereal that it sells by the pound. The cost of each bulk grain is indicated in the table below, along with the units of four types of nutrient (Nutrient 1, 2, 3, and 4) that is contained in each pound of the grains.   After consulting with the nutritionist, Whole Food has determined that each pound serving of the cereal should contain...
how would i change the for loops to while loops in the code below #include<stdio.h> #include<stdlib.h>...
how would i change the for loops to while loops in the code below #include<stdio.h> #include<stdlib.h> int main() { int seed; // Taking seed value as input from the user printf("Enter a seed value (0 to quit): \n"); scanf("%d", &seed); // Running the loop until user enters 0 to quit // count array will count frequency of 0 , 1 , 2 ,3 int count[4]; for (int i = 0; i < 4; i++) count[i] = 0; while (seed !=...
11. Read about how flexible for-loops are in C. Write two examples of "non-traditional" for-loops (ie,...
11. Read about how flexible for-loops are in C. Write two examples of "non-traditional" for-loops (ie, for-loops that don't look like for-loops you learned in introductory courses) and explain how they work. 12. Compare/contrast case/when in Ruby with a switch statement in another language of your choice. 13. What does the last keyword do in a loop in Perl? 14. Many contemporary PLs allow two kinds of comments: one in which delimiters are used on both ends (multiple-line comments) and...
**CODED IN C LANGUAGE** Case 1: The given snapshot in the assignment instructions checks for the...
**CODED IN C LANGUAGE** Case 1: The given snapshot in the assignment instructions checks for the following: P to be switched with Q (Once done will remain as it is in all the rows) If the user enters the same P again, the program must not make any changes For instance, given elements are 0123456789 3 4          0              0124456789 2 5          1              0154456789 (Keeping the change in Row 0 (input for row 1); 2 is switched to 5) 1 6          2              0654456789 (Keeping...
Python Programming This assignment will give you practice with interactive programs, if/else statements, collections, loops and...
Python Programming This assignment will give you practice with interactive programs, if/else statements, collections, loops and functions. Problem Description A small car yard dealing in second hand cars needs an application to keep records of cars in stock. Details of each car shall include registration(rego), model, color, price paid for the car (i.e. purchase price) and selling price. Selling price is calculated as purchased price plus mark-up of 30%. For example, Toyota Corolla bought for $20,000 will have the selling...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT