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

In C language (not C++) Write a segment of code to do each of the following. 1.

ID: 3680956 • Letter: I

Question

 In C language (not C++) 
 Write a segment of code to do each of the following. 
    
 1. Input a set of numbers (integers) terminated by the value -999.  Calculate the 
 average, the largest and smallest value in the set of numbers. 
    
 2. Print a metric conversion chart  which shows pounds converted to kilograms. 
 Chart should print pounds from 1 to 50 and their equivalent kilograms.  (there 
 are 2.2 pounds in 1 kilogram. 
    
 3. Prompt the user to enter a sentence terminated by the enter key.  Report the 
 number of vowels, digits, question marks, commas, periods and letters in the 
 sentence. 
    
 4. Ask the user to input 2 numbers, output the sum of the squares of the 2 
 numbers.  Continue to get numbers until the user answers 'n' when asked to 
 repeat again. 
    
 5. Find the sum of the numbers from 100 to 200 inclusive. 
    
 6.  Write a menu driven program that has the following options: 
     1. Print Thanksgiving greeting 
     2. Print Halloween greeting 
     3. Print Birthday Greeting 
     4. Quit  
    
 7. Write a program that does the following:  Finds the greatest common divisor 
 of 2 integers as input from the user.  Program repeats the process until the 
 user wants to quit.  (To find the greatest common divisor, divide the smaller 
 number into the larger number, get the remainder.  As long as the remainder is 
 not zero, the old divisor becomes the dividend, the old remainder becomes the 
 divisor, and get the next remainder.  Keep doing this until you get a zero 
 remainder, when that happens the last divisor (causing the 0 remainder) is the 
 greatest common divisor. 
    
 8. Write a program to count the number of words, letters, digits, and 
 punctuation on an input file.  Words are terminated by a blank space, a period, 
 or an exclamation point or the end of a line.   
    
 9. Print a chart of the decimal ascii codes from 32 to 126 showing the char and 
 its numeric code. 
    
 10. Print a list of the positive integers less than 1000 that are divisible by either 5 
 or 6.  When the list is complete, print a count of the number of integers that 
 were found. 
    
 11. If an organism doubles its population every 12 hours, and you start with 100 
 organisms, how many hours will it take to have 1 million organisms? 
    
 12. Calculate the factorial of a number, what is the biggest integer number 
 without overflow you can get the factorial of using integers? floating point? 
    
 13.  Given a file of test scores ending with -1, count the number of a's, b's, c's, 
 d's and f's on the file, and calculate the overall average of all the scores.  
    
 14.  Given an input file consisting of a well number(integer), barrels produced(integer) and 
 a water factor (real) on each record, sentinel record is any negative well number on a line 
 by itself.  Produce a production report.  The report contains the data on the file, nicely 
 formatted plus the actual barrels of oil produced and the selling value of the oil.  The 
 actual barrels produced is the water factor taken out of the barrels shown.  The water 
 factor is a value in decimal form that represents the amount of water in the barrels 
 produced by each well.  This  must be deducted from the barrels given to reflect the actual 
 barrels produced.  The selling value of the oil is the market price reduced by 5%.  The 
 market price is currently 13.41 per barrel.  The report should be written to an output file. 
    
 15.  Produce the nth fibonnaci number in the fibonnaci sequence.  Ask the user to input 
 which number in the sequence that they want to know and then output the appropriate 
 value.  The fibonacci sequence consists of the numbers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 
 etc.  So for example if the user asked for the 6th number in the sequence the program 
 would report the value 5.   
    
 16.  Which is a better deal?  You are given .01  (a penny) on the first day of the month.  A 
 person offers you one of these deals:  You can accept either 1 million dollars today or take 
 the penny which the person will double its value everyday for the entire month of 30 days. 
 SO on day 1 you will have .01, on day 2 you will have .02, on day 3 you will have .04  
 etc.  At the end of the month you receive the money total as it doubles itself every day.  
 Which deal is worth the most?  Write a program to decide. 

Explanation / Answer

1.

#include <stdio.h>
#include <limits.h>

int main() {
int input;

int count = 0;
int sum = 0;
int largest = INT_MIN;
int smallest = INT_MAX;

scanf("%d", &input);
while(input != -999) {
count += 1;
sum += input;
largest = (largest > input ? largest : input);
smallest = (smallest < input ? smallest : input);
scanf("%d", &input);
}

printf("Average = %lf ", sum * 1.0 / count);
printf("Largest = %d ", largest);
printf("Smallest = %d ", smallest);
return 0;
}

2.

#include <stdio.h>

int main() {
int i;
printf("%10s %s ", "Kilogram(s)", "Pound(s)");
for (i = 1; i <= 50; ++i) {
printf("%10d %10.2lf ", i, i * 2.2);
}
return 0;
}

3.

#include <stdio.h>
#include <string.h>

int main() {
char s[1000];
printf("Enter sentence: ");
gets(s);
int len = strlen(s) - 1;

int vowels = 0, digits = 0, question_marks = 0, commas = 0, periods = 0, letters = 0;
while (len >= 0) {
char Vowels[] = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
int i;
for (i = 0; i < 10; ++i) if (Vowels[i] == s[len]) {
vowels++;
break;
}
if (s[len] >= '0' && s[len] <= '9') ++digits;
if ((s[len] >= 'a' && s[len] <= 'z') || (s[len] >= 'A' && s[len] <= 'Z')) ++letters;
if (s[len] == '?') ++question_marks;
if (s[len] == '.') ++periods;
if (s[len] == ',') ++commas;

len = len - 1;
}

printf("Vowels: %d ", vowels);
printf("Digits: %d ", digits);
printf("Question Marks: %d ", question_marks);
printf("Commas: %d ", commas);
printf("Periods: %d ", periods);
printf("Letters: %d ", letters);
return 0;
}

4.

#include <stdio.h>

int main() {
while (1) {
int a, b;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
printf("Sum of squares of %d and %d: %d ", a, b, a * a + b * b);
printf("Do you want to continue? ");
char uch; scanf("%c", &uch);
scanf("%c", &uch);
if (uch == 'n') break;
}
return 0;
}

Please post rest of the questions as separate one.