下列程序的功能是从输入的整数中,统计大于零的整数个数和小于零的整数个数。用输入0来结束输入,用i,j来放统计数,请填空完成程序。
void main()
{ n,i=0,j=0;
printf(“input a integer,0 for end\n”);
scanf(“%d”,&n);
while ( ) {
if(n>0) i= ;
else j=j+1;
}
printf(“i=%4d,j=%4d\n”,i,j);
int
n != 0
i + 1
int n i+1
n!=0
i+1
i != 0
i +1
1.int
2.n!=0
3.i=i+1
n或n != 0
1.int 2.n!=0 3.i+1
n
#include <stdio.h>
int main() {
int n, i = 0, j = 0; printf("input number,0 for end\n"); scanf("%d",&n); while(n != 0){ if(n > 0){ i = i+1; }else{ j = j+1; } scanf("%d",&n); } printf("i = %4d, j = %4d\n",i,j); }
int n!=0 i+1
int n!=0 i=i+1
{ int n,i=0,j=0;
while ( n ) {
if(n>0) i= i+1 ;
void main() { int n,i=0,j=0; printf(“input a integer,0 for end\n”); scanf(“%d”,&n); while ( n或n!=0 ) { if(n>0) i= i+1 ; else j=j+1; scanf(“%d”,&n); } printf(“i=%4d,j=%4d\n”,i,j); }
x!=0
n<0 || n>0
int n!0 i+1
int n=0 i+1
int n != 0 或n i+1
1
int i+1
int n != 0 i+
printf('input a integer,0 for end\n');
scanf('%d',&n);
while (n!=0) {
if(n>0) i=i+1;
printf('i=%4d,j=%4d\n',i,j);
n!=0
while ( n || n!=0 ) {
n !=0
n || n!= 0
#include <stdio.h> void main()
while ( n!=0 ) {
++
i!=0
int,n!=0,i+1
2.d
3.i+1
n==0
aa_ca 回复 WhiteWing: 经典0分 n==0进入循环么 哥们
WhiteWing 回复 aa_ca: 看错啦
1. int
2.n!=0
int,n,i+1
代码优化
#include <stdio.h> void main(){ int n, i=0, j=0; int status; printf("input a integer, 0 for end\n"); status = scanf("%d", &n); while(status == 1){ if(n > 0) i = i+1; else if(n < 0) j=j+1; else if(n == 0) break; status = scanf("%d", &n); } printf("i=%4d,j=%4d\n", i, j); }
!n
Dlweikin 回复 Dlweikin: !n表示把自己变成与之相反的数,0变为非零数 while的退出条件是0
&n...
用户登录可进行刷题及查看答案
while ( n或n!=0 ) {
登录后提交答案