本文目錄一覽:
c程序編寫一個水果店售貨員算賬的程序
#includestdio.h
void main()
{
float n[4],apple=2.5,pear=1.8,banana=2,orange=1.6,price,charge,money;
printf(“請輸入水果重量蘋果 鴨梨 香蕉 橘子 (不買的水果請輸入0): \n”);
int i;
for(i=0;i4;i++)scanf(“%f”,n[i]);
printf(“應付錢 %.2f 元\n”,price=apple*n[0]+pear*n[1]+banana*n[2]+orange*n[3]);
printf(“請輸入付款數:”);scanf(“%f”,money);
printf(“應找錢 %.2f 元\n”,money-price);
}
c語言,編寫一個售貨機(POS)計算程序,用於水果店售貨員算賬.蘋果每千克3.2元,梨每千克1.96元,香
#include stdio.h
int main(void)
{
float p[4] = {3.2, 1.96, 3, 24};
float w[4] = {1.5, 2, 3, 1.5};
float s = 0;
int i;
for(i=0;i4;i++)
s+= p[i]*w[i];
printf(“%s%12s%12s%13s\n”, “名稱”, “單價”, “重量”, “應付價錢”);
printf(“———————————————\n”);
printf(“%s%12.2f%12.2f%13.3f\n”,”蘋果”, p[0], w[0], p[0]*w[0]);
printf(“%s%12.2f%12.2f%13.3f\n”,”梨 “, p[1], w[1], p[1]*w[1]);
printf(“%s%12.2f%12.2f%13.3f\n”,”香蕉”, p[2], w[2], p[2]*w[2]);
printf(“%s%12.2f%12.2f%13.3f\n”,”櫻桃”, p[3], w[3], p[3]*w[3]);
printf(“———————————————\n”);
printf(“%s%37.2f\n”, “總計”, s);
printf(“%s%37.2f\n”, “付款”, 100.0);
printf(“%s%37.2f\n”, “找零”, 100.0 – s);
return 0;
}
問一道關於記賬的c語言程序
#includestdio.h
void fun(){
int i, ch; float price = 9.8, in_price, total = 0; while (1){
printf(“\n1.算賬模式\n2.算賬\n3.退出\n”);
scanf(“%d”, i);
switch (i){
case 1://算賬模式
{
do{
printf(“應付款金額 %f 元.\n付款金額:”, price);
scanf(“%f”, in_price);
printf(“實際付款金額%f,應找零金額 %f 元.\n”, in_price, in_price – price);
total += price;
scanf(“%d”, ch);
} while (ch != -1);
break;
}
case 2:{
printf(“收款總額:%6.2f 元.\n”, total); break;
}
case 3:
exit(0);
}
}
}
void main()
{
fun();
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/250890.html