目录
7-219 sdut-C语言实验-A+B for Input-Output Practice (不确定次数循环)
7-217 在数组中查找1
分数 5
全屏浏览题目
切换布局
作者 庄波
单位 滨州学院
编写程序在 n 个元素的数组中查找指定的元素 x。
输入格式:
第一行包含两个整数 n 和 x,分别表示数组元素的个数(不超过 20)和待查找的数。
第二行包含 n 个整数,要求依次存入数组。
输出格式:
若在数组中找到 x 提示找到,并给出在数组中第一出现的时下标。
若找不到,则提示未找到。
输入样例 1:
在这里给出一组输入。例如:
5 3
1 2 3 4 5
输出样例 1:
在这里给出相应的输出。例如:
Found 3 at 2
输入样例 2:
在这里给出一组输入。例如:
5 6
1 2 3 4 5
输出样例 2:
在这里给出相应的输出。例如:
Not found 6
#include "stdio.h"
int main(){
int n,m;
int i,j;
scanf("%d%d",&n,&m);
int arr[20]={0};
for (i = 0; i < n; ++i) {
scanf("%d",&arr[i]);
}
int flag = 0;
for (j = 0; j < n; ++j) {
if(m == arr[j]){
printf("Found %d at %d\n",m,j);
flag = 1;
}
}
if(flag == 0){
printf("Not found %d",m);
}
return 0;
}
7-218 数完数个数
分数 10
全屏浏览题目
切换布局
作者 C课程组-ty
单位 湖南工程学院
一个正整数的真因子是指所有能整除它的正整数(不包括自身)。
一个正整数的所有真因子之和等于其本身则被称为完数。
例如:6=1+2+3,6是完数;
而9不是,1也不是。
求在[m,n]之间的完数的个数。
输入格式:
在一行中输入m和n的值,保证m<=n,并且都是正整数(读者无需考虑)。
输出格式:
在一行中输出个数。
输入样例1:
5 30
输出样例1:
2
输入样例2:
2 5
输出样例2:
0
#include <stdio.h>
int main(){
int num=0;
int f[999];
int n;
int m;
int c=0;
scanf("%d",&m);
scanf("%d",&n);
for (int i = m; i <= n; ++i) {
int index = 0;
int temp = 0;
for (int j = 1; j <= i/2; ++j) {
if(i%j==0){
f[index] = j;
temp += j;
num++;
index++;
}
}
if(temp == i){
// printf("%d\n",i);
c++;
}
num = 0;
}
printf("%d",c);
return 0;
}
7-219 sdut-C语言实验-A+B for Input-Output Practice (不确定次数循环)
分数 10
全屏浏览题目
切换布局
作者 马新娟
单位 山东理工大学
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 5
10 20
输出样例:
在这里给出相应的输出。例如:
6
30
#include "stdio.h"
int a,b;
int main()
{
while(scanf("%d%d",&a,&b)!= EOF)
{
printf("%d\n",a+b);
}
}