一道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个月,学的不是很深,都是基础,希望大家能够用简单点的方法帮我解——使用函数模块(属于流程控制)我们现在学到的有数据处理和交互式输入,流程控制(选择控制和循环控制)谢谢大家,麻烦好心人了~! 展开
展开全部
这个函数的意思就是,你有178块钱,那么你就要转换成1张100的,1张50的,1张20的,1张5块的,1张2块的,1张1块的。
只不过你的问题没有我举的例子这么复杂。
#include<stdio.h>
void TransChange(int total,int *gallon,int *quart,int *pint,int *cup)
{
*gallon=total/16;//get the number of gollon
total=total%16;//change the total at the quart
*quart=total/4;//get the number of quart
total=total%4;//change the total at the pint
*pint=total/2;//get the number of pint
total=total%2;//change the tatal at the cup
*cup=total;//get the number of cup
}
void main(void)
{
int total,gallon,quart,pint,cup;//define the variables
printf("please input the total of cup\n");//register input
scanf("%d",&total);//input the variable of total
TransChange(total,&gallon,&quart,&pint,&cup);
printf("The result is %d gallons,%d quarts,%d pints,%d cups\n",gallon,quart,pint,cup);//output the result
}
只不过你的问题没有我举的例子这么复杂。
#include<stdio.h>
void TransChange(int total,int *gallon,int *quart,int *pint,int *cup)
{
*gallon=total/16;//get the number of gollon
total=total%16;//change the total at the quart
*quart=total/4;//get the number of quart
total=total%4;//change the total at the pint
*pint=total/2;//get the number of pint
total=total%2;//change the tatal at the cup
*cup=total;//get the number of cup
}
void main(void)
{
int total,gallon,quart,pint,cup;//define the variables
printf("please input the total of cup\n");//register input
scanf("%d",&total);//input the variable of total
TransChange(total,&gallon,&quart,&pint,&cup);
printf("The result is %d gallons,%d quarts,%d pints,%d cups\n",gallon,quart,pint,cup);//output the result
}
2008-12-02
展开全部
好简单的题目啊!how simple this question is!
#include<stdio.h>
void TransChange(int total,float *gallon,float *quart,float *pint,float *cup)
{
*gallon=total/16.0;
*quart=total/4.0;
*pint=total/2.0;
*cup=total;
}
int main(void)
{
int total;
float gallon,quart,pint,cup;
printf("Please input the total of cups:\n");
scanf("%d",&total);
TransChange(total,&gallon,&quart,&pint,&cup);
printf("The result is %f gallons or %f quarts or %f pints or %f cups.\n",gallon,quart,pint,cup);
return 0;
}
#include<stdio.h>
void TransChange(int total,float *gallon,float *quart,float *pint,float *cup)
{
*gallon=total/16.0;
*quart=total/4.0;
*pint=total/2.0;
*cup=total;
}
int main(void)
{
int total;
float gallon,quart,pint,cup;
printf("Please input the total of cups:\n");
scanf("%d",&total);
TransChange(total,&gallon,&quart,&pint,&cup);
printf("The result is %f gallons or %f quarts or %f pints or %f cups.\n",gallon,quart,pint,cup);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Define a struct which include 4 members:gallons,quarts,pints,cups.
Define variable "total" for "input cups";the function liquid() would caculate the data of the struct's member according to the "cups".
/********************Start Program***************************/
typedef struct
{
int gallons;
int quarts;
int pints;
int cups;
} TLIQUID;
void liquid( TLIQUID *this, int total )
{
this->gallons = ( total/16 );//16cups to a gallon
this->quarts = ( total/4 ); //4 cups to a quart
this->pints = ( total/2 ); //2 cups to a pint
this->cups = ( total ); //cups to cups:)
}
/*************************************************************/
I assume it should be OK,try it:-)
And, DO NOT FORGET the REWORD-_-
Define variable "total" for "input cups";the function liquid() would caculate the data of the struct's member according to the "cups".
/********************Start Program***************************/
typedef struct
{
int gallons;
int quarts;
int pints;
int cups;
} TLIQUID;
void liquid( TLIQUID *this, int total )
{
this->gallons = ( total/16 );//16cups to a gallon
this->quarts = ( total/4 ); //4 cups to a quart
this->pints = ( total/2 ); //2 cups to a pint
this->cups = ( total ); //cups to cups:)
}
/*************************************************************/
I assume it should be OK,try it:-)
And, DO NOT FORGET the REWORD-_-
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询