c语言编程练习题:7-55 查询水果价格
作者:yunjinqi   类别:    日期:2023-05-29 16:57:16    阅读:124 次   消耗积分:0 分    

image.png

#include <stdio.h>
int main(){
    int count=0;
    int n=0;
    double prices[5] = {0,3.00,2.50,4.10,10.20};
    char names[][7] = {"exit","apple","pear","orange","grape"};
    int sequences[5] = {1,2,3,4,0};
    int i;
    int r=0;
    char *s;
    // 输出编号和名字
    for (i=0;i<5;i++){
        r = sequences[i];
        s = names[r];
        printf("[%d] %s\n",r,s);
    }
    // 保存查询的num
    //while (scanf("%d",&n)!=EOF && count<5){
    while (scanf("%d", &n) != EOF) {
        
        if (count>=5){break;}
        if (n==0){break;}
        //printf("n=%d %.2f\n",n, prices[n]);
        //if (n>4){printf("price = 0.00\n");}
        //if (n<0){printf("price = 0.00\n");}
        if (n<=4 && n>0){printf("price = %.2f\n",prices[n]);}
        else{printf("price = 0.00\n");}
        count++;
    }
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/180
上一篇:c语言编程练习题:7-54 求阶乘序列前N项和
下一篇:c语言编程练习题:7-56 求给定精度的简单交错序列部分和