首页 > 试题广场 >

学生基本信息输入输出

[编程题]学生基本信息输入输出
  • 热度指数:205762 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
依次输入一个学生的学号,以及3科(C语言,数学,英语)成绩,在屏幕上输出该学生的学号,3科成绩(注:输出成绩时需进行四舍五入且保留2位小数)。

数据范围:学号满足 ,各科成绩使用百分制,且不可能出现负数

输入描述:
学号以及3科成绩,学号和成绩之间用英文分号隔开,成绩之间用英文逗号隔开。


输出描述:
学号,3科成绩,输出格式详见输出样例。
示例1

输入

17140216;80.845,90.55,100.00

输出

The each subject score of No. 17140216 is 80.85, 90.55, 100.00.
示例2

输入

123456;93.33,99.99,81.20

输出

The each subject score of No. 123456 is 93.33, 99.99, 81.20.
#include <stdio.h>
double sol(double x)
{
    int e = x * 1000, f = x * 100, h = f * 10, g = e - h;
    double F = f;
    if (g < 5)
    {
        double z = 0;
        z = F / 100;
        return z;
    }
    else
    {
        double z = 0;
        z = ++F / 100;
        return z;
    }
}
int main(void)
{
    double a = 0, b = 0, c = 0;
    unsigned long long int d = 0;
    scanf("%llu;%lf,%lf,%lf", &d, &a, &b, &c); //这要求符号隔开,起码vs2022最好用空格或者干脆不隔开,容易出问题
    double A = sol(a);
    double B = sol(b);
    double C = sol(c);
   /* double eps = 1e-8;
    a = a + eps;
    b = b + eps;
    c = c + eps;*/
    printf("The each subject score of No. %llu is %.2lf, %.2lf, %.2lf.", d, A, B, C);
    return 0;
}
发表于 2024-11-10 15:49:52 回复(1)
#include <stdio.h>

int main()
{
    int a;//the number
    double b,c,d;//three scores
    scanf("%d;%lf,%lf,%lf",&a,&b,&c,&d);
    printf("The each subject score of No. %d is %.2lf, %.2lf, %.2lf.",a,b,c,d);
    return 0;
}

发表于 2024-10-23 19:43:17 回复(2)
#include <stdio.h>
int main()
{
    int a = 0;//学号
    double b = 0.00;//c语言成绩
    double c = 0.00;//数学成绩
    double d = 0.00;//英语成绩

    scanf("%d;%lf,%lf,%lf", &a,&B,&C,&D);
    if (a >= 1, a <= 20000000 && B >= 0 && C >= 0 && D >= 0)//限制条件,养成习惯
    {
        double b = (int)((B * 100) + 0.5) / 100.0;//四舍五入
        double c = (int)((C * 100) + 0.5) / 100.0;//四舍五入
        double d = (int)((D * 100) + 0.5) / 100.0;//四舍五入
        printf("The each subject score of No. %d ",a);
        printf("is %.2lf, ", b);
        printf("%.2lf, ", c);
        printf("%.2lf.", d);
        //.2的意思是保留小数点后两位
    }
    else
    {
        printf("错误");
    }

    return 0;
}
发表于 2024-10-20 21:09:23 回复(0)
#include <stdio.h>

int main() 
{
    int n = 0;
    float C = 0.0;
    float M = 0.0;
    float Y = 0.0;

    scanf("%d;%f,%f,%f",&n,&C,&M,&Y);

    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",n,C,M,Y);

    return 0;

}

发表于 2024-08-03 17:07:21 回复(0)
#include <stdio.h>
int main() 
{
   int a=0;
   float b=0, c=0, d=0;
   scanf("%d ;%f, %f, %f", &a, &b, &c ,&d);
   printf("The each subject score of N0. %d is  %.2f , %.2f %.2f.",a , b , c , d);
    return 0;
 }

这怎么会一直答案错误呢?

