Accept any three numbers and find their squares and cubes.

This is one of the easiest C program. All you have to do is, accept three numbers and display their squares and cubes.

## Steps 🪜

### To find squares and cubes of 3 numbers

- Display a message to the user and accept three numbers. Store these values in three variables
**n1**,**n2**and**n3**. Since, we can display the results directly using printf statements that is why no need to declare extra variables to store the results. - Write three printf() statements to display the modulo operation by 2, 3 and 4 respectively. That’s it. 😎

## Flow Chart 🌻

Check how to draw flow chart for this program.

## Code 💻

```
#include <stdio.h>
#include <conio.h>
int main()
{
float n1=0, n2=0, n3=0;
printf("Please enter 3 numbers:\n");
scanf("%f%f%f", &n1, &n2, &n3);
// Square and Cube of n1
printf("\n\nSquare of n1: %0.2f", n1 * n1);
printf("\n\nCube of n1: %0.2f", n1 * n1 * n1);
// Square and Cube of n2
printf("\n\nSquare of n2: %0.2f", n2 * n2);
printf("\n\nCube of n2: %0.2f", n2 * n2 * n2);
// Square and Cube of n3
printf("\n\nSquare of n3: %0.2f", n3 * n3);
printf("\n\nCube of n3: %0.2f", n3 * n3 * n3);
return 0;
}
```

## Example 😍

Let’s assume, the user enters 3 numbers as 2, 4 and 6. As we know, it is displaying results directly through printf statements without any extra variables.

So, first it will display the squares and cubes of 2 i.e. 4 and 8. Next, it will display the squares and cubes of 4 i.e. 16 and 64. Finally, it will display the squares and cubes of 6 i.e. 36 and 216.

The output will be like this:

```
Square of n1: 4
Cube of n1: 8
Square of n2: 16
Cube of n2: 64
Square of n3: 36
Cube of n3: 216
```

This is how you can find squares and cubes of any 3 numbers. 😇

For more C Programs, click here.

## Comments