1 solutions

  • 0
    @ 2025-11-5 15:51:36

    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 求正数的和

    Information

    ID
    17260
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By