Area of a rectangle
Combine two parameters into one result. An easy embedded C problem (First steps in C), run and graded in the browser.
easy · First steps in C · arithmetic · parameters
A display driver needs to know how many pixels a rectangle covers.
Return the area of a rectangle that is width wide and height high.
Starter code
int area(int width, int height) {
return 0;
}Example tests
Three by four
printf("%d\n", area(3, 4));Expected output:
12A thin rectangle
printf("%d\n", area(10, 1));Expected output:
10Learn it first
- Microcontrollers and your first program · What a microcontroller is, how code gets onto it, and the parts of a C program.
More First steps in C problems
- Return a value · Make a function hand back a number.
- Add two numbers · Use the inputs a function receives.
- Fix a compiler error · Read an error message and repair the code.
- Minutes to seconds · Convert a duration with one multiplication.
- Print a line · Send text to the output with printf.
- Print a number · Put a value into printed text with a placeholder.