c语言一个大程序,用基本语句,100句左右

c语言一个大程序,用基本语句,100句左右,第1张

# include "stdio.h"

# include "stdlib.h"

# include "string.h"

# define NULL 0

struct xiangcun

{

char num[4]//乡村的编号

char name[20] //村名

int people //总人数

int relieve//救济人数

float amount //救济总金袜链和额

struct xiangcun *next

}

struct jiating

{

char num[10] //乡村编号

char candidate[20] //身份z号码

char fname[20]//户主名字

char sex[2] //性别

int fpeople //家庭人数

float insert //年收入

int time //接受救助次数

struct jiating * next

}

struct out

{

char candidate[20]//户主身份z号码

char goodsname[20] //商品名字

char date[15]//发放日期

char unit[10] //单位

float price //单价

int count//发放数量

float money /唤正/金额

struct out *next

}

struct xiangcun *h1,*tail1

struct jiating *h2,*tail2

struct out *h3,*tail3

struct xiangcun * rebuilt1() //构建乡村链表

{

int n1=0

struct xiangcun *p1,*p2,*head

p1=p2=(struct xiangcun *)malloc(sizeof(struct xiangcun))

printf("\n\n\n\告盯n\n\n 请输入以下信息:\n 乡村的编号:\n 村名:\n 总人数:\n 救济人数:\n 就系总金额:\n")

scanf("%s%s%d%d%f",p1->num,p1->name,&p1->people,&p1->relieve,&p1->amount)

while(strcmp(p1->num,"0")!=0)

{

n1++

if(n1==1)

h1=p1

else

p2->next=p1

p2=p1

p1=(struct xiangcun *)malloc(sizeof(struct xiangcun))

scanf("%s%s%d%d%f",p1->num,p1->name,&p1->people,&p1->relieve,&p1->amount)

}

p2->next=NULL

return h1

}

struct jiating * rebuilt2() //构建家庭信息链表

{

int n2=0

struct jiating *p1,*p2,*head

p1=p2=(struct jiating *)malloc(sizeof(struct jiating))

printf("\n\n\n\n\n\n 请输入以下信息:\n乡村名字: \n户主身份z号码: \n 户主名字:\n 户主性别:\n 家庭人数:\n 年收入:\n 接受救助的次数:\n")

scanf("%s%s%s%s%d%f%d",p1->num,p1->candidate,p1->fname,p1->sex,&p1->fpeople,&p1->insert,&p1->time)

while(strcmp(p1->candidate,"0")!=0)

{

n2++

if(n2==1)

h2=p1

else

p2->next=p1

p2=p1

p1=(struct jiating *)malloc(sizeof(struct jiating))

scanf("%s%s%s%s%d%f%d",p1->num,p1->candidate,p1->fname,p1->sex,&p1->fpeople,&p1->insert,&p1->time)

}

p2->next=NULL

return h2

}

struct out * rebuilt3() //构建物资信息链表

{

struct out *p1, *p2,*head

int n3=0

p1=p2=(struct out *)malloc(sizeof(struct out))

printf("\n\n\n\n\n\n 请输入以下信息:\n 户主身份z号码:\n 商品名字:\n 发放日期:\n 单位:\n 单价:\n 发放数量:\n 金额:\n")

scanf("%s%s%s%s%f%d%f",p1->candidate,p1->goodsname,p1->date,p1->unit,&p1->price,&p1->count,&p1->money)

while(strcmp(p1->candidate,"0")!=0)

{

n3++

if(n3==1)

h3=p1

else

p2->next=p1

p2=p1

p1=(struct out *)malloc(sizeof(struct out))

scanf("%s%s%s%s%f%d%f",p1->candidate,p1->goodsname,p1->date,p1->unit,&p1->price,&p1->count,&p1->money)

}

p2->next=NULL

return h3

}

int change1(xiangcun *head1,char *num) //对乡村信息的修改

{

struct xiangcun *p

p=head1->next

printf("\n\n\n\n\n\n")

while(1)

{

if(p==NULL)

{

return 1

}

if(strstr(p->num,num))

{

printf(" 请重新输入要修改乡村的各项:")

scanf("%s%s%d%d%d",p->num,p->name,&p->people,&p->relieve,&p->amount)

return 1

}

p=p->next

}

}

int change2(jiating *head2,char *num) //对家庭信息的修改

{

struct jiating *p

p=head2->next

printf("\n\n\n\n\n\n")

while(1)

{

if(p==NULL)

{

return 1

}

if(strstr(p->fname,num))

{

printf(" 请重新输入要修改家庭的各项:")

scanf("%s%s%s%s%d%f%d",p->num,p->candidate,p->fname,p->sex,&p->fpeople,&p->insert,&p->time)

return 1

}

p=p->next

}

}

int change3(out *head3,char *name) //对物资信息的修改

{

struct out *p

p=head3->next

printf("\n\n\n\n\n\n")

while(1)

{

if(p==NULL)

{

return 1

}

if(strstr(p->goodsname,name))

{

printf(" 请重新输入要修改物资的各项:")

scanf("%s%s%s%s%f%d%f",p->candidate,p->goodsname,p->date,p->unit,&p->price,&p->count,&p->money)

return 1

}

p=p->next

}

}

