东方博宜OJ 1026:求商数和余数 ← cin/cout + scanf/printf

【题目来源】
https://oj.czos.cn/p/1026

【题目描述】
输入 a,b 两个整数,编程求出 a 除以 b 得到的商和余数。

【输入格式】
输入一行,只有两个整数(中间有空格)。

【输出格式】
输出只有一行,两个整数(中间有空格)。

【输入样例】
7 3

【输出样例】
2 1

【数据范围】
两个整数数据范围(1~1000)内。

【算法分析】
考查输入输出(cin/cout、scanf/printf)的语法,以及整除(/)、求余(%)的语法。

【算法代码一:cin、cout

#include <bits/stdc++.h>
using namespace std;

int main() {
    int a,b;
    cin>>a>>b;
    cout<<a/b<<" "<<a%b;

    return 0;
}

/*
in:7 3
out:2 1
*/


【算法代码二:scanf、printf

#include <bits/stdc++.h>
using namespace std;

int main() {
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d %d",a/b,a%b);

    return 0;
}

/*
in:7 3
out:2 1
*/




【参考文献】
/



 

posted @ 2026-02-07 07:48  Triwa  阅读(0)  评论(0)    收藏  举报