首页 > 试题广场 >

学生基本信息输入输出

[编程题]学生基本信息输入输出
  • 热度指数:230344 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
依次输入一个学生的学号,以及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>

int main() {
    int id;
    double score1, score2, score3;
    scanf("%d;%lf,%lf,%lf", &id, &score1, &score2, &score3);
    
    // 添加0.0005偏移确保四舍五入正确
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.", 
           id, 
           score1 + 0.0005,
           score2 + 0.0005,
           score3 + 0.0005);
    return 0;
}
float类型用不了,四舍五入的精度不够,让人很费解
发表于 2025-06-14 11:51:33 回复(1)
我这个一直报错是什么原因

#include <stdio.h>
double a, b, c;
unsigned int xuehao;
int main()
{
	scanf("%d;%lf,%lf,%lf", &xuehao, &a, &b, &c);//scanf可以实现一次获取多个不同类型的按键值
	printf("The each subject score of No. %d is %.2lf, %.2lf, %.2lf.", xuehao, a, b, c);
	return 0;

}

发表于 2025-05-22 17:01:22 回复(1)
#include <stdio.h>
float sheru(float q){
    int x=0;
    x=(int)(q*1000)%10;
    if(x>4) q=q+0.01-x*0.001;
    else q=q-x*0.001;
    return q;
}
int main() {
    long number=0;
    float c=0,m=0,e=0;
    scanf("%ld;%f,%f,%f",&number,&c,&m,&e);
    c=sheru(c);
    m=sheru(m);
    e=sheru(e);
    printf("The each subject score of No. %ld is %.2f, %.2f, %.2f.",number,c,m,e);
    return 0;
}
这样子可以通过,我猜大概率是浮点数存储有误差,导致有时候没法很好做到四舍五入。我这里定义了一个函数可以稍微纠正一下;
发表于 2025-04-16 00:34:28 回复(0)
为什么有一组不对,四舍五入的问题 ,搞不懂   
float=0.0f;
    float j=0.0f;
    float k=0.0f;
    int a=0;
    scanf("%d;%f,%f,%f",&a,&i,&j,&k);
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.\n",a,i,j,k);

发表于 2025-02-12 13:29:14 回复(2)
#include <math.h>
#include <stdio.h>

int main() 
{
    int SuID = 0;
    float C = 0;
    float math = 0;
    float Eg = 0;
    scanf("%d;%f,%f,%f",&SuID,&C,&math,&Eg);
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",SuID,round(C * 100) / 100,math,Eg);
    return 0;
}
//C语言成绩这里因为浮点数存储有不准确性,所以有概率出现四舍五入不对的情况,这个时候要用round(变量 * 100) / 100 来让浮点数变得具有准确性

发表于 2025-01-19 14:33:06 回复(4)
#include <stdio.h>
int main()
{
    int a;
    float b = 0.0f;
    float c = 0.0f;
    float d = 0.0f;
    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;
}
这代码为什么不会四舍五入
发表于 2025-01-16 16:45:40 回复(2)
#include <stdio.h>
struct stu {
    int n;
    float C;
    float Math;
    float English;
};

int main() {
    struct stu s = {0,0.0f,0.0f,0.0f};
    scanf("%d;%f,%f,%f",&s.n,&s.C,&s.Math,&s.English);
    if (s.n >= 1 && s.n <= 20000000 && s.C >= 0 && s.Math >= 0 && s.English >= 0) {
        printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",s.n,s.C,s.Math,s.English);
    }
    return 0;
}
发表于 2024-12-31 19:56:24 回复(0)
#include <stdio.h>

int main() {
    int a;
    float b,c,d;
    scanf("%d%f%f%f",&a,&b,&c,&d);
    if(a>=1&&a<=20000000){
        printf("The each subject score of No. %d is %.2f,%.2f,%.2f",a,b,c,d);
    }
    return 0;
}大佬们请帮忙看看为什么出错
发表于 2024-12-21 14:44:33 回复(1)
#include <stdio.h>
int main() {
    float a , b , c ;
     int n;
    scanf("%d", &n);
    scanf("%f%f%f", &a, &b, &c);
    printf("The each subject score No.%d is %.2f, %.2f, %.2f.\n", n, a, b, c);
    return 0;
}为什么这个代码错误
发表于 2024-11-24 18:15:16 回复(1)
#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 回复(3)
#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)