计算概论(A)/基础编程练习1(8题)/7:奇数求和
#include<stdio.h>
int main() {
// 输入非负整数
int m, n;
scanf("%d %d", &m, &n); // 声明和
int s=; // 求m到n(包括m和n)之间的所有奇数的和
// 遍历判断奇偶性 再加和
for(int i=m; i<=n; i++) {
if(i%!=) {
s+=i;
}
}
printf("%d\n", s);
return ;
}
/*
pkuic_6171.c
计算概论(A)/基础编程练习1(8题)/7:奇数求和
http://pkuic.openjudge.cn/base1/7/
7:奇数求和
查看 提交 统计 提问
总时间限制: 1000ms 内存限制: 65536kB
描述
计算非负整数 m 到 n(包括m 和 n )之间的所有奇数的和,其中,m 不大于 n,且n 不大于300。例如 m=3, n=12, 其和则为:3+5+7+9+11=35。
输入
两个数 m 和 n,两个数以一个空格分开,其中 0 <= m <= n <= 300 。
输出
输出一行,包含一个整数,表示m 到 n(包括m 和 n )之间的所有奇数的和
样例输入
7 15
样例输出
55
*/
计算概论(A)/基础编程练习1(8题)/7:奇数求和的更多相关文章
- 计算概论(A)/基础编程练习2(8题)/8:1的个数
#include<stdio.h> int main() { ; // 存储测试数据的二进制形式中1的个数 int bian[N]; // 输入十进制整数N 表示N行测试数据 scanf( ...
- 计算概论(A)/基础编程练习2(8题)/7:整数的个数
#include<stdio.h> int main() { ] = {}; // 输入k个正整数 scanf("%d",&k); // 循环读入和进行算术 w ...
- 计算概论(A)/基础编程练习2(8题)/6:数组逆序重放
#include<stdio.h> int main() { // 输入n个整数 ; scanf("%d", &n); // 循环读入元素 while(scan ...
- 计算概论(A)/基础编程练习2(8题)/5:点和正方形的关系
#include<stdio.h> #include<math.h> int main() { // 输入坐标 float x, y; while(scanf("%f ...
- 计算概论(A)/基础编程练习1(8题)/2:苹果和虫子
#include<stdio.h> #include<math.h> int main() { /* n个苹果 每x小时能吃掉一个苹果 经过y小时 */ float n, x, ...
- 计算概论(A)/基础编程练习1(8题)/1:大象喝水
#include<stdio.h> int main() { ; // n < 100 scanf("%d", &n); // 循环遍历判断 再进行平方和 ...
- 计算概论(A)/基础编程练习2(8题)/4:骑车与走路
#include<stdio.h> int main() { // 待处理的数据数量n ; scanf("%d", &n); float meters[n]; ...
- 计算概论(A)/基础编程练习2(8题)/3:计算三角形面积
#include<stdio.h> #include<math.h> int main() { // 声明三角形的三个顶点坐标和面积 float x1, y1, x2, y2, ...
- 计算概论(A)/基础编程练习2(8题)/2:计算书费
#include<stdio.h> int main() { // 声明与初始化 ; // k组测试数据的总费用 double s[k]; // 单价表 double price[]= { ...
随机推荐
- 代码使用了php的包管理器composer,include到你的php脚本
使用数据库进行crontab配置管理,除非你能够保证数据库的请求能够在长时间内保持稳定响应的话.推荐使用nosql类型的cache存储,同时做好持久化备份. 测试代码: define('DS', DI ...
- Ucloud云主机无法yum安装处理办法
Ucloud云主机在yum安装的时候出现这个提示 执行一下命令 yum --disablerepo=salttestyum-config-manager --disable salttestyum-c ...
- MapReduce计算之——hadoop中的Hello World
1. 启动集群 2. 创建input路径(有关hadoop 的命令用 "hadoop fs"),input路径并不能在系统中查找到,可以使用 “hadoop fs -ls /” ...
- 多态设计 zen of python poem 显式而非隐式 延迟赋值
总结 1.python支持延迟赋值,但是给调用者带来了困惑: 2.显式而非隐式,应当显式地指定要初始化的变量 class Card: def __init__(self, rank, suit): s ...
- Docker Hub Mirror
什么是Docker Hub Mirror? 根据Docker的官方文档,Mirror的定义是: Such a registry is provided by a third-party hosting ...
- sql中varchar(max),取代text类型
SQL Server 2005之后版本:请使用 varchar(max).nvarchar(max) 和 varbinary(max) 数据类型,而不要使用 text.ntext 和 image 数据 ...
- 让WIN7桌面显示IE图标
首先新一个文本文件,将以下代码复制到新建文档中.然后保存为IE.reg,右键以管理员权限运行.此时,注册表注册成功.LOOK,IE图标出来了 Windows Registry Editor Versi ...
- 洛谷P2679 子串 [noip2015] dp
正解:dp 解题报告: 感觉是道dp好题啊,所以就写了个题解 代码实现难度低,思维难度大,像我这种思维僵化傻逼选手只想到了爆搜+组合数学... 其实是道很妙的dp题!好趴也没有多妙主要大概是妙在想到了 ...
- 请用漂亮欢呼-------Day38
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/marSmile_tbo/article/details/31108557 周末,双休,疯了两天.敲了 ...
- 如何在 vue 项目里正确地引用 jquery 和 jquery-ui的插件
copy内容的网址: https://segmentfault.com/a/1190000007020623 使用vue-cli构建的vue项目,webpack的配置文件是分散在很多地方的,而我们需要 ...