首页 > 试题广场 >

牛牛学加法

[编程题]牛牛学加法
  • 热度指数:42072 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}给定两个整数 ab,其中 0 \leqq a, b \leqq 1000,请计算它们的和并输出结果。

输入描述:
\hspace{15pt}在一行中输入两个整数 a, b0 \leqq a, b \leqq 1000)。


输出描述:
\hspace{15pt}输出一个整数,表示 a+b 的值。
示例1

输入

1 2

输出

3

说明

1+2=3,输出结果为 3
示例2

输入

1000 0

输出

1000

说明

1000+0=1000,输出结果为 1000
#include <stdio.h>

int main() {
    int a,b=0;
    scanf("%d %d",&a,&b);
    printf("%d",a+b);
    return 0;
}


发表于 2024-01-06 18:14:10 回复(0)
x = input()
a,b = x.split()
print(int(a)+int(b))

发表于 2022-07-17 15:43:15 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(a + b);
        }
    }
}
发表于 2025-08-02 02:06:27 回复(0)
# a,b = map(int,input().split())
# sums = a+b
# print(sums)

print(sum(map(int,input().split())))

发表于 2024-09-27 01:19:31 回复(0)
C
箍头像
#include <stdio.h>
int add(int a, int b){ return a + b; }
int(*func)(int ,int)=add;
int main() {
   int a,b;
   scanf("%d %d",&a,&b);
   printf("%d",func(a,b));
   return 0;
}
发表于 2025-08-15 13:12:01 回复(0)
x=input()
a,b=x.split()
s=int(a)+int(b)
print(s)

发表于 2025-07-19 15:43:33 回复(0)
发表于 2025-07-13 15:22:35 回复(0)
#include <stdio.h>
int main() {
    int a=0, b=0;
scanf("%d %d",&a,&b);
if(0<=a&&b<=1000)
printf("%d",a+b);
else
printf("超出输入范围");
    return 0;
}


发表于 2024-04-23 12:35:14 回复(0)
简单理解,看都看,给点个赞呗
#include<iostream>

using namespace std;

int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        cout<<a+b<<endl;
    }
}
发表于 2022-08-12 23:18:28 回复(0)
a, b = map(int, input().split())
print(a + b)

发表于 2022-08-11 10:43:02 回复(1)
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d",&a,&b);
    if (a>=0 && b<= 1000)
    {
        c=a+b;
        printf("%d",c);
    }
    else
    {
        printf("sorry, worry,check please!");
    }
    return 0;
}
发表于 2022-08-01 19:03:22 回复(0)
a,b=map(int,input().split(' '))
z=a+b
print(z)
发表于 2022-06-13 22:09:05 回复(0)
#include <stdio.h>
int main() {
    int a, b;

    scanf("%d%d", &a, &b);
    if (a >= 0 && b <= 1000)
        printf("%d", a + b);

    return 0;


}
发表于 2022-04-07 21:09:13 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        System.out.println(a+b);
    }
}
发表于 2025-10-30 11:00:19 回复(0)
#include <stdio.h>

int main() {
    int a, b, i;
    int sum = 0;
    scanf ("%d",&a);
    for (i=0;i<5;i++)
    {
        if (a>=0)
        break;
        else if (i=5)
        return 0;
        else
        {
            printf("请重新输入");
            scanf ("%d",&a);
        }
       
    }
    scanf ("%d",&b);
    for (i=0;i<5;i++)
    {
        if (b<=1000)
        break;
        else if (i=5)
        return 0;
        else
        {
            printf("请重新输入");
            scanf ("%d",&b);
        }
       
    }
    sum=a+b;
    printf ("%d",sum);
    //printf ("%d+%d=%d,输出结果为%d。",a,b,sum,sum);

   

    return 0;
}
发表于 2025-10-26 22:28:59 回复(0)
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d",&a,&b);
    printf("%d",a+b);
    return 0;
}
发表于 2025-10-23 15:57:01 回复(0)
using System;

public class Program {
    public static void Main() {
        // 读取一行输入并按空格分割成两个字符串
        string[] input = Console.ReadLine().Split(' ');
       
        // 将分割后的字符串转换为整数
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
       
        // 计算和并输出
        Console.WriteLine(a + b);
    }
}
发表于 2025-10-19 16:49:22 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(a + b);
        }
    }
}

发表于 2025-09-30 16:31:33 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        System.out.println(a + b);
        in.close();
    }
}
  1. 输入处理
    • 使用Scanner类的nextInt()方法连续读取两个整数
    • 由于两个整数在同一行且用空格分隔,nextInt()会自动跳过空格,无需额外处理
发表于 2025-09-20 00:18:41 回复(0)
#include<iostream>
using namespace std;
int jia(int a,int b){
    return a+b;
}
int main(){
    int a,b;
    cin>>a>>b;
    cout<<jia(a,b)<<endl;
    return 0;
}
发表于 2025-09-08 16:22:32 回复(0)

问题信息

上传者:牛客301599号
难度:
77条回答 4012浏览

热门推荐

通过挑战的用户

查看代码
牛牛学加法