-
Notifications
You must be signed in to change notification settings - Fork 1
/
Power_x_y.c
50 lines (48 loc) · 855 Bytes
/
Power_x_y.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
47
48
49
50
/*
*File name:
*Source file name:
*Author: Tamkien Cao
*Last modified: Fri, Feb 22nd, 2019
*Other info: exercise 2.4
*Version: 1.0
*/
#include<stdio.h>
#include<stdlib.h>
int power(int x, int y)
{
int S = 1;
for (int i = 1; i <= y; i++)
{
S *= x;
}
return S;
}
main()
{
int x, y, S = 1;
printf("This program can help you calculate x^y.\n");
printf("=================================\n");
do
{
printf("Enter x here enter 0 to exit.\n");
scanf_s("%d", &x);
if (x == 0)
{
printf("0^n = 0\n");
break;
}
else
{
printf("Enter y here\n");
scanf_s("%d", &y);
for (int i = 1; i <= y; i++)
{
S *= x;
}
printf("%d^%d = %d\n\n", x, y, power(x, y));
}
} while (1);
printf("\n=================================\n");
printf("Written by Tamkien Cao. Thank you for using my application!\n");
system("pause");
}