首页 > 其他分享 >task3

task3

时间:2022-10-18 11:02:51浏览次数:42  
标签:main task3 int sum a1 include

#include<stdio.h>
#include<math.h>

int main()
{
     unsigned int sum;
    int n,a1, q;
    scanf_s("%d", &n);
    a1 = 1;
    q = 2;
    sum = a1*(1 - pow(q,n) )/ (1 - q);
    
    printf("n=:%d,sun=%u\n", n, sum);

    return 0;
}

不能,n取64时,计算结果数据过大,超出无符号整形的范围

标签:main,task3,int,sum,a1,include
From: https://www.cnblogs.com/lht22MoonHalo/p/16801889.html

相关文章

  • task3.c
    #include<stdio.h>intmain(){intn;printf("n=");scanf_s("%lld",&n);intsum=0,i=0,t=1;while(i<=n){sum+=t;......