作业帮 > 综合 > 作业

1)编写一个C语言程序,输入a、b、c 3个值,输入其中最大者,要求在子函数里面比较数大

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 17:11:53
1)编写一个C语言程序,输入a、b、c 3个值,输入其中最大者,要求在子函数里面比较数大
2)编程输入三角形的三边长,计算并输出三角形面积和周长(可以只计算周长).
3)编写一个函数用冒泡法对10个整数由小到大顺序排列,用数组名作为实参.
哥哥姐姐~小弟真的很需要帮助
/* 1.输入a、b、c 3个值,输出其中最大者,要求在子函数里面比较数大 */
#include
int mycmp(int a,int b,int c)
{
\x05int max = a;
\x05if(max < b) max = b;
\x05if(max < c) max = c;
\x05return max;
}
int main()
{
\x05int x1,x2,x3,max;
\x05printf("Please input x1 x2 and x3:\n");
\x05scanf("%d %d %d",&x1,&x2,&x3);
\x05mycmp(x1,x2,x3);
\x05max = mycmp(x1,x2,x3);
\x05printf("max = %d\n",max);
\x05return 0;
}
/* 2.编程输入三角形的三边长,计算并输出三角形面积和周长(可以只计算周长).*/
#include
#include
double sum,area; //周长:sum,面积:area
void mycount(double a,double b,double c)
{
\x05double p;
\x05sum = a + b + c;
\x05//面积:海伦公式
\x05p = sum/2;
\x05area = sqrt(p*(p-a)*(p-b)*(p-c));
}
int main()
{
\x05double x1,x2,x3;
\x05printf("Please input x1 x2 and x3:\n");
\x05scanf("%lf %lf %lf",&x1,&x2,&x3);
\x05mycount(x1,x2,x3);
\x05printf("周长 = %f,面积 = %f\n",sum,area);
\x05return 0;
}
/* 3.编写一个函数用冒泡法对10个整数由小到大顺序排列,用数组名作为实参 */
// 楼主注意啦,有些回答不是冒泡排序,而是简单选择排序,如 yumao121
// 当本身是从小到大排序的时候,倒霉熊lujin 解答要遍历n-1趟,其实只要遍历一趟
#include
#include
double sum,area; //周长:sum,面积:area
void swap(int *a,int *b)
{
\x05int temp;
\x05temp = *a;
\x05*a = *b;
\x05*b = temp;
}
void BubbleSort(int A[],int n)
{
\x05int i,j,last; //last:记录最近被修改的记录
\x05i = n - 1;
\x05while( i>0 )
\x05{
\x05\x05last = 0;
\x05\x05for(j = 0; j < i; j++)
\x05\x05{
\x05\x05\x05if(A[j+1] < A[j])
\x05\x05\x05{
\x05\x05\x05\x05swap(&A[j],&A[j+1]);
\x05\x05\x05\x05last = j;
\x05\x05\x05}
\x05\x05}
\x05\x05i = last;
\x05}
}
int main()
{
\x05int i,B[10];
\x05printf("please enter 10 nums:\n");
\x05for(i = 0;i < 10;i++)
\x05{
\x05\x05scanf("%d",&B[i]);
\x05}
\x05BubbleSort(B,10);
\x05printf("sort:\n");
\x05for(i = 0;i < 10;i++)
\x05{
\x05\x05printf("%d ",B[i]);
\x05}
\x05printf("\n");
\x05return 0;
}