3、编写程序,读入一批正整数(以零或负数为结束标志),求其中的奇数和。 输入输出示例 input integers:1 3 90 7 0 the sum of odd numbers is 11

3、编写程序,读入一批正整数(以零或负数为结束标志),求其中的奇数和。 输入输出示例 input integers:1 3 90 7 0 the sum of odd numbers is 11


参考答案和解析
ex2-8.cpp

相关考题:

以下程序是从终端读入数据到数组中,统计其中正数的个数,并计算它们的和。请填空。main(){int i,a[20],sum,count;sum=count=【】;for(i=0; i20;i++)scanf("%d",【】);for(i=0; i20;i++) { if(a[i]0) { count++; sum+=【】; } }printf("sum=%d.count=%d\n",sum,count);}

( 9 )下面的函数利用递归实现了求 1+2+3+ …… +n 的功能:int sum ( int n ) {if ( n==0 )return 0;elsereturn n+sum ( n-1 ) ;}在执行 sum ( 10 )的过程中,递归调用 sum 函数的次数是【 9 】 。

【程序说明】 计算1~30之间能够被3整除的奇数的阶乘和。【程序】** 主程序SET TALK OFFS=0FOR I=1 TO 30 STEP 2IF (4)(5)S=S+NENDIFENDFOR?“1到30之间能被3整除的奇数阶乘和为:”+ (6)SET TALK ONRETURN** 过程 P1.PRGPARAMETERS M(7)N=1FOR J=1 TO MN=N*JENDFOR(8)(4)A.MOD(I,3)=0B.MOD(I,3)>0C.MOD(I,3)<>0D.MOD(I,3)=0

LOOPNZ意味着:() A、CX=0并且标志为1时转移结束循环B、CX=0或ZF标志为0时结束循环C、CX=0或ZF标志为1时结束循环

如程序示例FORR[1]=0TO3BY1,步进值为( )。 A.0B.1C.2D.3

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]编写一个函数,输入为偶数时,调用函数求1/2+?/+…+1/n,当输入n为奇数时,调用函数1/1+1/3+…+1/n (利用指针函数)。[函数]include "stdio. h",main(){float peven (),podd (),dcall ();float sum;int n;while (1){scanf("%d",n);if (n>1)break;}if(n%2==0){printf("Even="):(1);}else{pfinff("Odd=");(2);}printf("%f",sum);}float peven (int n){float s;int is=1;for(i=2;i<=n;i+=2)(3);return (s);}float podd (n)int n;{float s;int i;s=0;for(i=1 i<=n;i+=2)(4);return (s);}float dcall(fp,n)float (*fp) ();int n;{float s;(5);returu (s);}

已知在4行3列的全局数组score(4,3)中存放了4个学生3门课程的考试成绩(均为整数),现需要计算每个学生的总分,某人编写程序如下: Option Base 1 Private Sub Command1_Click() Dim sum As Integer sum=0 For i=1 To 4 For j=1 To 3 sum=sum+score(i,j) Next j Print "第" i "个学生的总分是:";sum Next i End Sub 运行此程序时发现,除第1个人的总分计算正确外,其他人的总分都是错误的,程序需要修改。下列修改方案中正确的是( )。A.把外层循环语句For i=1 To 4 改为 For i=1 To 3 内层循环语句For j=1 To 3改为For j=1 To 4B.把sum=0移到For i=1 To 4和For j=1 To 3之间C.把sum=sam+score(i,j)改为sum=sum+score(j,i)D.把sum=sum+score(i,j)改为sam=score(i,j)

【程序说明】 计算下列算式的值。a,Ai为正整数,从键盘输入。其小∑Ai=1+2…+ Ai,Ai!=1 *2*3*Ai(i=1,2… a)。【程序】SET TAIK OFFCLEARINPUT“M=”TO MSTORE 0 TO S1,S2FOR I=1 TO M(8)DO SUB1DO SUB2ENDFOR? ” 所求算式的值为:“+ALLTRIM(STR(S1/S2,15,3))SET TALK ONPROCEDURE SUB1(9)FOR R=1 TO AK=K+RENDFOR(10)RETURNPROCEDURE SUB2(11)FOR P=1 TO AT=T*PENDFOR(12)RETURN(8)A.INPUT“A=”TO AB.INPUT“I=”TO IC.INPUT“R=”TO STR(R)D.INPUT“K=”TOK

有如下程序: Option Base 1 Private Sub Form. Click() Dim arr,Sum Sum=0 alt=Array(1,3,5,7,9,11,13,15,17,19) For i=1 To 10 If arr(i)/3=arr(i)\3 Then Sum=Sum+arr(i) End If Next i Print Sum End Sub 程序运行后,单击窗体,输出结果为______。A. 25B.26C.27D.28

有如下程序: Option Base 1 Private Sub Form_Click() Dim arr,Sum Sum=0 alt=Array(1,3,5,7,9,11,13,15,17,19) For i=1 To 10 If arr(i)/3=arr(i)13 Then Sum=Sum+alt(I) End If Next i Print Sum End Sub 程序运行后,单击窗体,输出结果为______。A.25B.26C.27D.28

