## 请教一个C语言的问题

@学PHP的小蚂蚁 你好，想跟你请教个问题：

1.       输入n（正整数，2位数），计算nn次方的后3位数字。

#include <stdio.h>
#include <math.h>
main()
{
int  n=0, a, b, c;
float z=0;
printf("请输入一个两位整数：\n");
scanf("%d", &n);
z = pow (n,n);
a =  z/100%10;
b = z/10%10;
c = z%10;
printf("%lf\n", z);
printf("%d%d%d",a,b,c);
return 0;
}

0

z是一个float类型的数，其与int型的数运算的结果还是float型。而float类型不能求余。

```#include <stdio.h>
#include <math.h>
int main()
{
int  n=0;
double z=0;
printf("请输入一个两位整数：\n");
scanf("%d", &n);
z = pow (n,n);
while(z >= 1000){
z-=1000;
}
n = z;
printf("%lf\n", z);
printf("%03d",n);
return 0;
}```

0

0
```#include <stdio.h>

int main()
{
unsigned int n, i, j;
printf("integer: ");
scanf("%d", &n);

j = n;
for (i = 1; i < n; i++) {
j *= n;
j %= 1000;
}

printf("%03d\r\n", j);
}```

0
```#include<stdio.h>
#include<math.h>
#include<string.h>

int main(){

int a=0;
double n=0;

printf("double size is:%ld\n",sizeof(n));

scanf("%d",&a);

printf("get intput is :%d\n",a);

if(a>100){
printf("\n");
printf("-------------------------------\n");
printf("the input value must be <100!!!\n");
printf("-------------------------------\n");
printf("\n");
return -1;
}

n=pow(a,a);

printf("cacul result is:%lf\n",n);

char str[512];
int j=0;
for(j=0;j<256;j++){
str[j]='a';
}

sprintf(str,"%lf",n);
printf("get str is:%s\n",str);

printf("without point . is:");
int index=0;
int i=0;
for(i=0;i<256;i++){
if((str[i]>='0')&&(str[i]<='9'))
printf("%c",str[i]);
else{
index=i;
break;
}
}

printf("\n");

printf("point . index is:%d\n",index);

if(index>=3){
printf("last three value is:");
int k=index-3;
for(;k<index;k++)
printf("%c",str[k]);
printf("\n");
}else{
int g=n;
printf("last three value is:%d\n",g);
}

return 0;
}```

0
```/**
* @param num1
* @param num2
* @param c    +     -     *     /      ^  (加  减  乘  除  幂)
* @return result
*/
public static String getBigNumCalculate(String num1, String num2, char c) {
BigDecimal b1 = new BigDecimal(num1);
BigDecimal b2 = new BigDecimal(num2);
BigDecimal result = null;
switch (c) {
case '+':
break;
case '-':
result = b1.subtract(b2);
break;
case '*':
result = b1.multiply(b2);
break;
case '/':
result = b1.divide(b2);
break;
case '^':
int i = Integer.parseInt(num2);
if (i>=1) {
for (int k = 0; k < i-1; k++) {
b1 = b1.multiply(b2);
}
}
result = b1;
break;
default:
break;
}
if (result == null) {
return "";
} else {
return result.toString();
}

}```