当前位置: 代码迷 >> C语言 >> [求助] 补充程序完整
  详细解决方案

[求助] 补充程序完整

热度:117   发布时间:2007-01-07 19:27:21.0
[求助] 补充程序完整

请大家帮忙补充一下这四个程序

小女不胜感激啊

谢谢啊!!^^

祝大家开心!

1、以下程序求a数组中所有素数之和,函数isprime用来判断自变量是否为素数,素数x是能被1和它本身整除大于1的自然数。请补充完整程序

#include "____①________"
main()
{int i, a[____②___],*p=a, sum=____③______;
Printf("Enter 10 num:\n");
for(i=0; i<10; i++) scanf("%d",___④_____);
if(isprime(*(p+____⑤_____))==1)

{ printf("&d",*(a+i));
sum+=*(a+i);
}
printf("\n The sum=%d\n",__⑥___);
}
isprime(int x)
{ int___⑦_____;
for(i=2;___⑧_____;i++)
if(x%i==0) return(0);
if(x>1) return(1);
else return(0);
}


⑵以下程序为结构数组接收10个人的姓名、年龄和性别。然后输出,请补充完整程序

Struc man
{_①___name[20];
unsigned age;
char sex[7];
};
main()
{___②__person[10];
data_in(person);
data_out(__③____);
}
data_in(p)
Struct map *p;
{ struct man *q=__④______;
for(;p<q;p++)
{Printf("age;sex;name");
scanf("%u%s",p→age,p→sex);
___⑤____;
}
}
data_out(p)
__⑥_____*p;
{Struct man *q=___⑦___;
for(;p<q;p++)
Printf("%s;%u;__⑧____\n",p→age,p→sex);
}


⑶以下程序对10个字符串由小到大的顺序排列。main函数对字符串赋初值并输出排序结果。(其中strcmp(srt1,srt2)为字符串比较函数;若srt1<srt2 则函数值为一负数;若srt1=srt2 则函数值为0;若srt1>srt2 则函数值为一正数)

#include "stdio.h"
main()
{void sort(char *s[],int n);
char *str[10]={"java","prolog","pl","lisp","logo","VB","fortran","cobol","pascal","c++"};
int i;
sort(__①____);
Printf("new seguence of strigs is:\n");
for(___②___;___③___;___④________)
Printf("%s\n",str[i]);
}
Void sort(char *s[],int n)
{char *temp;
int i,j;
for(i=0;i<n;i++)
for(i=0;j<n;j++)
if(strcmp(s[i],s[j])<0)
{_⑤___=s[i];
__⑥__=__⑦__;
s[j]=__⑧__;}
}


⑷以下f函数功能是:在带有头结点单向链表中,查找结点数据域的最大值作为函数返回值
Struct book
Struct book
{int a;
__①___*next;
}
int f(struct book *pl)
{___②___*p2;
p2=p1→next
m=p2→a;
for(p2=p2→next;p2!='\0';p2=__③___)
if(___④____)m=p2→a;
return__⑤___;
}

搜索更多相关的解决方案: 开心  不胜感激  Enter  

----------------解决方案--------------------------------------------------------

(1) 1、 stdio.h 2、10 3、0 4、&a[i] 5、i 6、sum 7、i 8、i<x


----------------解决方案--------------------------------------------------------
#include "stdio.h"
main()
{void sort(char *s[],int n);
char *str[10]={"java","prolog","pl","lisp","logo","VB","fortran","cobol","pascal","c++"};
int i;
sort(str,10);
printf("new seguence of strigs is:\n");
for(i=0;i<10;i++)
printf("%s\n",str[i]);
}

void sort(char *s[],int n)
{char *temp;
int i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(strcmp(s[i],s[j])<0)
{temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
----------------解决方案--------------------------------------------------------

struct book
{int a;
struct book *next;
}
int f(struct book *pl)
{struct book *p2;
p2=p1→next
m=p2→a;
for(p2=p2→next;p2!='\0';p2=p2->next)
if(p2->a>m)m=p2→a;
return m;
}

----------------解决方案--------------------------------------------------------

对于程序1:
#include "stdio.h"
#include "math.h"
main()
{int i, a[10],*p=a, sum=0;
Printf("Enter 10 num:\n");
for(i=0; i<10; i++) scanf("%d",a+i);
if(isprime(*(p+i))==1)

{ printf("&d",*(a+i));
sum+=*(a+i);
}
printf("\n The sum=%d\n",sum);
}
isprime(int x)
{ int i;
for(i=2;i<=(int) sqrt(x);i++)
if(x%i==0) return(0);
if(x>1) return(1);
else return(0);
}


----------------解决方案--------------------------------------------------------
谢谢大家的帮助啊!
----------------解决方案--------------------------------------------------------
  相关解决方案