C語言的作業:將千米(double)轉化為英里(double),以前有順利寫出過。但這次要求用function來寫,但真的完全不知道function跟以前寫的有什么不同........要求:1. Create the prototype for the method2. create the method3. call it from the main()第一和第三不是很明白,第一個意思是寫一個偽碼?第三個從main()調用,這個調用是什么?還有prototypesvoid main{}Functions這是function的格式嗎?void main 查了下說是沒有返回值,這個返回值是什么?
3 回答

子衿沉夜
TA貢獻1828條經驗 獲得超3個贊
#include<stdio.h>
double km2mile(double km);//Create the prototype for the method即函數方法的聲明
void main()//main函數返回void型即不返回返回值,因為返回值沒有用處這里就不需要了
{
double km;
double result=0;
printf("請輸入千米數值\n");
scanf("%lf",&km);
result=km2mile(km);//call it from the main()函數的調用
printf("轉化為相應的英里為:");
printf("%f\n",result);
}
double km2mile(double km)//create the method函數的實現這個函數實現應該在main函數之后,
//如果在main函數之前那么第一步的聲明可以不要,所以題目給的格式是這樣的
{
return(0.62137*km);
}
- 3 回答
- 0 關注
- 1070 瀏覽
添加回答
舉報
0/150
提交
取消