下列函数的功能为________。void Exchange(int *p1, int *p2){ int p; p = *p1; *p1 = *p2; *p2 = p;}
#include
#define N 10
void ReadData(int a[], int n);
void PrintData(int a[], int n);
void Swap(int *x, int *y);
int main()
{
int a[N], b[N], i, n;
printf("Input array size(n<=10):");
scanf("%d", &n);
printf("Input array a:");
ReadData(a, n);
printf("Input array b:");
ReadData(b, n);
for (i=0; i<n; i++)
{
Swap(____________);
}
printf("Output array a:");
PrintData(a, n);
printf("Output array b:");
PrintData(b, n);
return 0;
}
/* 函数功能:输入数组a的n个元素值 */
void ReadData(int a[], int n)
{
int i;
for (i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
}
/* 函数功能:输出数组a的n个元素值 */
void PrintData(int a[], int n)
{
int i;
for (i=0; i<n; i++)
{
printf("%5d", a[i]);
}
printf("\n");
}
/* 函数功能:两整数值互换 */
void Swap(int *x, int *y)
{
int temp;
____________;
____________;
____________;
}
#include
int main(void)
{
static int x[] = {1,2,3};
int s = 1, i, *p = x;
for (i=0; i<3; i++)
{
s*= *(p + i);
}
printf("%d\n", s);
return 0;
}
#include
int FindMax(int a[], int n, int *pMaxPos);
int FindMin(int a[], int n, int *pMinPos);
int main()
{
int a[10], maxValue, maxPos, minValue, minPos, i;
printf("Input 10 numbers:");
for (i=0; i<10; i++)
{
scanf("%d", &a[i]); // 输入10个数
}
maxValue = FindMax(a, 10, _________); // 找最大值及其所在下标位置
minValue = FindMin(a, 10, _________); // 找最小值及其所在下标位置
printf("max=%d,pos=%d\n", maxValue, maxPos);
printf("min=%d,pos=%d\n", minValue, minPos);
return 0;
}
//函数功能:求有n个元素的整型数组a中的最大值及其所在下标位置,函数返回最大值
int FindMax(int a[], int n, int *pMaxPos)
{
int i, max;
max = a[0]; //假设a[0]为最大值
__________; //假设最大值在数组中的下标位置为0
for (i=1; i max)
{
max = a[i];
__________; //pMaxPos指向最大值数组元素的下标位置
}
}
return max ;
}
//函数功能:求有n个元素的整型数组a中的最小值及其所在下标位置,函数返回最小值
int FindMin(int a[], int n, int *pMinPos)
{
int i, min;
min = a[0]; //假设a[0]为最小
__________; //假设最小值在数组中的下标位置为0
for (i=1; i<10; i++)
{
if (a[i] < min)
{
min = a[i];
__________; //pMinPos指向最小值数组元素的下标位置
}
}
return min ;
}
#include
float Fun1(float x);
float Fun2(float x);
float Integral(float (*f)(float), float a, float b);
int main()
{
float y1, y2;
y1 = Integral(Fun1, 0.0, 1.0);
y2 = Integral(Fun2, 0.0, 3.0);
printf("y1=%f\ny2=%f\n", y1, y2);
return 0;
}
/* 函数功能:计算函数1+x*x的函数值 */
float Fun1(float x)
{
return 1 + x * x;
}
/* 函数功能:计算函数x/(1+x*x)的函数值 */
float Fun2(float x)
{
return x / (1 + x * x);
}
/* 函数功能:用梯形法计算函数的定积分 */
float Integral(float (*f)(float), float a, float b)
{
float s, h;
int n = 100, i;
s = __________;
h = __________;
for (i=1; i<n; i++)
{
s += __________;
}
return __________;
}
#include
int DayofYear(int year, int month, int day);
int dayTab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int main()
{
int year, month, day, yearDay;
printf("Please enter year, month, day:");
scanf("%d,%d,%d", &year, &month, &day);
yearDay = DayofYear(year, month, day);
printf("yearDay = %d\n", yearDay);
return 0;
}
/* 函数功能:对给定的某年某月某日,计算并返回它是这一年的第几天 */
int DayofYear(int year, int month, int day)
{
int i, leap;
leap = ________________________; /* 若year为闰年,即leap值为1,则用第1行元素dayTab[1][i]计算;
否则leap值为0,用第0行dayTab[0][i]计算 */
for (i=1; _______; i++)
{
day = ________________;
}
return day; /* 返回计算出的day的值 */
}
#include
void ReadData(int a[], int n);
void PrintData(int a[], int n);
void MaxMinExchang(int a[], int n);
void Swap(int *x, int *y);
int main()
{
int a[10], n;
printf("Input n(n<=10):");
scanf("%d", &n);
printf("Input %d numbers:", n);
ReadData(a, n);
MaxMinExchang(a, n);
printf("Exchange results:");
PrintData(a, n);
return 0;
}
/* 函数功能:输入数组a的n个元素值 */
void ReadData(int a[], int n)
{
int i;
for (i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
}
/* 函数功能:输出数组a的n个元素值 */
void PrintData(int a[], int n)
{
int i;
for (i=0; i<n; i++)
{
printf("%5d", a[i]);
}
printf("\n");
}
/* 函数功能:将数组a中的最大数与最小数位置互换 */
void MaxMinExchang(________, int n)
{
int maxValue = a[0], minValue = a[0], maxPos = 0, minPos = 0;
int i;
for (i=1; i maxValue)
{
maxValue = _______;
maxPos = ____;
}
if (a[i] < minValue)
{
minValue = a[i];
minPos = i;
}
}
Swap(________________);
}
/* 函数功能:两整数值互换 */
void Swap(int *x, int *y)
{
int ________;
temp = *x;
_________;
*y = temp;
}
#include
void MonthDay(int year, int yearDay, int *pMonth, int *pDay);
int dayTab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int main()
{
int year, month, day, yearDay;
printf("Please enter year, yearDay:");
scanf("%d,%d", &year, &yearDay);
_________________;
printf("month = %d, day = %d\n", month, day);
return 0;
}
/* 函数功能:对给定的某一年的第几天,计算它是这一年的第几月第几日 */
void MonthDay(int year, int yearDay, int *pMonth, int *pDay)
{
int i, leap;
leap = _________________________;
for (i=1; yearDay>dayTab[leap][i]; i++)
{
yearDay = ______________________;
}
______________; /* 将计算出的月份值赋值给pMonth所指向的变量 */
*pDay = yearDay; /* 将计算出的日号赋值给pDay所指向的变量 */
}
#include
int Fun(int *x,int *y)
{
if(___________) /*如果形参变量x所指的内存单元中的数据小于y所指的内存单元中的数据,则返回该最小值*/
return *x;
else
return *y;
}
int main()
{
int a=7,b=8,_______,r;
p=&a;
q=&b;
r=____________; /*调用子函数Fun,返回变量a和b中的最小值,将其存放到变量r中。*/
printf("%d,%d,%d\n",*p,*q,r);
return 0;
}
#include
int DayofYear(int year, int month, int day);
int dayTab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int main()
{
int year, month, day, yearDay;
printf("Please enter year, month, day:");
scanf("%d,%d,%d", &year, &month, &day);
yearDay = DayofYear(year, month, day);
printf("yearDay = %d\n", yearDay);
return 0;
}
/* 函数功能:对给定的某年某月某日,计算并返回它是这一年的第几天 */
int DayofYear(int year, int month, int day)
{
int i, leap;
leap = ________________________; /* 若year为闰年,即leap值为1,则用第1行元素dayTab[1][i]计算;
否则leap值为0,用第0行dayTab[0][i]计算 */
for (i=1; _______; i++)
{
day = ________________;
}
return day; /* 返回计算出的day的值 */
}
#include
void MonthDay(int year, int yearDay, int *pMonth, int *pDay);
int dayTab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int main()
{
int year, month, day, yearDay;
printf("Please enter year, yearDay:");
scanf("%d,%d", &year, &yearDay);
_________________;
printf("month = %d, day = %d\n", month, day);
return 0;
}
/* 函数功能:对给定的某一年的第几天,计算它是这一年的第几月第几日 */
void MonthDay(int year, int yearDay, int *pMonth, int *pDay)
{
int i, leap;
leap = _________________________;
for (i=1; yearDay>dayTab[leap][i]; i++)
{
yearDay = ______________________;
}
______________; /* 将计算出的月份值赋值给pMonth所指向的变量 */
*pDay = yearDay; /* 将计算出的日号赋值给pDay所指向的变量 */
}
#include
float Fun1(float x);
float Fun2(float x);
float Integral(float (*f)(float), float a, float b);
int main()
{
float y1, y2;
y1 = Integral(Fun1, 0.0, 1.0);
y2 = Integral(Fun2, 0.0, 3.0);
printf("y1=%f\ny2=%f\n", y1, y2);
return 0;
}
/* 函数功能:计算函数1+x*x的函数值 */
float Fun1(float x)
{
return 1 + x * x;
}
/* 函数功能:计算函数x/(1+x*x)的函数值 */
float Fun2(float x)
{
return x / (1 + x * x);
}
/* 函数功能:用梯形法计算函数的定积分 */
float Integral(float (*f)(float), float a, float b)
{
float s, h;
int n = 100, i;
s = __________;
h = __________;
for (i=1; i<n; i++)
{
s += __________;
}
return __________;
}
#include
int Fun(int *x,int *y)
{
if(___________) /*如果形参变量x所指的内存单元中的数据小于y所指的内存单元中的数据,则返回该最小值*/
return *x;
else
return *y;
}
int main()
{
int a=7,b=8,_______,r;
p=&a;
q=&b;
r=____________; /*调用子函数Fun,返回变量a和b中的最小值,将其存放到变量r中。*/
printf("%d,%d,%d\n",*p,*q,r);
return 0;
}