While we used recursion to do repetition in Scheme, the primary mechanism for repetition in a C program is a new construct called a “loop”.
The goal of this lab is to introduce loops in C programming and increase familiarity with different types of loops.
Earlier this semester, you saw a program (quarts.c.), that converted quarts to liters. Write a program that prints a table listing the conversions from one to twelve quarts into liters.
Use a careful print statement to keep proper spacing in the table.
Example Output:
Table of quart and liter equivalents
Quarts Liters
1 0.9463
2 1.8927
3 2.8390
4 3.7853
5 4.7317
6 5.6780
7 6.6243
8 7.5707
9 8.5170
10 9.4633
11 10.4097
12 11.3560
Driver: The student closer to the whiteboard.
for construct.while construct.The mathematical constant \(e\) is calculated by an infinite series
\[e = 1 + 1/1! + 1/2! + 1/3! + ...\]\(e\) is an irational number, where the first couple digits are \(2.718281828459045...\)
We can approximate the value of \(e\) with a partial sum:
\[1 + 1/1! + 1/2! + 1/3! + ... + 1/n!\]Driver: The student farther to the whiteboard.
scanf function in class, but readings have shown how to use it to ask the user for input.
The following code fragment will ask a user to input an integer value:
printf("Please enter a number:");
int n;
scanf("%d", &n);
printf, you can use the %f format specifier to tell scanf to read a floating point value.Note: You should not include any header files to help you complete this program (such as one with math features). Instead, use loops!
Consider this program output:
Enter a number: 60
Enter a number: 38.3
Enter a number: 4.89
Enter a number: 100.62
Enter a number: 0
The largest number entered was 100.62
Driver: The student closer to the whiteboard.
Can you write this program in as few lines as possible? i.e. don’t repeat the same statement more than once.