下面程序的运行结果是()。include void main(){static int a[][4]={ 1,2,3,4,5,6,7, 下面程序的运行结果是( )。#include <iostream.h>void main(){static int a[][4]={ 1,2,3,4,5,6,7,8,9,10,11,12};int i, j, sum=0;for(i=0;i<3;i++)for(j=0;j<4;j++)if(j>i)sum+=a[i][j];cout<<sum<<end1;}A.24B.30C.36D.40

以下程序输出结果是 ______。includevoid main(){ int a[3][3]={1,3,5,7,9,10,13,1 以下程序输出结果是 ______。 #include<iostream.h> void main(){ int a[3][3]={1,3,5,7,9,10,13,15,17},sum=0,i,j; for(i=0;i<3:i++) for(j=0;j<3;j++){ a[i][j]=i+j; if(i= =j)sum=sum+a[i][j]; } cout<< "sue="<<sum; }A.15B.25C.6D.9

以下程序是一个函数,功能是求二阶矩阵(m行n列矩阵)的所有靠外侧的各元素值之和。(本程序中二阶矩阵用一维数组来表示。)例如,矩阵为:3 0 0 32 5 7 31 0 4 2则所有靠外侧的各元素值之和为3+0+0+3+2+3+1+0+4+2=18。add(int m,int n,int arr[]){ int i,j,sum=0;for(i=0;ifor(j=0;jN;J++)sum=sum+ (7) ;for(j=0;jfor(i=1; (8) ;i++)sum=sum+arr[i*n+j];return(sum);}

码垛层数设定()A、码垛方式选择只有“0”和“1”两种;B、当选择“0”时码垛为1/3/5/7/9/11---层为奇数层一种方式码垛;C、当选择“0”时码垛为2/4/6/8/11---层为偶数层一种方式码垛D、当选择“1”时码垛为1/3/5/7/9/11---层为偶数层一种方式码垛;E、当选择“1”时码垛为2/4/6/8/10---层为奇数层一种方式码垛

编写程序,求20元素无符号字数组ARRAY中最小的奇数,存入ODD单元,如果不存在奇数,将ODD单元清零。

相当于零序分量的高次谐拨是()谐波。A、3n次B、3n+1次C、3n—1次(其中n为正整数)

单选题If a and b are integers and the sum of ab and b is even, which of the following could be true?Ⅰ. a and b are both odd.Ⅱ. a is even and b is odd.Ⅲ. a is odd and b is even.AⅠ onlyBⅡonlyCⅢ onlyDⅠ and ⅡEⅠand Ⅲ

单选题x, y, and z are positive integers. Which of the following lists all the possible ways for x + y + z to be an odd number?I. One of the numbers is odd.II. Two of the numbers are odd.III. Three of the numbers are odd.AIBI and IICI and IIIDII and III

单选题1)#include 2)usingnamespacestd; 3)intmain() 4){ 5)inta,b,result; 6)coutab; 8)result=3*a-2*b+1; 9)cout"resultis"Aplease input two numbers:的前面Bplease input two numbers:的后面Cplease input two numbers:的下一行首列D不确定

单选题What is the average (arithmetic mean) of 8 consecutive odd integers if the smallest of those integers is n?An+5Bn+6Cn+7Dn+8En+9

单选题Set X = even integers and Set Y = odd integers. Therefore X ∩ Y = ______.Aprime numbersBintegersCempty setDcomposite numbersEwhole numbers

单选题1)#include 2)# include 3)using namespace std; 4)double max(double x,doubley); 5)void main() 6){ 7)double a,b,c; 8)cout ab; 10)c=max(a,b); 11)couty) 16)returnx; 17)else 18)returny; 19)}执行完第8行后,屏幕上输出:()Ainput two numbers:/nBinput two numbers:Ccout”input two numbers:/n”D”please input two numbers:/n”

单选题1)#include 2)usingnamespacestd; 3)intmain() 4){ 5)inta,b,result; 6)coutab; 8)result=3*a-2*b+1; 9)cout"resultis"Aplease input two numbers:/nBplease input two numbers:Ccout”please input two numbers:/n”D”please input two numbers:/n”

单选题If m and n are positive integers and 3m+n-1=2m+2n, which of the following must be true?I. m and n are consecutive integers.II. m is even.III. n is odd.ANoneBI onlyCII onlyDIII onlyEI, II, and III

问答题从键盘输入若干个数,当输入0时结束输入,求这些数的和以及平均值。 提示:设输入的数存放在x中,sum表示和,n表示读入数的个数,则求若干个数的和,就是对x进行累加,即sum=sum+x,其中sum的初值为0。如果读入个数n大于0,则输出sum、sum/n。 要求:采用while与if结构语句实现。

单选题The sum of two numbers is 7 and their difference is 4. Which of the following could be the difference of their squares?A-11B-3C3D28E3

问答题4 9 6 2 3 4 7 8 2 1 9 6 4 3 2  Multiply by 7 the number of odd numbers which are immediately followed by an even number in the list above. What is the answer?

问答题编写程序,求20元素无符号字数组ARRAY中最小的奇数,存入ODD单元,如果不存在奇数,将ODD单元清零。