|
|
发表于 2019-1-15 15:24:56
|
显示全部楼层
动动手:
0. 问题:求 1^2 + 2^3 + 3^4 + 4^5 + 5^6 的值?(1^2 表示 1 的 2 次方)
#include <stdio.h>
#include <math.h>
int main(void)
{
int a;
a = pow(1,2)+pow(2,3)+pow(3,4)+pow(4,5)+pow(5,6);
printf("%d", a);
return 0;
}
1. 舍罕王的失算
#include <stdio.h>
#include <math.h>
int main(void)
{
//在这裡声明下边要使用的变量: sum, temp, weight和 i
unsigned long long int sum = 0;
unsigned long long int i, temp, weight=0;
for (i=0; i<64; i++)
{
// 计算每一格要放多少麦子
temp = pow(2,i);
sum = sum+temp;
}
weight = sum / 25000;
printf("舍罕王应该给予达依尔%u粒麦子 !\n", sum);
printf("果每25000粒麦子为1kg, 那么应该给%u公斤麦子 !\n", weight);
return 0;
}
|
|