返回书名,价格和页数的程序

问题描述 投票:1回答:2

这只是一个基本程序。我们将输入书名(1个字符名称),price(浮点数)和ant输出的页数(int)应与输入的相同,但不相同。

#include<stdio.h>

int main()
{
    struct book
    {
        char name;
        float price;
        int pages;
    };

    struct book b1,b2,b3;
    printf("Enter names,prices & no. of pages of 3 books\n");
    scanf("%c %f %d",&b1.name,&b1.price,&b1.pages);
    scanf("%c %f %d",&b2.name,&b2.price,&b2.pages);
    scanf("%c %f %d",&b3.name,&b3.price,&b3.pages);
    printf("And this is what you entered\n");
    printf("%c %f %d\n",b1.name,b1.price,b1.pages);
    printf("%c %f %d\n",b2.name,b2.price,b2.pages);
    printf("%c %f %d\n",b3.name,b3.price,b3.pages);
    return 0;
}

enter image description here

c struct structure
2个回答
1
投票

这是您输入的内容。浮点比实际值更近似。这就是为什么当您输入123.134时,计算机会四舍五入到最接近的可能值123.124003。它适用于工程,图形和统计,这些细微的差异在呈现给人类之前先经过四舍五入。但是,当您需要精确的值时,浮点变量是完全不合适的。


0
投票

您使用的程序错误。

© www.soinside.com 2019 - 2024. All rights reserved.