C Primer Plus第六版 第六章编程练习10~18

10.编写一个程序,要求用户输入一个上限整数和一个下限整数,计算从上限到下限范围内所有 整数的平方和,并显示计算结果。然后程序继续提示用户输入上限和下限整数,并显示结果,直到 用户输入的上限整数等于或小于下限整数为止。程序的运行示例如下:

Enter lower and upper integer limits: 5 9

The sums of the squares from 25 to 81 is 255

Enter next set of limits: 3 25

The sums of the squares from 9 to 625 is 5520

Enter next set of limits: 5 5

Done

#include <stdio.h>
int main(void)
{
int lower,upper,i;
long sum=0;

printf("Enter lower and upper integer limits:");
while((scanf("%d %d",&lower,&upper)==2)&&lower<upper)
{
for(i=lower;i<=upper;i++)
sum+=i*i;
printf("The sum of squares from %d to %d is %ld\n",lower,upper,sum);
sum=0;
printf("Enter next set of limits:");
}
printf("Done\n");

return 0;
}

11.编写一个程序,在数组中读入8个整数,然后按倒序打印这8个整数。

#include <
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值