输入A和B,计算并输出A+B

EOF是一个预定义的常量,等于-1。

 

 

输入A和B,计算并输出A+B

 

Sample input: 1    5

                      10  20

Sample output: 6

                      30

 

 

#include <iostream>
using namespace std;
int main()
{     int a, b;
      while(cin >> a >> b)


            cout << a + b << endl;
      return 0;
}

 

 

 

 

*********************************************************************************************************

 

Sample input:   2

                        1  5

                        10  20

Sample output:    6

                         30

 

 

 

// 使用C++语言提交的代码

#include <iostream>
using namespace std;
int main()
{   

int n,i,a,b;
     cin>>n;
     for(i=0;i<n;i++)
     {  

               cin>>a>>b;
        cout<<a+b<<endl; 
     }
    return 0;
}

 

 

 

/ 使用C语言提交的代码


#include <stdio.h>
int main()
{  

  int n,i,a,b;
     scanf("%d",&n);
for(i=0;i<n;i++)
{  

scanf("%d %d",&a, &b);
     printf("%d\n",a+b);
}
}

 

 

 

*********************************************************************************************************************
以某个特殊输入  为结束标志

 

 

Sample input:
1     5

10  20
0   0

 

 

Sample output:    6

                         30

 

 

 

// C语言AC代码1


#include <stdio.h>
int a,b;
int main()
{    

while(  scanf("%d%d",&a,&b)!=EOF    &&   (a || b)   )    

              
             printf("%d\n",a+b);
       return 0;
}

 

 

 

/ C语言AC代码2


#include <stdio.h>
int main()
{    int a,b;
     scanf("%d %d",&a, &b);
     while(   a!=0   ||   b!=0)
     {    

 

            scanf("%d %d",&a, &b);

                printf("%d\n",a+b); 
            
     }
}

 

 

 

/ C++语言AC代码


#include <iostream>
using namespace std;
int main()
{   

int a,b;
     cin>>a>>b;
     while( a!=0 || b!=0)
     {    

               cin>>a>>b;

    cout<<a+b<<endl; 
            
     }
     return 0;
}

 

 

 

 

***********************************************************************************************************************************

Sample input:
2
4 1 2 3 4
5 1 2 3 4 5

 

Sample output:    10

                         15

 

 

 

 

 

 

 

// C语言AC代码


#include <stdio.h>
int n,c,t,sum;
int main() {   

  while( scanf("%d",&c)!=EOF )
       {   

while(c--)   
            {   scanf("%d",&n); sum=0;       
                 while(n--)  

         
                  {    scanf("%d",&t);   
                        sum+=t;   }


            printf("%d\n",sum); }
       }
       return 0;
}

 

 

 

 

 

// C++语言AC代码


#include <iostream>
using namespace std;
int n,c,t,sum;
int main()
{     while( cin>>c)
          {    while(c--)   
                 {   cin>>n;     sum=0;       
                 while(n--)           
                    {    cin>>t;  sum+=t;   }
            cout<<sum<<endl; }
       }
       return 0;
}

 

 

 

 

 

********************************************************************************************************************************************

 

 

 

 

Sample input:
4    1 2 3 4
5     1 2 3 4 5
0

 

 

Sample output:    10

                         15

 

 

// C语言AC代码

#include<stdio.h>  
int main()
{   

int i,n,a[100],m=0;         
     while( scanf("%d",&n)!=EOF  &&  (n!=0) )   
     {   

           for(i=0;i<n;i++)                      {   scanf("%d",&a[i]);       m+=a[i];  

      
             printf("%d\n",m);         m=0;
     }
     return 1;
}

 

 

 

 

/ C++语言AC代码


#include <iostream>
using namespace std;
int n,sum,t;
int main()
{   while( cin>>n && n)
     { 

  sum=0;
         while(n--)             {       cin>>t;       sum+=t;   }
         cout<<sum<<endl;
     }
     return 0;
}

 

 

 

 

 

 

 

***************************************************************************************************

Sample input:
4 1 2 3 4
5 1 2 3 4 5

 

Sample output:
10
15

 

 

 

/ C++语言AC代码
#include <iostream>
using namespace std;
int n,sum,t;
int main()
{   while( cin>>n && n )       
     {     sum=0;
           while(n--)
            {     cin>>t;   sum+=t;  }  
            cout<<sum<<endl;
     }
     return 0;
}

 

转载于:https://www.cnblogs.com/wc1903036673/p/3870591.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值