急求一C语言编程题答案!!!!!

2024-11-24 03:58:05
推荐回答(3个)
回答1:

# include /*程序从函数main开始执行*/
int main()
{
int interger1,interger2,interger3,Sum,Average,product;
printf( "Input three different intergers\n" );
scanf( "%d%d%d",&interger1,&interger2,&interger3 );
Sum = interger1 + interger2 + interger3;
printf( "Sum is %d\n",Sum );
Average = ( interger1 + interger2 + interger3 ) / 3;
printf( "Average is %d\n",Average );
Product = interger1 * interger2 * interger3;
printf( "Product is %d\n",Product );
if ( interger1 > interger2 && interger2 > interger3 )
{
printf( "Smallest is %d\n",interger3 );
printf( "Largest is %d\n",interger1 );
}
if ( interger2 > interger3 && interger3 > interger1 )
{
printf( "Smallest is %d\n",interger1 );
printf( "Largest is %d\n",interger2 );
}
if ( interger3 > interger2 && interger2 > interger1 )
{
printf( "Smallest is %d\n",interger1 );
printf( "Largest is %d\n",interger3 );
}
if ( interger1 > interger3 && interger3 > interger2 )
{
printf( "Smallest is %d\n",interger2 );
printf( "Largest is %d\n",interger1 );
}
if ( interger2 > interger1 && interger1 > interger3 )
{
printf( "Smallest is %d\n",interger3);
printf( "Largest is %d\n",interger2 );
}
if ( interger3 > interger1 && interger1 > interger2 )
{ printf( "Smallest is %d\n",interger2 );
printf( "Largest is %d\n",interger3 );
}
return 0;
}

回答2:

/*程序已测试过,复制粘贴应该就可以跑;4的问题可能要用直接插入排序,这里偷懒,依然用冒泡排了*/

#include

int sort(int *a, int num) //冒泡
{
int i = 0;
int j = 0;
int tmp = 0;

for(i = 0; i < num; i++)
{
for(j = 1; j < num; j++)
{
if(a[j-1] < a[j])
{
tmp = a[j-1];
a[j-1] = a[j];
a[j] = tmp;
}
}
}
return 0;
}

int reverse(int *a, int num) //反转
{
int i = 0;
int tmp = 0;

for(i = 0; i < num/2; i++)
{
tmp = a[i];
a[i] = a[num-1-i];
a[num-1-i] = tmp;
}
return 0;
}

int main(int argc, char* argv[])
{
int a[11] = {0};
int i = 0;

//input
for(i = 0; i < 10; i++)
{
scanf("%d",&a[i]);
}

//sort
sort(a,10);

//output
for(i = 0; i < 10; i++)
{
printf("[%d]",a[i]);
}

printf("\n");

//insert
scanf("%d",&a[10]);

printf("\n");

//sort
sort(a,11);

//output
for(i = 0; i < 11; i++)
{
printf("[%d]",a[i]);
}

//reverse
reverse(a,11);

printf("\n");

//output
for(i = 0; i < 11; i++)
{
printf("[%d]",a[i]);
}

printf("\n");

return 0;
}
}

回答3:

加分我给你程序