仅供参考,欢迎指正
1. 9.50
2. 0
3. 2.50
4. 3.50
5. 1
6. 0
7. 7
8. 0
9. 1
10. 0
11. 1
12. 1
13. 0
14. 1
15. 24
16. 60
17. 0
18. 3
19. 0
20. 64
⭐ 直接拷贝输出就好
#include
int main(){
// 1
// printf("%f\n",3.5+1/2+56%10);//9.50000
//2
// int a = 2;
// printf("%d\n",a++*1/3);//0.000000
//3
// float x = 2.5,y = 4.7;
// int a = 7;
// printf("%f",x+a%3*(int)(x+y)%2/4);//2.500000
//4
// int a = 2;
// int b = 3;
// float x = 3.5,y = 2.5;
// printf("%f",(float)(a+b)/2 + (int)x % (int)y);//3.500000
//5
// int x = 3, y = 4; // 下边中间的 x+5 不是 x += 5 (x 值不变)
// printf("%d",(x = ++y,x+5,x/5));// 1 (看最后一个表达式子的值)
//6
// int x = 4,y = 3;
// printf("%d",(x>y>=2)?1:0);// 0 x>y == 1; 1>=2 == 0;
//7
// int a = 5, b = 6;
// printf("%d",(++a=b--)?++a:--b);// 7
//8~14
/*
int a = 3,b = 4, c = 5;
printf("%d\n",b>c&&b==c);
printf("%d\n",!(a>b)&&!c||1);
printf("%d\n",!(a=c)&&(b-c)&&0);
printf("%d\n",!(a+b)+c-1&&b+c/2);
printf("%d\n",a||(b+b)&&(c-a));
printf("%d\n",(!a==1)&&(!b==0));
printf("%d\n",a&&(b||c));
*/
//15~20
int a = 12;
// printf("%d\n",a+=a);// 24
// printf("%d\n",a*=2 + 3);// 60
// printf("%d\n",a/=a+1);// 0
// printf("%d\n",a >>= 2);//3 (12 二进制 11000)
// printf("%d\n",a+=a -= a*=a);//0 (从左往右顺序计算 )
printf("%d\n",a <<= a-=8);//64 ( -= 优先级高于 <<=)
return 0;
}
⭐ 公式化简直接求解
#include
int main(){
double r1,r2;
scanf("%lf %lf",&r1,&r2);
printf("%.2lf",r1*r2/(r1+r2));
return 0;
}
⭐ 记录最大值和最小值
#include
int main(){
double max = -1e9;
double min = 1e9,t;
int n;
scanf("%d",&n);
while(n--){
scanf("%lf",&t);
max = max > t ? max : t;
min = min < t ? min : t;
}
printf("%.2lf",max-min);
return 0;
}
推公式很难?无所谓,我会套公式
⭐ 临时变量版
#include
int main()
{
int n,i;
scanf("%d", &n);
int an = 0;
int t = 2;
for (i = 1; i <= n; i++){
an = t + 2 * (i - 1);
t = an;
}
printf("%d", an);
}
⭐ 数组版
#include
int main() {
int n, A[1000], i; // 数组长度1000足够
scanf("%d", &n);
A[0] = 2; // 初始化A[1]为2
for (i = 1; i < n; i++) {
A[i] = A[i-1] + 2*i; // 计算An的值
}
printf("%d\n", A[n-1]);
return 0;
}
⭐ 递推(特殊处理前两项然后套公式)
#include
int main()
{
int n;
scanf("%d", &n);
int f1 = 0, f2 = 1, fn = 0,i;
for ( i = 3; i <= n; i++) {
fn = (i-1) * (f1 + f2);
f1 = f2;
f2 = fn;
}
if(n == 2)
fn = 1;
if(n == 1)
fn = 0;
printf("%d", fn);
return 0;
}
⭐ 输入: fgets(字符数组, 长度, 输入源)
⭐ ASII 码值的应用
#include
int main()
{
int i;
char ss[61];
//初始化字符数组
for (i = 0; i < 61; i++)
ss[i] = ' ';
fgets(ss, 60, stdin);//读取一行字符串
for (i = 0; i < 61; i++){
char c = ss[i];
if (c >= 97 && c <= 122)//小写 --> 大写
{
ss[i] = (c - 32-'A'+3) % 26 + 'A' ;
}
else if (c >= 65 && c <= 90)//大写 --> 小写
ss[i] = (c + 32-'a' + 3) % 26 + 'a';
else if (c >= 48 && c <= 57)//数字 --> 后延5个符号
ss[i] = (c - '0' + 5) % 10 + '0';
}
for (i = 0; i < 61; i++)
printf("%c", ss[i]);
return 0;
}
⭐ a 除以 b : a ÷ b
⭐ a 除 b: b ÷ a
#include<stdio.h>
int main()
{
int a,b,c,d,i;
scanf("%d %d", &a, &b);
printf("%d/%d=", a, b);
while (1){
c = b/a + 1;// 分母 c
a = a*c - b;
b *= c;
printf("1/%d+", c);
//出口(结束条件)
if (a > 1 && b%a == 0)
{
printf("1/%d", b / a);
break;
}
if (a == 1){
printf("1/%d", b);
break;
}
}
return 0;
}
⭐ 暴力枚举
#include
int main()
{
int a, b, c, d;
for (a = 1; a <= 4; a++)
for (b = 1; b <= 4; b++)
for (c = 1; c <= 4; c++)
for (d = 1; d <= 4; d++)
if (a != b && a != c && a != d && b != c && b != d && c != d)
if ((c == 1 && a != 3) || (c != 1 && a == 3))//甲对一半
if ((b == 1 && d != 4) || (b != 1 && d == 4))//乙对一半
if ((d == 2 && c != 3) || (d != 2 && c == 3))//丙对一半
printf("abcd\n%d%d%d%d\n", a, b, c, d);
return 0;
}