算法笔记刷题(100000566-100000568)第一天

算法笔记刷题(100000566-100000568)第一天


以前的 codeup打不开,新的网址使用

http://codeup.hustoj.com/problem.php?cid=题组号(二维码上面网址的cid)

100000566

A

#include <stdio.h>

int main()
{
    printf("This is my first c program!");
}

B

#include <stdio.h>

int main()
{
    printf("********************\nVery Good!\n********************");
}

C

#include <stdio.h>
int main()
{
    int a=123,b=456,sum;
    sum=a+b;
    printf("sum=%d",sum);
    return 0;
}

D

#include <stdio.h>

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d", a + b);
    return 0;
}

E

#include <stdio.h>
#include <math.h>

int main()
{
    double a,b,c;
    scanf("%lf %lf %lf",&a,&b,&c);
    double delt;
    delt=pow(b,2)-4*a*c;
    if(a==0)
        return 1;
    if(delt<=0)
        return 1;
    else
    {
        double r1,r2;
        r1=(-b+sqrt(delt))/(2*a);
        r2=(-b-sqrt(delt))/(2*a);
        printf("r1=%7.2f\nr2=%7.2f",r1,r2);
    }
    return 0;

}

F

#include <stdio.h>
#include <math.h>

int main()
{
    char a[4],c;
    int i = 0;
    while ((c=getchar()) != '\n'&&i<3) {
        a[i] = c;
        i++;
    }
    a[3] = '\0';
    printf("%s\n", a);
    return 0;
}

100000567

A

#include <stdio.h>
#include <math.h>

int main()
{
    double a, b, c;
    scanf("%lf %lf %lf", &a,&b, &c);
    double delt = pow(b, 2) - 4 * a * c;
    if (a == 0||delt<0) {
        printf("No real roots!");
    }
    else {
        printf("r1=%7.2f\nr2=%7.2f", (-b + sqrt(delt)), (-b - sqrt(delt)));
    }
    return 0;
}


B

#include <stdio.h>

int main()
{
    double a, b;
    scanf("%lf %lf", &a, &b);
    if (a <= b) {
        printf("%.2f %.2f", a, b);
    }
    else {
        printf("%.2f %.2f", b, a);
    }

    return 0;
}

C

先进行a,b(前两位)的比较,再进行c与b比较(交换),再进行a,b(前两位)的比较。c一步步先前移。

#include <stdio.h>

int main()
{
    double a, b,c,temp;
    scanf("%lf %lf %lf", &a, &b,&c);
    if (a > b) {
        temp = b;
        b = a;
        a = temp;
    }
    else if (c<b) {
        temp = b;
        b = c;
        c = temp;
        if (b < a) {
            temp = b;
            b = a;
            a = temp;
        }
    }
    printf("%.2f %.2f %.2f", a, b, c);
    return 0;
}

D

设置中间值max

#include <stdio.h>
#include <math.h>

int main()
{
    int a, b,c;
    scanf("%d %d %d", &a, &b,&c);
    int max = a;
    if (b > max) {
        max = b;
    }
    if (c > max) {
        max = c;
    }
    printf("%d", max);
    return 0;
}

E

#include <stdio.h>
#include <math.h>

int main()
{
    double benefit,reward;
    scanf_s("%lf", &benefit);
    double tail = 1e5;
    if (benefit <= tail) {
        reward = benefit * 0.1;
    }
    else if (benefit > tail && benefit <= (2 * tail)) {
        reward = tail * 0.1 + (benefit - tail) * 0.075;
    }
    else if (benefit > 2*tail && benefit <= (4 * tail)) {
        reward = tail * 0.1 + tail * 0.075+ (benefit - tail*2) *0.05;
    }
    else if (benefit > 4 * tail && benefit <= (6 * tail)) {
        reward = tail * 0.1 + tail * 0.075 + tail * 2 * 0.05+ (benefit - tail * 4) * 0.03;
    }
    else if (benefit > 6 * tail && benefit <= (10 * tail)) {
        reward = tail * 0.1 + tail * 0.075 + tail * 2 * 0.05 + tail * 2 * 0.03+ (benefit - tail * 6) * 0.015;
    }
    else {
        reward = tail * 0.1 + tail * 0.075 + tail * 2 * 0.05 + tail * 2 * 0.03 + tail * 4 * 0.015+ (benefit - tail * 6) * 0.01;;

    }
    printf("%.2f\n", reward);
    return 0;
}

100000568

A

#include <stdio.h>

int main()
{
    int i = 1,sum=0;
    while (i <= 100) {
        sum = sum + i;
        ++i;
    }
    printf("%d", sum);
    return 0;
}

B

#include <stdio.h>
#include <math.h>

int main()
{
    int i = 1,sum=0;
    do
    {
        sum += i;
        ++i;
    } while (i<101);
    printf("%d\n", sum);
    return 0;
}

C

#include <stdio.h>
#include <math.h>

int main()
{
    int i,sum=0;
    for (i = 1; i <= 100; i++) {
        sum += i;
    }
    printf("%d\n", sum);
    return 0;
}

D

true在c中没有定义,编译不成功

#include <stdio.h>

int main()
{
    int i=1,n,sum=0;
    scanf("%d", &n);
    while (true) {
        sum += i;
        ++i;
        if (i > n) {
            break;
        }
  
    }
    printf("%d\n", sum);
    return 0;
}

E

#include <stdio.h>

int main()
{
    int i=1,sum=0;
    while (true) {
        sum += i;
        if (sum > 1000) {
            break;
        }
        ++i;     
    }
    printf("%d\n", i);
    return 0;
}

F

数组表示{},+表示显示正负号,-号左对齐,默认右对齐

#include <stdio.h>

int main()
{
    int a[4][5] = { {1,2,3,4,5},{2,4,6,8,10},{3,6,9,12,15},{4,8,12,16,20} },i,j;
    for (i = 0; i < 4; ++i) {
        for (j = 0; j < 5; ++j) {
            printf("%3d", a[i][j]);
        }
        printf("\n");
    }
    
    return 0;
}

G

#include <stdio.h>
#include <math.h>

int main()
{
    double a = 1, sum = 0.0;
    int i = 1;
    while (true) {
        if ((1 / a) < 1e-6) {
            break;
        }
        if (i % 2 == 1) {
            sum += 1 / a;
        }
        if(i % 2 == 0) {
            sum -= 1 / a;
        }
        ++ i;
        a += 2;

   }
    printf("PI=%10.8f", sum * 4);
    
    return 0;
}

H

#include <stdio.h>
int F(int n) {
    if (n == 1 || n == 2) {
        return 1;
    }
    else {
        return F(n - 1) + F(n - 2);
    }
}

int main()
{
    int n,sum=0;
    scanf_s("%d", &n);
    if (n > 50) {
        return 1;
    }
    else {
        printf("%d\n", F(n));
    }
    return 0;
}

I

#include <stdio.h>

int main()
{
    double a = 2, b = 1,sum = 0,temp;
    int i;
    for (i = 0; i < 20; ++i) {
        sum += a / b;
        temp = a;
        a = a + b;
        b = temp;
    }
    printf("%.6f", sum);

    return 0;
}

int n,sum=0;
scanf_s("%d", &n);
if (n > 50) {
    return 1;
}
else {
    printf("%d\n", F(n));
}
return 0;

}


I

```c++
#include <stdio.h>

int main()
{
    double a = 2, b = 1,sum = 0,temp;
    int i;
    for (i = 0; i < 20; ++i) {
        sum += a / b;
        temp = a;
        a = a + b;
        b = temp;
    }
    printf("%.6f", sum);

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sadnessdry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值