This question requires writing a program to calculate
sum = 2 1 + 2 2 + 2 3 +… + 2 n sum=2^{1}+2^{2}+2^{3}+...+2^{n}sum=21+22+23+⋯+2n
can be exponentiated by calling the pow function.
Input format:
Enter a positive integer in one line n(≤10)
.
Output format:
result = 计算结果
Output in the format " ".
Input sample:
5
Sample output:
result = 62
Code:
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
int main() {
int n,result = 0,i;
scanf("%d",&n);
for (i=1;i<=n;i++) {
result += pow(2,i);
}
printf("result = %d",result);
return 0;
}
Submit screenshot:
Problem-solving ideas:
Nothing to say, basic operation!