C语言。CDOJ的买菜问题的失败版本

本文展示了一个使用C语言编写的简单买菜程序。程序通过输入卡余额和各种菜的价格,实现了价格排序功能,并预留了购买流程的实现空间。本文涉及C语言的基础语法和简单的数组操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//买菜
#include<stdio.h>
#include<string.h>
int main(void)
{
    int left;//卡的余额
    int N;//菜有N种
    int price[200];//每种菜的价格
    int money;//剩下的钱数
/*
    scanf("%d",&left);//输入卡的余额
    scanf("%d",&N);//输入菜的品种数目
    printf("%d\n",left);
    printf("%d\n",N);
*/
    int i=0;//输入菜的价格。
    for(i=0;i<=200;i++)
    {
        scanf("%d",&price[i]);
        getchar();
    }
    int j=0;//排序.
    for(j=0;j<=(strlen(price)-1);j++)
    {
        int smallest;
        smallest=j;
        int k=0;
        int temp;
        for(k=j+1;k<=(strlen(price)-1);k++)
        {
            if(price[k]<price[smallest])
            {
                temp=price[k];
                price[k]=price[smallest];
                price[smallest]=temp;
            }
        }
    }
    int q=0;
    for(q=0;q<=strlen(price);q++)
    {
        printf("%d ",price[q]);
    }
/*
    int p=0;//开始买菜。。。
    for(p=0;p<=strlen(price);p++)
    {
        money=left-price[p];
        if(money<5)
            printf("剩下的钱是%d",money);
    }
*/
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值