发表于 2024-07-19 18:25:35 回复(1)
#include <stdio.h>
int main()
{
    double a,b,c;
    int m;
    scanf("%d;%lf,%lf,%lf",&m,&a,&b,&c);
    printf("The each subject score of No. %d is %.2lf, %.2lf, %.2lf.",m,a,b,c);
    return 0;
为什么用双精度double就不行了
发表于 2024-07-04 17:19:32 回复(2)
#include <stdio.h>

struct stu{
    int n;
    float C;
    float Math;
    float English;
}p;

int main() {
    scanf("%d;%f,%f,%f",&p.n,&p.C,&p.Math,&p.English);
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",p.n,p.C,p.Math,p.English);
    return 0;
}
编辑于 2024-04-25 15:55:43 回复(0)
int main()
{
    int id;
    float c,math,eng;
    scanf("%d;%f,%f,%f",&id,&c,&math,&eng);
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",id,c,math,eng);//%.2f表示浮点数保留小数点后两位
    return 0;
}
发表于 2024-04-12 14:47:17 回复(0)
#include <stdio.h>

int main() 
{
    long long number = 0;
    float a, b, c;

    scanf("%lld;%f,%f,%f", &number, &a, &b, &c);

    printf("The each subject score of No. %lld is %.2f, %.2f, %.2f.\n", number, a, b, c);

    return 0;
}

编辑于 2024-03-02 19:19:37 回复(0)
#include <stdio.h>

int main() {
    int a;
    float b,c,d;
    scanf ("%d;%f,%f,%f",&a,&b,&c,&d);
    //空格是重灾区
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",a,b,c,d);
    return 0;
}
编辑于 2024-03-01 16:43:17 回复(0)
#include <stdio.h>

int main() {
    float a,b,c,d;
    char e = 'a';
    scanf("%f%c%f%c%f%c%f",&a,&e,&b,&e,&c,&e,&d);
    printf("The each subject score of No. %.0f is %.2f, %.2f, %.2f.",a,b,c,d);
return 0;
}
真是服了,字符也算输入去了。
发表于 2024-01-31 16:44:10 回复(0)
#include <stdio.h>
#include <math.h>

int main() {
    struct student {
        int number;
        float c_score;
        float math_score;
        float english_score;
    };
    struct student stu;
    scanf("%d;%f,%f,%f", &stu.number, &stu.c_score, &stu.math_score, &stu.english_score);
    stu.c_score = round(stu.c_score * 100) / 100;
    stu.math_score = round(stu.math_score * 100) / 100;
    stu.english_score = round(stu.english_score * 100) / 100;
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.", stu.number, stu.c_score, stu.math_score, stu.english_score);
    return 0;
}
发表于 2024-01-09 14:39:41 回复(0)
#include <stdio.h>
#include<math.h>
int main() {
    int a=0;
    double b=0,c=0,d=0,b1,c1,d1;
    scanf("%d;%lf,%lf,%lf",&a,&b,&c,&d);
    b1=round(b*100)/100;
    c1=round(c*100)/100;
    d1=round(d*100)/100;
    printf("The each subject score of No. %d is",a);
    printf(" %.2lf,",b1);
    printf(" %.2f,",c1);
    printf(" %.2f.",d1);
    return 0;
}
编辑于 2024-01-05 13:24:24 回复(0)
#include <stdio.h>

int main() {
    int a=0;
    float b=0,c=0,d=0;
    scanf("%d;%f,%f,%f",&a,&b,&c,&d);
    printf("The each subject score of No.%d is %.2f,%.2f,%.2f.\n",a,b,c,d);
    return 0;
}
发表于 2023-12-19 18:49:49 回复(0)
#include<stdio.h>
int main()
{
    int n=0;
    float c=0;
    float math=0;
    float english=0;
    scanf("%d;%f,%f,%f",&n,&c,&math,&english);
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",n,c,math,english);
    return 0;
}

发表于 2023-11-20 16:02:23 回复(0)
#include <stdio.h>

int main()
{
    int stu = 0;
    float c = 0;
    float math = 0;
    float english = 0;
    scanf("%d;%f,%f,%f",&stu,&c,&math,&english);
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",stu,c,math,english);
    return 0;
}
发表于 2023-11-17 15:15:41 回复(0)
发表于 2023-11-11 16:27:57 回复(1)
#include <stdio.h>
#include <math.h>

// Function to round a score to two decimal places
double round_score(double);

int main() {
    int id;
    double score1, score2, score3;

    scanf("%d;%lf,%lf,%lf", &id, &score1, &score2, &score3);

    score1 = round_score(score1);
    score2 = round_score(score2);
    score3 = round_score(score3);

    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.", id, score1, score2, score3);

    return 0;
}

double round_score(double score) {
    return round(score*100)/100;
}

发表于 2023-11-09 21:05:25 回复(0)
int main() {
    int num;
    float a, b, c;
    int n1, n2, n3;
    scanf("%d", &num);
    scanf("%f%f%f", &a, &b, &c);
    n1 = a * 1000;
    n2 = b * 1000;
    n3 = c * 1000;
    if (n1 % 10 >= 5)
        a = (n1 + 10) / 1000;
    if (n2 % 10 >= 5)
        b = (n2 + 10) / 1000;
    if (n3 % 10 >= 5)
        c = (n3 + 10) / 1000;
    printf("The each subject score of No. %d is %.2f,%.2f,%.2f", num, a, b, c);
    return 0;
}
发表于 2023-11-07 22:18:28 回复(0)