C Primer Plus5-6

来源:互联网 发布:openwrt nginx https 编辑:程序博客网 时间:2024/06/05 06:55
/*6.现在修改编程练习 5 中的程序,使它能够计算整数平方的和(如果您喜欢,可以这样认为:如果您第一天得到$l,第二天得到$4,第三天得到$9,以此类推您将得到多少钱。这看起来像一个很好的买卖)。C 没有平方函数,但是您可以利用 n 的平方是 n*n 的事实。*/#include<stdio.h>#include<stdlib.h>int main() {     int day, money;     printf("Please input the days:");     scanf("%d", &day);     printf("Total money is:%d\n",  day * (2 * day + 1) * (day + 1) / 6);     system("pause");     return 0; }

这里写图片描述

0 0