A
Problem Description
Input
Output
#include <stdio.h>
int main()
{
int i, s, n, a, b;
scanf ("%d", &n);
for (i = 1; i <= n; i++)
{
scanf("%d %d", &a, &b);
s = a + b;
printf("%d\n", s);
}
return 0;
}
B
Problem Description
Input
Output
第二行输出最小公倍数。
#include <stdio.h>
int main()
{
int a, b, m, i, t;
scanf("%d %d", &a, &b);
if (a < b) {t = a; a = b; b = t;}
for (i = b; ; i--)
{
if (a % i == 0 && b % i == 0)
{
break;
}
}
m = a * b / i;
printf("%d\n", i);
printf("%d\n", m);
return 0;
}
C
Problem Description
如果是素数则输出"This is a prime."
否则输出“This is not a prime.”
Input
Output
如果n是素数则输出"This is a prime."
否则输出“This is not a prime.”
#include <stdio.h>
int main()
{
int a, i;
int flag;
flag = 1;
scanf("%d", &a);
for(i = 2; i <= a - 1 ; i++)
if ( a % i == 0)
flag = 0;
if(flag && a != 1)
printf("This is a prime.\n");
else
printf("This is not a prime.\n");
return 0;
}
D
Problem Description
Input
Output
#include <stdio.h>
int main()
{
int a, i, n, m, t, p;
scanf("%d", &a);
p = 0;
for( i = 1; i <= a ; i++)
{
scanf("%d", &n);
if (n < 0)
{
m = -n;
if (m > p)
p = m;
t = n;
}
else if (n > p)
t = n;
}
printf("%d\n", t);
return 0;
}
E
输入n值,并利用下列格里高里公式计算并输出圆周率:
Input
#include <stdio.h>
int main()
{
int n, i;
double a, pi, t;
scanf("%d", &n);
t = 0;
for (i = 1; i <= n ; i++)
{
a = (1.0 / (4 * i - 3)) - (1.0 / (4 * i - 1));
t = a + t;
}
pi = 4 * t;
printf("%.5lf\n", pi);
return 0;
}
F
Problem Description
求s=a+aa+aaa+aaaa+……+aa…aa(n位)
其中,a的值由键盘输入,位数n也由键盘输入。
Input
第二行输入位数n。
Output
比如a=3,n=6时,s=3+33+333+3333+33333+333333
#include <stdio.h>
int main()
{
int a, t, f, s, n, i;
int b = 10;
s = 0;
scanf("%d", &a);
t = a;
f = a;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
s = s + a;
t = f * b;
a = t + a;
b = b * 10;
}
printf("%d", s);
return 0;
}
G
Problem Description
Input
Output
#include <stdio.h>
int main()
{
int a, n, s, i;
a = 0;
s = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++ )
{
a = i;
s = s + a;
}
printf("%d\n", s);
return 0;
}
H
Problem Description
Input
Output
#include <stdio.h>
int main()
{
int a, n, s, i;
a = 0;
s = 1;
scanf("%d", &n);
for (i = 1; i <= n; i++ )
{
a = i;
s = s * a;
}
printf("%d\n", s);
return 0;
}
I
Problem Description
Input
Output
int main()
{
int a, b, n, i;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
scanf("%d %d", &a, &b);
if(b > a)
a = b;
printf("%d\n", a);
}
return 0;
}
J
Problem Description
请用C语言编写一个程序。此程序接收一个正整数N,然后打印输出“N次N*(1->N)格式”的数据。例如:此程序接收正整数5,那会输出以下格式的数据:
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25
Input
int main()
{
int n, i;
scanf("%d", &n);
if (n <= 100)
{
for (i = 1; i <= n; i++)
{
printf("%d*%d=%d\n", n, i, n * i);
}
}
return 0;
}
K
Problem Description
接受从键盘输入的N个整数,输出其中的最大值、最小值和平均值(平均值为整除的商)。
Input
第二行有N个用空格隔开的整数Ti (1<= i <=N, 0<= Ti <= 1000)
ouput
Output
#include <stdio.h>
int main()
{
int n, a, t, m, ave, s, i;
scanf("%d", &n);
if (n <= 100)
{
scanf("%d", &a);
m = a; t = a; s = a;
for (i = 1; i < n ;i++)
{
scanf("%d", &a);
if (a > m)
m = a;
if (a < t)
t = a;
s = s + a;
}
ave = s / n;
printf("%d %d %d", m, t, ave);
return 0;
}
}
L
Problem Description
既然小猫这么喜欢吃糖,小狗决定每天都给小猫几块糖,但是呢,不能每天都给相同块数的糖,那样就太单调了。于是,第一天小狗给小猫1*1=1块,第二天2*2=4块……第 n 天给的糖数为 n*n 。现在已知小狗家共有 N 块糖,你需要帮他计算下这些糖最多可以给小猫几天?
Input
输入只有一个整数 N (1 < N <=10000)。
#include <stdio.h>
int main()
{
int n, d, t;
scanf("%d", &n);
t = 0;
for (d = 1; ; d++)
{
t = t + d * d;
if (n - t < 0) break;
}
printf("%d", d-1);
return 0;
}
M
Problem Description
Input
Output
int main()
{ int a, b, t, i, n;
double s;
a = 2;
b = 1;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
s = s + (double)a /(double) b;
t = a;
a = a + b;
b = t;
}
printf("%.6lf", s);
return 0;
}
N
Problem Description
期末考试结束了,老师想要根据学生们的成绩划分出等级。共有5个等级A,B,C,D和E。
划分方法如下,90分(含90)以上的为A,80~90(含80)间的为B,70~80(含70)间的为C,
60~70(含60)的为D,不及格的为E。
根据输入的成绩,编程输出各个级别段人数。
Input
一个学生的成绩。
Output
A nA
B nB
C nC
D nD
E nE
其中A,B,C,D,E代表等级,nA,nB等代表个等级的人数,等级和人数之间有一个空格。
int main()
{
int n, f, i, na, nb, nc, nd, ne;
na = 0;
nb = 0;
nc = 0;
nd = 0;
nd = 0;
ne = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
scanf("%d", &f);
switch (f / 10)
{
case 5 : ne++; break;
case 6 : nd++; break;
case 7 : nc++; break;
case 8 : nb++; break;
case 9 : na++; break;
case 10 : na++; break;
default : ne++; break;
}
}
printf("A %d\nB %d\nC %d\nD %d\nE %d\n", na, nb, nc, nd, ne);
return 0;
}
O
Problem Description
飞飞特别喜欢平方数,可是他数学并不好,你能帮他计算从n到m之间所有平方数之和吗?
提示:若一个整数的开方还是整数,它就是平方数。例如:4、9、16、25是平方数。
Input
第一行 T 代表数据的组数。
接下来有 T 行,每行两个整数n,m
Output
输出一个整数,代表所求区间内平方数之和。
#include<stdio.h>
int main()
{
int a, b, c, t, n, m, i, y, s;
scanf("%d", &t);
s = 0;
for (i = 1; i <= t; i++)
{
scanf("%d %d", &n, &m);
if (n < m)
{
y = n;
n = m;
m = y;
}
for (b = m; b <= n ; b++)
{
for ( a = 1; a <= n; a++ )
{if ( a * a == b)
{
s = s + b;
c = s;
}
}
}
s = 0;
printf("%d\n", c);
}
return 0;
}
P
从键盘输入一个整数n(1≤n≤9),打印出指定的数字图形。
Input
Output
Example Input
5
Example Output
1 121 12321 1234321 123454321 1234321 12321 121 1
#include <stdio.h>
int main()
{
int i, n, k, h;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
for (k = n; k > i; k--)
{
printf(" ");
}
for (h = 1; h <= i; h++)
{
printf("%d", h);
}
for (h = i-1 ; h >= 1 ;h--)
{
printf("%d", h);
}
printf("\n");
}
for (i = n - 1; i > 0; i--)
{
for (k = 1; k <= n - i; k++)
{
printf(" ");
}
for (h = 1 ; h <= i ;h++)
{
printf("%d", h);
}
for (h = i - 1; h >= 1; h--)
{
printf("%d", h);
}
printf("\n");
}
return 0;
}
Q
Problem Description
Input
Output
第一行前面有n-1个空格,第二行有n-2个空格,依此类推。
Example Input
5
Example Output
* *** ***** ******* ********* ******* ***** *** *
#include <stdio.h>
int main()
{
int i, n, k, h;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
for (k = n; k > i; k--)
{
printf(" ");
}
for (h = 1; h <= i; h++)
{
printf("*");
}
for (h = i-1 ; h >= 1 ;h--)
{
printf("*");
}
printf("\n");
}
for (i = n - 1; i > 0; i--)
{
for (k = 1; k <= n - i; k++)
{
printf(" ");
}
for (h = 1 ; h <= i ;h++)
{
printf("*");
}
for (h = i - 1; h >= 1; h--)
{
printf("*");
}
printf("\n");
}
return 0;
}
I
Problem Description
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1 3+5 3+3 3。
现在要求输出所有在m和n范围内的水仙花数。
Input
Output
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
int main()
{
int a, b, c, n, m, i, flag, skip;
while (scanf("%d %d", &m, &n) != EOF)
{
flag = 0, skip = 1;
for (i = m; i <= n; i++)
{
a = i / 100;
b = (i / 10) % 10;
c = i % 10;
if (i == a * a * a + b * b * b + c * c * c)
{
if (skip)
{
skip = 0;
printf("%d", i);
flag = 1;
}
else
{
printf(" ");
printf("%d", i);
}
}
}
if (flag ==1)
printf("\n");
if (flag == 0)
printf("no\n");
}
return 0;
}
S
输入n的值,计算cos(x)。
Input
Output
Example Input
0.0 100
Example Output
1.0000
#include <stdio.h>
#include <math.h>
int main()
{
int n, i, j;
double s, k, a;
double x;
while(~ scanf("%lf %d", &x, &n)) {
s = 1;
for (i = 1; i <= n; i++)
{
a = 1;
for (j = 1; j <= 2 * i; j++)
{
a *= j;
}
s = s + pow(-1,i) * pow(x,2 * i) / a;
//printf("%d %.4f %.4f\n", i, a, s);
}
printf("%.4lf\n", s);
}
return 0;
}
T
Problem Description
Input
Output
#include<math.h>
int main()
{
int t, i, j;
double b, h, n, s, l;
scanf("%d", &t);
for (i = 1; i <= t; i++)
{
scanf("%lf %lf", &h, &n);
s = h;
b = h;
for (j = 1 ; j <= n; j++)
{
if (j == 1)
{s = h;}
else
{
h = h * 0.5;
s = s + 2 * h;
}
}
l = b * pow(0.5 , n);
printf("%.2f %.2f\n", s, l);
}
return 0;
}
U
Problem Description
素数又称质数。指一个大于1的自然数,除了1和此整数自身外,不能被其他自然数整除的数。我们定义:如果一个素数是完美的素数,当且仅当它的每一位数字之和也是一个素数。现在给你一个正整数,你需要写个程序判断一下这个数按照上面的定义是不是一个完美的素数。
Input
输入包含多组测试数据。
每组测试数据只包含一个正整数 n (1 < n < 10^6)。
Output
int main ()
{
int n, t, b, s, t1, t2;
while((scanf("%d",&n))!=EOF)
{
if(n < 2)
{
printf("NO\n");
continue;
}
b = 0;
for (t = 2; t * t <= n; t++)
{
if (n % t==0)
{
b++;
}
if(b == 0)
{
s = 0;
for(; n > 0; n /= 10)
{
t1 = n % 10;
s += t1;
}
for (t2 = 2; t2 * t2 <= s; t2++)
{
if (s % t2==0)
{
b++;
}
}
}
if (b)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
V
Problem Description
Input
Output
Example Input
4 1 2 3 4 5 1 2 3 4 5 0
Example Output
10 15
#include <stdio.h>
int main()
{
int i, n, s, a;
while ((scanf("%d", &a)) != EOF)
{s = 0;
if (a != 0)
{
for (i = 1; i <= a; i++)
{
scanf("%d", &n);
s = s + n;
}
printf("%d\n", s);
}
}
return 0;
}
W
Problem Description
众所周知,C语言的学习是我们程序设计基础的重点和主要内容。
有一天,小金(a1s4z5)觉得好饿、好饿,于是去地里找玉米吃。他拿了一个很大的背包,可以装下很多很多玉米。
他掰玉米有一个习惯,第1次的时候掰1个,第2次的时候掰2个,第3次的时候掰3个...第n次的时候掰n个,他打算掰完第n次的时候就回家吃玉米。
在苞米地里,他越掰越高兴越掰越高兴,终于当他摩擦到要停不下来的时候,发现自己根本背不动他的背包了。于是他要将前m次掰的玉米全都扔掉才能回家开饭。但是小金的数学很不(li)好(hai),请你帮他算一算袋子里还有多少玉米。
Input
多组输入。
第一行输入两个空格隔开的整数n和m,含义如题意描述。(0 < m < n < 10^4)
Output
输出小金的背包里最后剩下多少玉米。输入输出各占一行,保证数据合法。
#include <stdio.h>
int main()
{
int i, n, m, a, s, k;
while (scanf("%d %d", &n, &m) != EOF)
{
s = 0;
a = 0;
for (i = 1; i <= n; i++)
{
s = s + i;
}
for (k = 1; k <= m; k++)
{
a = a + k;
}
printf("%d\n", s - a);
}
return 0;
}
X
Problem Description
Input
Output
Example Input
100
Example Output
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
#include <stdio.h>
#include <math.h>
int main()
{
int a, m, k, i, count = 0;
scanf("%d", &m);
for (i = 2; i <= m; i++)
{
for (k = 2; k < i; k++)
if (i % k == 0) break;
if (k >= i)
{
printf("%d ", i);
count++;
if(count % 10 == 0)
printf("\n");
}
}
printf("\n");
return 0;
}
Y
Problem Description
Input
Output
#include <stdio.h>
#include <math.h>
int main()
{
int a, m, k, i;
a = 0;
for (i = 101; i <= 200; i++)
{
for (k = 2; k < i; k++)
if (i % k == 0) break;
if (k >= i)
a++;
}
printf("%d\n", a);
for (i = 101; i <= 200; i++)
{
for (k = 2; k < i; k++)
if (i % k == 0) break;
if (k >= i)
a++;
if (k >= i)
printf("%d ", i);
}
printf("\n");
return 0;
}
Z
Problem Description
#include <stdio.h>
int main()
{
int i, n, k, h;
n = 4;
for (i = 1; i <= n; i++)
{
for (k = n; k > i; k--)
{
printf(" ");
}
for (h = 1; h <= i; h++)
{
printf("*");
}
for (h = i-1 ; h >= 1 ;h--)
{
printf("*");
}
printf("\n");
}
for (i = n - 1; i > 0; i--)
{
for (k = 1; k <= n - i; k++)
{
printf(" ");
}
for (h = 1 ; h <= i ;h++)
{
printf("*");
}
for (h = i - 1; h >= 1; h--)
{
printf("*");
}
printf("\n");
}
return 0;
}
AA
Problem Description
Input
Output
int main()
{
int i, n, k, h;
scanf("%d", &n);
for (i = n; i >= 1; i--)
{
for (k =2 * (i - 1); k > 0; k--)
{
printf(" ");
}
for (h = 1 ; h <= n - i + 1; h++)
{
if (n - i + 1 == 1)
printf("%d", h);
else
printf("%d ", h);
}
for (h = n - i; h >= 1; h--)
{
if (h == 1)
printf("%d", h);
else
printf("%d ", h);
}
printf("\n");
}
return 0;
}
AB
Problem Description
九九乘法表是数学学习的基础,今天我们就来看看乘法表的相关问题。《九九乘法歌诀》,又常称为“小九九”,如下图所示。你的任务是写一个程序,对于给定的一个正整数 n ,输出“九九乘法表”的前 n 行。例如,输入 n 为 9,你的程序的输出将为下图:
Input
输入包含多组测试数据,以 EOF 结束。每组测试数据只包含一个正整数 n (0 < n < 10)。
Output
int main()
{
int i, n, k, h;
while (scanf("%d", &n) != EOF)
{
// scanf("%d", &n);
for (i = 1; i <= n; i++)
{
for (k = 1; k <= i; k++)
{
if (k == i)
printf("%d*%d=%d", k, i, k * i);
else
printf("%d*%d=%d ", k, i, k * i);
}
printf("\n");
}
}
return 0;
}
AC
Problem Description
Input
Output
Example Input
3 0 1 3 4 1 1 2 2 3 3
Example Output
1
#include <stdio.h>
int main()
{
int i, n, a, b, x1, x2, y1, y2, count;
while (scanf("%d", &n) != EOF)
{scanf("%d %d", &x1, &y1);
scanf("%d %d", &x2, &y2);
count = 0;
for (i = 1; i <= n; i++)
{
scanf("%d %d", &a, &b);
if (a > x1 && a < x2 && b > y1 && b < y2)
{
count++;
}
}
printf("%d\n", count);
}
return 0;
}
AD
Problem Description
Input
Output
int main()
{
int i, n, k, h;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
for (k = n; k > i; k--)
{
printf(" ");
}
for (h = 1; h <= i; h++)
{
if (h == 1)
printf("+");
else
printf("*");
}
for (h = i-1 ; h >= 1 ;h--)
{
if (h == 1)
printf("+");
else
printf("*");
}
}
for (i = n - 1; i > 0; i--)
{
{
}
for (h = 1 ; h <= i ;h++)
{
printf("+");
else
printf("*");
}
for (h = i - 1; h >= 1; h--)
{
if (h == 1)
printf("+");
else
printf("*");
}
}
return 0;
}
AE
Problem Description
今天,小鑫在山上玩的时候,意外被推下了悬崖。
当然,掉下悬崖之后必然有奇遇。(剧情就是这么坑爹)就狗血的碰到了野人A和野人B。然后两位野人就给了他一本武功秘籍。
这是一本强大的武功秘籍(好像武功秘籍一直都很强大)。共有40层的内功心法。当他练到第n层的时候,就可以借助高强的武功离开这个地方。你已经知道的是:练成第一层需要一天,练成第二层需要两天,此后每一层武功要练成所需的天数是前两层所需天数之和。也就是说第三层需要三天才能练成,因为1+2=3嘛。
当然,当他练成的那一天,他一定会去感谢野人们对他的帮助。那天他们会嗨到很晚,只能第二天在离开。
你能预测出多少天后小鑫能离开么?
Input
输入有多组,以文件结尾结束。
每组只有一行,n。0<=n<=40
Output
输出小鑫第几天才能离开,当然当n=0时,输出0,因为他不需要秘籍也能离开,也不需要感谢野人。
Example Input
1
2
0
Example Output
2
4
0
#include <stdio.h>
int main()
{ int i, n, s, a, b, x;
while ((scanf("%d", &n)) != EOF)
{
s = 0;
a = 1;
b = 2;
for (i = 1; i <= n; i++)
{ if (i == 1 || i == 2)
x = i;
else
{ x = a + b;
a = b;
b = x;
}
s = s + x; }
if (s != 0)
s++; printf("%d\n", s);
}return 0;
}