....

2014年5月13日 星期二

[長知識] C語言 - 新手篇章 - 老闆請問打幾折

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {

int price;
float discounts, total;

printf("老闆請問多少錢?\n");


 //取記憶體price的數值
scanf("%i", &price);

printf("老闆請問打幾折?\n");
scanf("%f", &discounts);

 //算出total價格
total = price*discounts/10;

//取小數點後2位
printf("打 %.2f 折後為%f", discounts, total);

return 0;
}

沒有留言:

張貼留言