Experiment 2-4-6 Find the sum of powers (15 points)

This question requires writing a program to calculate sum=2 1 +2 2 +2 3 +...+2 n . You can call the pow function for exponentiation.

Input format:
Input a positive integer n (≤10) in one line.

Output format: output
according to the format "result = calculation result".

Input sample:
5
Output sample:
result = 62
title collection complete works portal

#include <stdio.h> 
#include <math.h>
int main(void)
{
    
    
    int n, sum = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        sum += pow(2, i);
    printf("result = %d", sum);

    return 0;
}

Guess you like

Origin blog.csdn.net/fjdep/article/details/112747181