100到200以内7的倍数之和

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sk_U238/article/details/53501842

思路是找到200以内有多少个7的倍数,并累计下来有多少个7并乘以7。

并找到100以内的7的倍数之和。两个相减就是了。

#include <stdio.h>
#include <stdlib.h>


int sum(int base, int n)
{
return base*(n/base)*(n/base+1)/2;
}


int main()
{
    printf("%d\n",sum(7,200)-sum(7,100));
system("pause");
return 0;
}

猜你喜欢

转载自blog.csdn.net/sk_U238/article/details/53501842