求桃子总数
1 #include <stdio.h> 2 3 int main() 4 { 5 int i,n,taozi; 6 while (scanf_s("%d", &n) != EOF) 7 { 8 taozi = 1; 9 for (i = n - 1; i > 0; i--) 10 { 11 taozi = (taozi + 1)*2; 12 } 13 printf("%d ",taozi); 14 } 15 return 0; 16 }
参考答案
1 #include <math.h> 2 #include <stdio.h> 3 4 int main(void) 5 { 6 int n; 7 8 while (scanf("%d", &n) != EOF) 9 printf("%.0f ", 3 * pow(2, n - 1) - 2); 10 11 return 0; 12 }