-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
46 lines (45 loc) · 1.31 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// C code
// This program will provide options for a user to calculate the square // or cube of a positive Integer input by a user.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include <stdio.h>
// Function prototypes
int Square(int value);
int Cube(int value);
int main () {
/* variable definition: */
int intValue, menuSelect,Results;
intValue = 1;
// While a positive number
while (intValue > 0)
{
printf ("Enter a positive Integer\n: ");
scanf("%d", &intValue);
if (intValue > 0)
{
printf ("Enter 1 to calculate Square, 2 to Calculate Cube \n: "); scanf("%d", &menuSelect);
if (menuSelect == 1)
{
// Call the Square Function
Results = Square(intValue);
printf("Square of %d is %d\n",intValue,Results);
}
else if (menuSelect == 2)
{
// Call the Cube function
Results = Cube(intValue);
printf("Cube of %d is %d\n",intValue,Results);
} else
printf("Invalid menu item, only 1 or 2 is accepted\n"); }
} return 0;
}
/* function returning the Square of a number */
int Square(int value)
{
return value*value;
}
/* function returning the Cube of a number */
int Cube(int value)
{
return value*value*value;
}