急求 3道c语言编程题

1,比较三数之中最大值并输出结果要求:1.提示用户输入三个数2.若不是数字则提示“Dataerror!Pleasetryagain!”3.输出结果采用“Themaxnum... 1,比较三数之中最大值并输出结果
要求:1.提示用户输入三个数
2.若不是数字则提示“Data error!Please try again!”
3.输出结果采用“The max number is :”格式
2,某学校宿舍管理处要求一宿舍分配方案程序
要求:1.6人一间
2.假设性别相同
3.输出结果
3,求出1-1000以内的素数
要求:每行显示5个数据
第二题的意思是输入人数,输出结果需要分配几间宿舍。
展开
 我来答
handsomeIven
2010-06-21 · TA获得超过171个赞
知道小有建树答主
回答量:131
采纳率:0%
帮助的人:148万
展开全部
第一道:(太晚了,困了,没时间写注释,不好意思)
#include<stdio.h>
#include<string.h>
#include<math.h>

int compare(int *a,int n)
{
int temp;
if(a[0]>a[1])
temp=a[0];
else
temp=a[1];
if(temp<a[2])
temp=a[2];
return temp;
}//compare

void main()
{
int a[3];
char str[3][10];
char *p;
int i,j,count;
printf("Please input the data.\n");
for( i=0;i<3;i++)
{
gets(str[i]);
p=str[i];
while(*p!='\0')
{
if(*p>='0'&&*p<='9')
p++;
else
{
printf("Data error!Please try again!\n");
i--;
break;
}//else
}//while

}//for
for( i=0;i<3;i++)
{
puts(str[i]);
count=0;
for(j=0;j<strlen(str[i]);j++)
{
count*=10;
count=count+(int)str[i][j]-48; //减去48是把字符型的ASCII码转换成本身代表的整数
}//for
a[i]=count;
}//for
printf("The max number is:%d.\n",compare(a,3));
}//main
第二道条件太少,不知道楼主到底想怎样的分寝室。
第三道:
#include<stdio.h>

void main()
{
int i,j,count,m=0;
for(i=2;i<=1000;i++)//1不是素数
{
count=0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{ count++;
break;
}
}//for
if(count==0)
{ printf("%d\t",i);
m++;
}//if
if(m==5)
{
printf("\n");
m=0;
}//if
}//for
}//main

补充:(时间匆忙,没时间编译。)
#include<stdio.h>
void main()
{
int person;
printf("Please input the number of person!");
scanf("%d",&person);
if(person%6==0)
printf("The number of dormitory is %d",person/6);
else
printf("The number of dormitory is %d",person/6+1);
}//main
栩箭
2010-06-20 · TA获得超过5310个赞
知道大有可为答主
回答量:3036
采纳率:0%
帮助的人:1606万
展开全部
2的条件太少
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
mike4o50
2010-06-21 · 超过20用户采纳过TA的回答
知道答主
回答量:98
采纳率:0%
帮助的人:53.7万
展开全部
1:if(a>b)
max=a;
else
max=b;
if(c>max)
max=c;
cout<<max;
2.同楼上
3.for(i=2;i<10000;i++)
{ for(j=2;j<sqrt(i);j++)
{ if(i%j==0)
break;
}
if(j>sqrt(i))
continue;
else
cout<<i;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
时评局
2010-06-21 · TA获得超过135个赞
知道答主
回答量:43
采纳率:0%
帮助的人:14.4万
展开全部
这个~~~~~~~这是选修老师出的原题~敢问楼主也是农大的???
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式