一道c语言的题,高分悬赏(最好有注释)

2024-11-14 19:09:54
推荐回答(3个)
回答1:

这个函数的意思就是,你有178块钱,那么你就要转换成1张100的,1张50的,1张20的,1张5块的,1张2块的,1张1块的。
只不过你的问题没有我举的例子这么复杂。
#include
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
}

回答2:

好简单的题目啊!how simple this question is!

#include
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;
}

回答3:

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-_-