Jimmy小站
小明也有大梦想 — 蒋明/铭4.1.3 编程题《求一批整数的奇数和》
2015-08-30 / C语言基础题 / 6263 次围观 / 0 次吐槽4.1.3 编程题《求一批整数的奇数和》 24
【问题描述】
读入一批正整数(以零或负数为结束标志),求其中的奇数和。请使用while 语句实现循环。
【输入形式】
从键盘输入一批正整数(以0或负数为结束标志)。
【输入输出样例1】(下划线部分表示输入)
Input integers: 1 3 90 7 0
The sum of the odd numbers is 11
【输入输出样例2】(下划线部分表示输入)
Input integers: 2 7 88 37 90 9 -1
The sum of the odd numbers is 53
【样例说明】
输入提示符后要加一个空格。例如“Input integers: ”,其中“:”后要加一个且只能一个空格。
输入的数据之间以一个空格相隔。
输出语句的“is”后面加一个且只能加一个空格。
英文字母区分大小写。必须严格按样例输入输出。
#include<stdio.h> int main(void) { int n,sum; sum=0; printf("Input integers: "); scanf("%d",&n); while(n>0){ if(n%2!=0){ sum=sum+n; } scanf("%d",&n); } printf("The sum of the odd numbers is %d",sum); return 0; }
推荐您阅读更多有关于“”的文章
- OTS 向量检索
本月热文
Copyright © Jimmy小站 Allrights Reserved.备案号:桂ICP备 15005996
额 本文暂时没人评论 来添加一个吧
发表评论