
c语言题~急!!!
编写一个名为liquid()的c语言函数,要求接收一个整型数字以及变量gallons,quarts,pints和cups的地址。被传递的整数表示杯的总数total以及以及...
编写一个名为liquid()的c语言函数,要求接收一个整型数字以及变量gallons,quarts,pints和cups的地址。被传递的整数表示杯的总数total以及以及这个函数要确定被传递数值中的加仑、夸脱、品脱和杯数的数量。使用传递的地址,这个函数应该直接改变调用函数中各自变量的数值。使用这个关系式:2杯等于1品脱,4杯等于一夸脱,16杯等于1加仑。
如用英文解答将追加分数50:
write a c function named liquid() that is to accept an integer number and the addresses of the variables gallons,quarts,pints and cups.the passed integer represents the total number of cups,and the function is to determine the number of gallons,quarts,pints and cups in the passed value.using the passed addresses,the function should directly alter the respective variables in the calling function.use the relationships of 2 cups to a pint,4 cups to a quart,and 16cups to a gallon.
最好有详解,谢谢~O(∩_∩)O
问题补充:我现在学c语言不到3个月,学的不是很深,都是基础,希望大家能够用简单点的方法帮我解——使用函数模块(属于流程控制)我们现在学到的有数据处理和交互式输入,流程控制(选择控制和循环控制)谢谢大家,麻烦好心人了~!这个是个很重要的作业,要求写的非常详细,希望大家能把完整的程序写出来最好写一些说明!!
只要能写出完整的程序就成,大家帮帮忙阿! 展开
如用英文解答将追加分数50:
write a c function named liquid() that is to accept an integer number and the addresses of the variables gallons,quarts,pints and cups.the passed integer represents the total number of cups,and the function is to determine the number of gallons,quarts,pints and cups in the passed value.using the passed addresses,the function should directly alter the respective variables in the calling function.use the relationships of 2 cups to a pint,4 cups to a quart,and 16cups to a gallon.
最好有详解,谢谢~O(∩_∩)O
问题补充:我现在学c语言不到3个月,学的不是很深,都是基础,希望大家能够用简单点的方法帮我解——使用函数模块(属于流程控制)我们现在学到的有数据处理和交互式输入,流程控制(选择控制和循环控制)谢谢大家,麻烦好心人了~!这个是个很重要的作业,要求写的非常详细,希望大家能把完整的程序写出来最好写一些说明!!
只要能写出完整的程序就成,大家帮帮忙阿! 展开
展开全部
实现如下,如果理解的不对,请补充,或单独留言
void liqiud(int iTotal, int* pGallons, int* pQuarts, int* pPints, int* pCups)
{
//calculator the gallons
*pGallons = iTotal/16;
//calculator the quarts
*pQuarts = (iTotal - 16*(*pGallons))/4;
//calculator the pints
*pPints = (iTotal - 16*(*pGallons) - 4*(*pQuarts))/2;
//the remainder is the cups
*pCups = iTotal - 16*(*pGallons) - 4*(*pQuarts) - 2*(*pPints);
}
int main(int argc, char* argv[])
{
int gallons;
int quarts;
int pints;
int cups;
int total = 100; //initial the total cups 100
printf("Please input the total cups: ");
scanf("%d", &total);
liqiud(total, &gallons, &quarts, &pints, &cups);
return 0;
}
void liqiud(int iTotal, int* pGallons, int* pQuarts, int* pPints, int* pCups)
{
//calculator the gallons
*pGallons = iTotal/16;
//calculator the quarts
*pQuarts = (iTotal - 16*(*pGallons))/4;
//calculator the pints
*pPints = (iTotal - 16*(*pGallons) - 4*(*pQuarts))/2;
//the remainder is the cups
*pCups = iTotal - 16*(*pGallons) - 4*(*pQuarts) - 2*(*pPints);
}
int main(int argc, char* argv[])
{
int gallons;
int quarts;
int pints;
int cups;
int total = 100; //initial the total cups 100
printf("Please input the total cups: ");
scanf("%d", &total);
liqiud(total, &gallons, &quarts, &pints, &cups);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询