void Csearch(xiangcun* head1) /* 查询全部乡村中每个村的救济总户数*/

{

struct xiangcun *p

p=head1->next

printf("\n\n\n\n\n\n")

if(p==NULL)

{

printf(" 全乡没有被救济的人!\n")

return

}

while(p!=NULL)

{

printf(" %s救济人数为:%d\n",p->name,p->relieve)

p=p->next

}

return

}

int Esearch(xiangcun * head1,char *name) /*查询全部乡村中某个村的村救济总金额*/

{

struct xiangcun *p

p=head1->next

while(1)

{

if(p==NULL)

{

return 0

}

if(strstr(p->name,name))

{

printf("\n\n\n\n\n\n %s的受救济总金额是:%g\n",p->name,p->amount)

return 1

}

p=p->next

}

}

int Fsearch(jiating* head2,char * name) /*查询某救济户 (如:张三)基本信息*/

{

struct jiating *p

p=head2->next

while(1)

{

if(p==NULL)

{

return 0

}

if(strstr(p->fname,name))

{

printf("\n\n\n\n\n\n 户主的乡村编号:%s\n 户主的身份z号码:%s\n",p->num,p->candidate)

printf(" 户主名字是:%s\n 户主性别是:%s\n",p->fname,p->sex)

printf(" 家庭人数:%d\n 年收入:%g\n /接受救助次数:d\n",p->fpeople,p->insert,p->time)

return 1

}

p=p->next

}

}int frelieve(jiating *head2,out *head3,char * name)/*查询某救济户 (如:张三)救济户物资发放的全部信息*/

{

struct jiating * p

p=head2->next

while(1)

{

if(p==NULL)

{

return 0

}

if(strstr(p->fname,name))

{

struct out *p1

p1=head3->next

printf("\n\n\n\n\n\n %s的物资信息:\n",p->fname)

while(1)

{

if(p1==NULL)

{

return 1

}

if(strstr(p->candidate,p1->candidate))

{

printf("物资名字:%s\n发放日期:%s\n物资的量的单位:%s\n",p1->goodsname,p1->date,p1->unit)

printf("物资单价:%g\n 发放数量:%d\n发放金额:%g\n",p1->price,p1->count,p1->money)

}

p1=p1->next

}

}

p=p->next

}

}

int Relieve(jiating * head2,out *head3,char * name,char *name2)/*查询某救济户 (如:张三)是否发放了某种救济物资 (如:矿泉水)的信息*/

{

struct jiating * p

p=head2->next

while(1)

{

if(p==NULL)

{

return 0

}

if(strstr(p->fname,name))

{

out *p1

p1=head3->next

while (1)

{

if(strstr(p->candidate,p1->candidate)&&strstr(p1->goodsname,name2))

{

return 1

}

p1=p1->next

if(p1==NULL)

{

return 0

}

}

}

p=p->next

}

}

void tprint(xiangcun * head1)/*统计并输出全乡的人口总数、救济总户数、救济总金额*/

{

int peo_sum=0,re_sum=0

float re_cost=0

xiangcun *p=h1

while(p!=NULL)

{

peo_sum+=p->people

re_sum+=p->relieve

re_cost+=p->amount

p=p->next

}

printf("\n\n\n\n\n\n 人口总数:%d\n 救济总户数:%d\n救济总金额:%g\n",peo_sum,re_sum,re_cost)

}

这个超大数不是10的100次方个数,而是一个数,只不过有100位,那么我们会用一个整型的历携数据存储,但没有相应的整型类型能存放这么大的数。

问题是:

-如果你肢敬伏想保留这个数,那么用一个字符串数组来存储每一位上的数字是可以的。

-你想计算是否能被3整除,那么你可以利用一个数学定理来完成这个计算,无需大内存,只要一小段程序即可,即:一个数能被3整除,那么这个数的每位上的数字的和能被3整除,比如12的两位数字之和是3,3能被3整除,那么12也能,21一样也能210,21000,同理都可以。那么你的计算就无需等待这个数都输入后再开始,而可以从每一位刚输入时就可以了。见下面程序:

int n,b,c=0,jchar a[101]

scanf("%d",&n)

for ( j=0j<nj++ )

{ do { b=getchar()} while ( !(b>='0' &&b<='9') )//保证输入一位数字,稿基输入整个大数后回车即可

a[j]=(b-'0')c+=a[j]//将输入的字符转换成数字,加到累加和上

}

if ( c%3 ) printf("No\n")else printf("Yes\n")

修改如下:早谨

#include<stdio.h>猜睁兆

int max(int a,int b)

{

int t

if(a>b)

t=a

else

t=b

return t

}

int main()

{

int a[10]

int i

int n

printf("请输入10个数字: \n")

scanf("%d",&a[0])

n=a[0]

for(i=1i<10i++)

{

scanf("%d",&a[i])

n=max(n,a[i])

}

printf("最大穗租:%d",n)

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12287377.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存