-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab9b1.c
More file actions
34 lines (32 loc) · 778 Bytes
/
lab9b1.c
File metadata and controls
34 lines (32 loc) · 778 Bytes
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
#include<stdio.h>
int power(int a, int n);
int main()
{
int a, n;
printf("nhap so nguyen a: ");
scanf("%d", &a);
printf("nhap so nguyen n: ");
scanf("%d", &n);
int ret;
ret = power(a,n);
if(n >=0)
{
printf("ket qua la: (%d)^%d = %d", a, n, ret);
}else
printf("khong ho tro tinh luy thua am, nhap lai n > 0.");
while(getchar() != '\n');
return 0;
}
int power(int a, int n)
{
int result;
result =1;
if(n >= 0)
{
for(int i=0;i<n;i++)
{
result = result * a;
}
return result;
}
}