C++程序设计 Output Positive Numbers

徐福建2022-10-04 11:39:541条回答

C++程序设计 Output Positive Numbers
Description
Please wirte a program to read integers from the keyboard and print all the positive numbers out.Each number is in the scope of the int type.
Input
The input contains two lines.The first line is a number that indicates how much numbers to be read.Then the numbers are listed in the second line separated by white spaces.There are no more than 1000 numbers to be read.
Output
Print out all the positive numbers in one line and there should be one white space between two numbers.
Note:there should be no white space in the end of the output.
Sample Input
3
12 13 -1
Sample Output
12 13

已提交,审核后显示!提交回复

共1条回复
florashaw11 共回答了23个问题 | 采纳率95.7%
#includeusing namespace std;int main(){bool isFirst = true;int totalNum, item;&nbs...
1年前

相关推荐

程序设计 call by value ,call by address ,call by name
程序设计 call by value ,call by address ,call by name
假设有一段code内容大致如下:
----------------------------------
MAIN()
BEGIN
A[1:4]={1,2,3,4};
X = 1;
Y = 2;
CALL SUB(X,Y,A[X]);
END
SUB(A,B,C)
BEGIN
A = B;
C = 12;
END
----------------------------------
在下列三种呼叫方式下
程式执行的结果各为何?
希望能附上说明给我,这样我比较能理解
call by value
call by address (reference)
call by name
zuixinren1年前1
winwinhua 共回答了15个问题 | 采纳率80%
call by value 方式:
调用时子程序得到的是参数值的副本,子程序中对形参的改变其实只是影响了该副本的值,但在返回主程序后该副本会被丢弃,因此在主程序中按值调用的参数仍保持原来的值.
例如SUB(A,B,C)中,若形参A是by value的,则在MAIN中CALL SUB(X,Y,A[X])后,X仍为1.
call by address/reference 方式:
调用时子程序得到的是实际参数的内存地址,因此在子程序中改变形参的值时,实际会导致对该形参所对应的地址处的内存数据的变化,即直接修改的是主程序中的变量的值,返回主程序后该参数所对应的变量值会产生变化.
例如SUB(A,B,C)中,若形参A是by reference的,则在MAIN中CALL SUB(X,Y,A[X])后,X会变为2.
call by name 方式:
有点类似于宏扩展的方式,调用的参数并非是在调用前计算出来,而是在子程序中每个引用所对应的形参的地方都重新进行计算,因此有延迟计算的作用.例如你例子中,若主程序调用SUB时是by name的,则实际执行的情况是:
A=B --> X=Y --> X=2
C=12 --> A[X]=12 --> A[2]=12
这里就看到,因为X的值先变化过,所以在对C赋值的时候,实际影响的是A[2],而不是A[1].
VF循环程序设计 DO WHILE
VF循环程序设计 DO WHILE
求 e=1+1/1!+ 1/2!+ ...+ 1/n!(要求1/n!
alexandergu1年前1
哈哈吆 共回答了14个问题 | 采纳率92.9%
clear
set talk off
e=1
n=1
p=1
do while 1/p>=10^(-6)
e=e+1/p
n=n+1
p=p*n
enddo
?"e=",e
set talk on
return