当前位置:首页 > 网站源码 > 正文内容

初学c编程100个代码大全(简单c编程代码)

网站源码2年前 (2023-02-08)514

本篇文章给大家谈谈初学c编程100个代码大全,以及简单c编程代码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

C语言简单代码

如果你想知道为什么会出现7253的话...

从代码上一行行看下来,当你看到c=a+b; 时,你还没输入哦,这时a和b是多少呢?

不知道,计算机也不知道,于是,给了一个随机数(当然,说是随机数应该不准确,只是内存里分别分配给a和b的各两个字节空间里原有的值.是别的程序运行后留下的,这个值可不确定啊,很可怕的一件事...)

把c=a+b;放到scanf("%d,%d",a,b);后面,那么,当你输入之后才去运行加法,这时a和b的值就是你输入的值了...这样才能输出正确的加法结果...

求简单C语言程序代码!

输入2个正整数m和n,求其最大公约数和最小公倍数

#include

#include

int main()

int m,n,p,q,s,r;

printf("请输入两个正整数;m,n\n");

scanf("%d,%d",m,n);

#includestdio.h

main()

int a,b,t=0;

scanf("%d %d",a,b);

if (ab)

printf("%d %d %d %d %d",(a+b),(a-b),(a/b),(a*b),(a%b));

}

主要特点

C语言是一种结构化语言,它有着清晰的层次,可按照模块的方式对程序进行编写,十分有利于程序的调试,且c语言的处理和表现能力都非常的强大,依靠非常全面的运算符和多样的数据类型,可以轻易完成各种数据结构的构建,通过指针类型更可对内存直接寻址以及对硬件进行直接操作,因此既能够用于开发系统程序,也可用于开发应用软件。

以上内容参考:百度百科-c语言

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

# 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]; //身份证号码

char fname[20]; //户主名字

char sex[2]; //性别

int fpeople; //家庭人数

float insert; //年收入

int time; //接受救助次数

struct jiating * next;

};

struct out

{

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

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 户主身份证号码: \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 户主身份证号码:\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 户主的身份证号码:%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);

}

速度求个100行的C语言编程,不限内容~

我给你发了一个word,我的留言是“影子加油”

例如一个题目是:

题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存。输入的字符串以!结束。

1.程序分析:

2.程序源代码:

#i nclude "stdio.h"

main()

{FILE *fp;

char str[100],filename[10];

int i=0;

if((fp=fopen("test","w"))==NULL)

{ printf("cannot open the file\n");

exit(0);}

printf("please input a string:\n");

gets(str);

while(str[i]!='!')

{ if(str[i]='a'str[i]='z')

str[i]=str[i]-32;

fputc(str[i],fp);

i++;}

fclose(fp);

fp=fopen("test","r");

fgets(str,strlen(str)+1,fp);

printf("%s\n",str);

fclose(fp);

}

c语言编程代码

两种方法我写在一起,可以独立拆开。

#include stdio.h

void finda1(char a[3][10]);

void finda2(char a[3][10]);

void show(char (*p)[10]);

int main()

{

  char a[3][10]={{"gehajl"},{"788a987a7"},{"ccabbbabbb"}};

  printf("原数组内容:\n");

  show(a);

  printf("\n1、用数组指针的方法(函数finda1):\n");

  finda1(a);

  printf("执行后:\n");

  show(a);

  printf("\n---------------------\n");

  char b[3][10]={{"gehajl"},{"788a987a7"},{"ccabbbabbb"}};

  printf("原数组内容:\n");

  show(a);

  printf("\n2、用指针数组的方法(函数finda2):\n");

  finda2(b);

  printf("执行后:\n");

  show(b);

  return 0;

}

void finda1(char a[3][10])

{

  int i,j;

  char (*p)[10]=a;

  for(i=0;i3;i++)

      for(j=0;j10;j++)

          if(p[i][j]=='a')

              printf("发现:第%d行第%d个元素是‘a’,已替换\n",i+1,j+1),p[i][j]='1';

}

void finda2(char a[3][10])

{

  int i,j;

  char *p[3]={a[0][0],a[1][0],a[2][0]};

  for(i=0;i3;i++)

      for(j=0;j10;j++)

          if(p[i][j]=='a')

              printf("发现:第%d行第%d个元素是‘a’,已替换\n",i+1,j+1),p[i][j]='1';

}

void show(char (*p)[10])

{

  int i,j;

  for(i=0;i3;i++,printf("\n"))

      for(j=0;j10;j++)

          printf("%c ",p[i][j]);

}

初学c编程100个代码大全的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于简单c编程代码、初学c编程100个代码大全的信息别忘了在本站进行查找喔。

扫描二维码推送至手机访问。

版权声明:本文由我的模板布,如需转载请注明出处。


本文链接:http://2565999.com/post/3156.html

分享给朋友:

“初学c编程100个代码大全(简单c编程代码)” 的相关文章

中国药品电子监管码查询官网(中国药品电子监管码查询官网下载)

中国药品电子监管码查询官网(中国药品电子监管码查询官网下载)

今天给各位分享中国药品电子监管码查询官网的知识,其中也会对中国药品电子监管码查询官网下载进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、中国药品电子监管码查询...

php模板引擎的功能(php模板引擎的功能有哪些)

php模板引擎的功能(php模板引擎的功能有哪些)

今天给各位分享php模板引擎的功能的知识,其中也会对php模板引擎的功能有哪些进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、PHP引擎程序是什么? 2、...

电脑装了谷歌浏览器不能访问网页(电脑装了谷歌浏览器不能访问网页了)

电脑装了谷歌浏览器不能访问网页(电脑装了谷歌浏览器不能访问网页了)

今天给各位分享电脑装了谷歌浏览器不能访问网页的知识,其中也会对电脑装了谷歌浏览器不能访问网页了进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、谷歌浏览器网页打...

真人打扑克牌的网站不用下载(扑克真人打牌真实视频)

真人打扑克牌的网站不用下载(扑克真人打牌真实视频)

本篇文章给大家谈谈真人打扑克牌的网站不用下载,以及扑克真人打牌真实视频对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。 本文目录一览: 1、小游戏三张扑克牌无需网络怎么下载? 2、四人扑克打...

网页设计表单左对齐代码(html表单左对齐)

网页设计表单左对齐代码(html表单左对齐)

今天给各位分享网页设计表单左对齐代码的知识,其中也会对html表单左对齐进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、急求!!!网页设计 HTML代码大全...

php文件打开显示源码(php文件打开显示源码错误)

php文件打开显示源码(php文件打开显示源码错误)

今天给各位分享php文件打开显示源码的知识,其中也会对php文件打开显示源码错误进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、PHP文件执行时显示源代码...