Link to presentation: Intro to C Workshop – Presentation
Complete each of the following questions in C.
Create a program which prints:
Hello World!Create a program which:
- Asks the user to input an integer.
- Prints the integer back to the screen.
Create a program which:
- Defines a float
pas the value of π (PI) to 3 decimal places. - Asks the user to input a radius.
- Calculates the area of the circle.
- Prints the result to 3 decimal places.
Formula for the area of a circle:
Area = p * r²Create a program which:
- Prints the word
countdown. - Prints a countdown from 5 to 1.
- Uses loops and arrays.
Example output:
countdown
5
4
3
2
1Create a program which prints your name using:
- Loops
- Strings
Create a program which prints the integer:
10You must use only pointers and addresses to accomplish this.
(No direct printing of the number is allowed.)
Create a program which:
- Starts with a value of
20. - Uses a
voidfunction nameddivide_by_10. - Divides the value by 10 using pointers and addresses.
- Prints the value before and after the division.
Function prototype:
void divide_by_10(float *value);Create a structure that allows tracking employees in a company with:
- Name
- Employee ID
- Department
- Salary
Then print each employee’s:
- Employee ID
- Department
- Salary
Use the following employees:
| Name | ID | Department | Salary |
|---|---|---|---|
| Bob | 30894 | HR | 83000 |
| Megan | 29836 | Marketing | 85900 |
| Steph | 98763 | IT | 92500 |
| Mo | 93087 | IT | 93840 |
Create a program which:
- Asks the user how many integers they want to store.
- Dynamically allocates enough memory to store that many integers using
malloc. - Uses a loop to let the user input each integer.
- Prints all the integers back to the screen.
- Frees the allocated memory using
free.
Rules:
- You must use
mallocto allocate the array. - You must check that
mallocwas successful. - You must use
freebefore the program exits.
Example run:
How many numbers do you want to store? 4
Enter number 1: 10
Enter number 2: 25
Enter number 3: 7
Enter number 4: 42
You entered:
10
25
7
42