当前位置:首页 » 软件设计 » c语言程序与设计答案

c语言程序与设计答案

发布时间: 2020-12-01 17:21:38

A. c语言程序设计课后习题解答与实验指导

#include<stdio.h>
int max(int x,int y,int z)
{
int t;
t=x>y?x:y;
t=t>z?t:z;
return(t);
}
int min(int x ,int y,int z)
{
int t;
t=x<y?x:y;
t=t<z?t:z;
return(t);
}
int aver(int x ,int y,int z)
{
int t;
t=(x+y+z)/3;
return(t);
}
void main()
{ int x,y,z,a,b,c;
scanf("%d,%d,%d",&x,&y,&z);
a=(*max)(x,y,z);
b=(*min)(x,y,z);
c=(*aver)(x,y,z);
printf("%d,%d,%d\n",a,b,c);
}
建议改成:
#include<stdio.h>
int max(int x,int y,int z)
{
int t;
t=x>y?x:y;
t=t>z?t:z;
return(t);
}
int min(int x ,int y,int z)
{
int t;
t=x<y?x:y;
t=t<z?t:z;
return(t);
}
float aver(int x ,int y,int z)
{
int t;
t=(float)((x+y+z)/3.0);
return(t);
}
void main()
{ int x,y,z,a,b;float c;
scanf("%d,%d,%d",&x,&y,&z);
a=(*max)(x,y,z);
b=(*min)(x,y,z);
c=(*aver)(x,y,z);
printf("max=%d\nmin=%d\naver=%g\n",a,b,c);
}

B. c语言程序设计答案

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MAX_LEN 10
typedef struct _DATA_ {
int value;
_DATA_ *next;
}DATA;
void main()
{
int i;
char ch;
char str[MAX_LEN + 1];
DATA *pdata, *ptem, *ppre;
pdata = (DATA *)malloc(sizeof(DATA));
pdata->next = pdata;

// Input
while (1) {
for (i = 0; i < MAX_LEN; i++) {
ch = (char)getch();
printf("%c", ch);
if (ch == ' ')
break;
str[i] = ch;
}

i = atoi(str);
if (i == -1)
break;
ptem = (DATA *)malloc(sizeof(DATA));
ptem->value = i;

ptem->next = pdata->next;
pdata->next = ptem;
}

// Delete even numbers
ppre = pdata;
ptem = pdata->next;
while (ptem != pdata) {
if (ptem->value % 2 == 0) {
ppre->next = ptem->next;
free(ptem);
ptem = ppre->next;
} else {
ppre = ppre->next;
ptem = ptem->next;
}

}

// Output
printf("\n");
ptem = pdata->next;
while (ptem != pdata) {
printf("%d ", ptem->value);
ptem = ptem->next;
}
printf("\n");

}

C. C语言程序设计答案

#include<stdio.h>
voidmain(){
for(inti=0;i<21;i++)//公鸡
for(intj=0;j<34;j++)//母鸡
for(intk=0;k<301;k++)//小鸡
{
if((i+j+k)==100&&(5*i+3*j+k/3)==100&&k%3==0)
printf("公鸡%d,母鸡%d,小鸡%d ",i,j,k);
}
}

D. c语言程序与设计第四版143页123题

一、
int f(int x){return 3*x*x*x+2*x*x+5*x+1;}
main()
{
int a[]={1,2,12,15,25},i;
for(i=0;i<5;i++)printf("f(%d)=%d\n",i,f(i));
}

int min(int x,int y){return x<y?x:y;}
main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("三个数是:%d,%d,%d\n",a,b,c);
printf("最小数是:%d\n",min(min(a,b),c));
}

int fun(int n,int k)
{
while((k--)>1)
{
n/=10;
if(!n)return -1;
}
return n%10;
}
main()
{
int n,k;
scanf("%d%d",&n,&k);
if(fun(n,k)==-1)printf("k值大于专位数!属");
else printf("%d\n",fun( n,k));
}

热点内容
美发店认证 发布:2021-03-16 21:43:38 浏览:443
物业纠纷原因 发布:2021-03-16 21:42:46 浏览:474
全国著名不孕不育医院 发布:2021-03-16 21:42:24 浏览:679
知名明星确诊 发布:2021-03-16 21:42:04 浏览:14
ipad大专有用吗 发布:2021-03-16 21:40:58 浏览:670
公务员协议班值得吗 发布:2021-03-16 21:40:00 浏览:21
知名书店品牌 发布:2021-03-16 21:39:09 浏览:949
q雷授权码在哪里买 发布:2021-03-16 21:38:44 浏览:852
图书天猫转让 发布:2021-03-16 21:38:26 浏览:707
宝宝水杯品牌 发布:2021-03-16 21:35:56 浏览:837