宇宙只有一个地球,人类共有一个家园。地球是人类唯一赖以生存的家园,珍爱和呵护地球是人类的唯一选择。习总书记提出”绿水青山就是金山银山,良好生态环境既是自然财富“。小明坚决拥护习总书记的科学论断,并在植树节种了一棵小树。小明每天都给小树浇水,盼望着小树快快长高。他知道小树现在有 n cm,每天长高k cm,他想知道多少天小树可以长到m cm。
输入格式:输入三个整数 n, m, k。 ( 0 <= n<= 10000, 0 <= m <= 10000,0 <= k <= 10000)
输出格式:输出一个整数,即需要的天数。
输入示例:
1
100 200 5
输出示例:
1
20
7-3 解答:
1
#include<stdio.h>
2
3
intmain(){
4
int n,m,k,d;
5
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
6
if (k ==0) {
7
printf("0\n");
8
}
9
if(m>=n){
10
if(k!=0){
11
d=(m-n)/k;
12
if ((m-n) % k !=0) {
13
d++;
14
}
15
printf("%d\n",d);
16
}
17
}
18
if(m<n){
19
printf("0");
20
}
21
}
22
return0;
23
}
7-4 sdut-C语言实验-数位数
给定一个正整数 n ,请你求出它的位数。
输入格式:单组输入,输入一个整数 n 。(1<= n <= 2147483647)
输出格式:输出一行,包含一个整数,即为 n 的位数。
输入示例:
1
1234567
输出示例:
1
7
7-4 解答:
1
#include<stdio.h>
2
3
intmain(){
4
int a,b=0;
5
scanf("%d",&a);
6
while(a>0){
7
a = a /10;
8
b++;
9
}
10
printf("%d",b);
11
return0;
12
}
7-5 sdut-C语言实验- 数列求和2
正整数序列是指从1开始的序列,例如{1,2,3,4,…}
给定一个整数 n,现在请你求出正整数序列 1 - n 的和。
输入格式:输入一个整数 n 。(1 <= n <= 1000)
输出格式:输出一个整数,即为正确答案。
输入示例:
1
2
输出示例:
1
3
7-5 解答:
1
#include<stdio.h>
2
3
intmain(){
4
int a,b=1,sum=0;
5
scanf("%d",&a);
6
while(a>=b){
7
sum += b;
8
b++;
9
}
10
printf("%d",sum);
11
return0;
12
}
7-6 sdut-C语言实验-N^3问题
输入一个正整数N,求出N^3的各位数字的立方和。
输入格式:输入N的值。N<=1024
输出格式:问题描述中所要求的数值。
输入示例:
1
3
输出示例:
1
351
7-6 解答:
1
#include<stdio.h>
2
#include<math.h>
3
4
intmain(){
5
int N,a,b,sum=0;
6
scanf("%d",&N);
7
a = N*N*N;
8
while(a!=0){
9
b=a%10;
10
a=a/10;
11
sum += b*b*b;
12
}
13
printf("%d",sum);
14
return0;
15
}
7-7 sdut-C语言实验-虎子的难题
虎子是个爱学习的孩子,暑假也在家有规律的学习,但是他最近碰到了一道难题,题目是这样的:
给出一个正整数 n 和数字 m ( m 取值范围[0,9]中的一个数字),求 m 在 n 中出现的次数。
比如 n = 2122345 , m = 2,答案就是 3 ,因为 2 在 2122345 中出现了三次。
你能帮帮他吗?
输入格式:输入只有一行,包含两个空格分开的整数 n 和 m 。(0 <= m <= 9,1 <= n <= 2147483647)
输出格式:输出一个数字,表示 m 在 n 中 出现的次数。
输入示例:
1
2122345 2
输出示例:
1
3
7-7 解答:
1
#include<stdio.h>
2
3
intmain(){
4
int n,m,a,counts=0;
5
scanf("%d%d",&n,&m);
6
while(n!=0){
7
a = n%10;
8
if(a==m){
9
counts++;
10
}
11
n=n/10;
12
}
13
printf("%d",counts);
14
return0;
15
}
7-8 sdut-C语言实验- A+B for Input-Output Practice (I)
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim
输入格式:The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
输出格式:For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
输入示例:
1
1 5
2
10 20
输出示例:
1
6
2
30
7-8 解答:
1
#include<stdio.h>
2
3
intmain(){
4
int a,b,sum;
5
while(scanf("%d%d",&a,&b)!= EOF){
6
sum = a + b;
7
printf("%d\n",sum);
8
}
9
return0;
10
}
7-9 sdut-C语言实验- A+B for Input-Output Practice (II)
Your task is to Calculate a + b.
输入格式:Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.
输出格式:For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
输入示例:
1
1 5
2
10 20
3
0 0
输出示例:
1
6
2
30
7-9 解答:
1
#include<stdio.h>
2
3
intmain(){
4
int a,b,sum;
5
while(scanf("%d%d",&a,&b)!= EOF){
6
if(a==0&&b==0){
7
break;
8
}
9
sum = a + b;
10
printf("%d\n",sum);
11
}
12
return0;
13
}
7-10 sdut-C语言实验-A+B for Input-Output Practice (III)
Your task is to Calculate a + b.
输入格式:The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
输出格式:For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.