1 条题解

  • 0
    @ 2025-9-9 23:54:53

    C :

    #include<stdio.h>
    main()
    {
    	int n,sum = 0;
    	scanf("%d",&n);
    	while(n > 0)
    	{
    		sum = sum + n;
    		scanf("%d",&n);
    	}
    	printf("%d",sum);
    	return 0;
    }
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc=new Scanner(System.in);
    		int s=0,temp;
    		while(sc.hasNext()){
    			temp=sc.nextInt();
    			if(temp<0||temp==0){
    				break;
    			}
    			s+=temp;
    		}
    		System.out.println(s);
    		sc.close();
    	}
    }
    
    • 1

    【基础题】第6章:循环控制结构 6.12 求正数的和

    信息

    ID
    1985
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者