c语⾔程序代码分享,⼀些简单的C语⾔程序代码(最新整理)《⼀些简单的C语⾔程序代码(最新整理)》由会员分享,可在线阅读,更多相关《⼀些简单的C语⾔程序代码(最新整理)(17页珍藏版)》请在⼈⼈⽂库⽹上搜索。
1、由键盘任意输⼊ 1 个 4 位数整数,分别输出其中的个位、⼗位、百位、千位。/* expe 3-10 */ #include #include void
main(void)int mun,a,b,c,d;scanf(%d,&mun);a=mun / 1000;/*千位*/ b=(mun % 1000) / 100;/*百位*/c=(mun % 100) / 10;/*⼗位*/d=(mun % 10);/*个位*/ printf(千位数字为=%dn,a);printf(百位数字为=%dn,b); printf(⼗位数字为=%dn,c); printf(个位数字为=%dn,d);由键盘任意输⼊ 。
2、3 个数据,出其中的最⼤数和最⼩数。#include void main(void)float a,b,c,k,g;/* k ⼩ g ⼤*/ printf (请输⼊三个
数);scanf(%f%f%f,&a,&b,&c); if (a c)/*最⼤*/printf (n 最⼤的数=%5.2f,g); elseprintf (n 最⼤的数=%5.2f,c);判断三⾓形的形状
#include #include void main(void)printf(请输⼊三⾓形三边);float a,b,c,p,s,k1,k2,k3;scanf(%f%f%f,&a,&b,&c);while (a + b vo。
3、id main(void)int i,j;for (i = 1;i void main(void)int i,j;for (i = 1;i void main(void)int i,j;for (i = 1;i void main(void)int i,j,k;for (i = 1;i = 0;i -)for (j = 4 - i;j 0;j -)printf( ! ); for (k = 2 * i ;k = 0;k -) printf( * );printf(n); 回⽂#include #includevoid main(void)char str80;int i,j,iStrlens。
4、tr,iFlag; printf(请输⼊字符串n); gets(str);iStrlenstr = strlen(str);for (i = 0 ,j = iStrlenstr - 1;i void main(void)char
str1080,a80,*p10,*q = NULL; int i, j,iFlag = 0;/int istrlenstr;printf(请输⼊名字n); for ( i = 0 ; i int main(void)int a10,*p = NULL ,iTem; int i,j,iPos = 0;printf(请输⼊ 10 个数n); for (i = 0; i 。
5、#includevoid main(void)char a1010,cTemp10; int i,j,iMax;printf(输⼊⼗个学⽣姓名:n); for(i = 0; i int main()char str80,*p = NULL,*q; char t;printf(请输⼊字符串:n); gets(str);printf(请输⼊想要删除的字符:n); t = getchar();p = str; q = str;for (p = str; *p != 0; p +)if (*p != t)*q+ = *p; *q = 0;puts(str);函数作业(全部)/*交换器,引⽤全局变量*/。
6、⽅法⼀int a,b;void main(void)scanf(%d%d,&a,&b); fun(); printf(a=%d,b=%dn,a,b);void fun(void)int c; c = a; a = b; b = c;⽅法⼆#include#define swap(x,y) int tmp=x;x=y;y=tmp; int main()int x,y;printf(请输⼊两个数字n); scanf(%d%d,&x,&y);
swap(x,y);printf(交换之后的数字是n); printf(%dt%dt,x,y);return 0;/*⽤函数最⼤公约数*/ #include。
7、int maxd(int,int); int main()int a,b,d;printf(请输⼊两个整数n); scanf(%d%d,&a,&b);d = maxd(a,b);printf(这两个数的最⼤公约数为:%d,d); return 0;int maxd(int a,int b)int m,n,k; if(a= 0 & *p /*⽤函数统计*/#includevoid iSort (int,int);t = xi;xi =
xiPos;#includeint main()xiPos = t; int icount(char* );int main()int a10;/*⽤函数素数*。
基础c语言代码8、/char str80;int i;printf(请输⼊ 10 个整数n);#includeint iPrime(int);int m = 0;printf(请输⼊字符串n);for (i = 0; i int
iChange(char*); int main()char s10; int i,k;printf(请输⼊⼀个⼋进制的数); gets(s);k = iChange(s);printf(对应的⼗进制的数位
=%d,k);int iChange(char *x)char *p; int n = 0; p = x;for(;*p != 0; p +)n = n * 8 + *p - 0; 。
9、/*⽤函数将矩阵转置规 定 是 ⽅ 阵 */ #include void change(int4); int main()int a44,b44=0;int i,j;printf(请输⼊⼀个四阶矩阵n); for (i = 0; i int dui(int4); int main()int a44,i,j,k = 0;printf(请输⼊⼀个四阶矩阵n); for (i = 0; i #includefloat icos(float); float
isin(float); int main()dot *= (-1) * a * a / (n *( n - 1); k += t;n += 2;。
10、while (fabs(t) = 1e-6); fcos = 1 + k;return fcos;float isin(float a)while (fabs(t) = 1e-6); fsin =1 + k;return fsin;*/*⽤函数分别统计 26 个字母的个数*/ #includevoid jishu(char str); int iCount126 = 0; void main(void)char str80;int i;printf(请输⼊字符串); gets(str);jishu(str);printf(26 个⼤写字母的个数分别是n); for (i = 0; i void。
11、 main(void)int a,n;printf(请输⼊⼀个整数:n); scanf(%d,&a);dst = 0;/加密后code = 1234;/密码printf(请输⼊明⽂:n);
scanf(%d,&stc);dst = stc code;printf(n 加密之后的⽂件是:%dn,dst); return 0;void jishu(char x)int i;for (i = 0; xi != 0; i +)if (xi = A & xi 0)/*偶数为清零*/ #include void main(void)int a;printf(请输⼊);位运算iCount1xi - A +;。
12、a = (a n) | (a void main(void)unsigned int x;printf(请输⼊数据:); scanf(%d,&x);x = x 0X00ff; printf(%xn,x);a = (a (8 * sizeof(int) - (- n);/左移printf(%un,a);/*利⽤位异或运算加密*/ #includeint main()int stc,code,dst;/*⼗六进制转⼆进制*/
#includevoid main(void)int a,b32,c = 1,i;scanf(%x,&a); for(i = 0; i i; c = 0; i -) prin。
13、tf(%d,bi); 员⼯⼯资#include #define N1 struct manlong ch;char nam10; intyear; float fareJB; float
fareYJ; float fareYF; float fareBX; float fareSD; float fareSF;void fare(struct man *p)struct man *q; for(q=p;qfareYF=p-fareJB+p-fareYJ;q-
fareSF=q-fareYF-q-fareBX-q-fareSD;for(q=p;qfareYF,q-fareSF); void PR。
14、INTF(struct man *p)struct man *q=p;printf(职⼯⼯号t 姓名t 年龄t 基本⼯资t 业绩⼯资t 应发⼯资t 保险费tt ⽔电费t 实发⼯资tn); for(q=p;qch,q-nam,q-year,q-fareJB,q-fareYJ,q-fareYF,q-fareBX,q-fareSD,q-fareSF);void main(void)struct man personN,*per; printf(输⼊员⼯信息);for(per=person;pernam); scanf(%d%d%f%f%f%f,&per-ch,&per-year,&per-fareJ。
15、B,&per-fareYJ,&per-fareBX,&per-fareSD);fare(person); PRINTF(person);部门销售情况管理程序#include #define N 1struct bumenlong num;char name20; float get4; float ave;aN;void chazhao(struct bumen *p)long NUM; int i;printf(输⼊要查的部门的代码:); scanf(%ld,&NUM);printf(n); for(i=0;inum=NUM)break;printf(部门代码t 部门名称t 春季销售额t 。
16、夏季销售额t 秋季销售额t 冬季销售额t 平均值n);printf(%ldt%6stt%8.2lft%8.2lft%8.2lft%8.2lft%8.2lftn ,p-num,p-name,p-
get0,p-get1,p-get2,p-get3,p-ave);void qiuave(struct bumen *p)int i,j;float sum=0; for(i=0;iave)
min=&pj;P=pi;pi=*min;*min=P;printf(部门代码t 部门名称t 春季销售额t 夏季销售额t 秋季销售额t 冬季销售额t 平均值n);for(k=0;k
#include#define S。
17、IZE sizeof(struct Note) struct Noteint value;num = Creatlist(); while (1)printf(1.统计n2.查n3.插⼊n4.删除n5.打印n6.退出n 请输⼊以选择:n); scanf(%d,&a);if (a = 1)k = Traverlist(num);printf(整型数据的个数是:%dn,k);m =Deletelist(num , iDelete); if (m = 0)printf(删除成功n);elseprintf(删除失败n);if (a = 5)void Printlist(num); if (a = 6。
18、)exit(1);struct Note *pNext;/*原型声明*/struct Note * Creatlist(void); int Traverlist(struct Note * );int searchlist(struct
Note * ,int); int Deletelist(struct Note *,int); void Printlist(struct Note * );/*-主函数*/void main(void)int a,k,l,m;int iFound,iDelete; struct Note *num;if (a = 2)printf(请输⼊想要查的数:)。
19、; scanf(%d,&iFound);l = searchlist(num,iFound); if (l = 1)printf(404 NOT FOUNDn);if (a = 3)printf(404 NOT FOUNDn); if
(a = 4)printf(请输⼊想删除的项⽬); scanf(%d,iDelete);/*-主函数到此结束*/struct Note * Creatlist(void)/
建⽴链表struct Note
*spHead,*spPre,*spCur; int a;spPre = (struct Note *)malloc(SIZE); spHead = spPre。
20、;spHead - pNext = NULL; doscanf(%d,&a); if (a != 0)spCur = (struct Note *)malloc(SIZE);spCur - value = a; spCur -pNext = NULL; spPre - pNext = spCur; spPre = spCur;value != x)spCur = spCur - pNext; if (spCur - value = x)printf(THE NUMBER IS %d,spCur - value);struct Note *spCur; spCur = sp - pNext;p。
21、rintf(链表中的整型数据为:/n); while (spCur != NULL)while(a != 0);/以输⼊ 0 作为结束return spHead;elsereturn
0;printf(%dn,spCur - value); spCur = spCur - pNext;int Traverlist(struct Note * sp)/统计struct Note *spCur; int b = 0;spCur = sp - pNext; while(spCur != NULL )b +;spCur = spCur - pNext;return b;int searchlist(s。
22、truct Note *sp,int x)/查struct Note *spCur; spCur = sp - pNext;while (spCur - pNext != NULL & spCur -return 1;int Deletelist(struct Note *sp,int x)/删除struct Note *spCur,*spT; spCur = sp;while(spCur - pNext != NULL & spCur - pNext -value != x)spCur = spCur -pNext; if (spCur - pNext = NULL)return 1; 。
23、spT = spCur - pNext;spCur - pNext = spCur - pNext - pNext; free(spT);return 0;void Printlist(struct Note *sp)printf(n);学⽣成绩1.0 版本/*五个学⽣四门功课成绩排名感觉像是回到了⾼中=。=第⼀次录⼊时,总分,均分输⼊ 0!*/ #include#define swap(x,y) int tmp=x;x=y;y=tmp;/*定义了⼀个交换器函数不然感觉很烦⼈*/ void main(void)int iCj57=0;int i,j,k;int iPos,iTem = 0;pr。
24、intf(请依次输⼊五位学⽣的学号和各科成绩n);for (i = 0; i struct studentlong num;char name20; float
score2;scanf(%ld,&sti.num); gets(sti.name);for (j = 0;j iCjiPos5) iPos = j;for (k=0;ksti.score1)?sti.score0 : sti.score1; iPos = 0;for (i = 1; i ciPos)iPos =i;return iPos;/*在平均分以下的*/void ave(struct student stN, int *x)。
25、float ave1 = 0,ave2 = 0; int i;for (i = 0; i #include #define N 5struct studentchar name20; long ID;float score3; float fAve; float fSum;stN;int main(void)FILE *fpGet; int i,j;float t;fpGet = ,w); if (fpGet = NULL)printf(error !); return
1;printf(请输⼊学⽣信息n); for(i = 0; i #include #define N。
26、 5struct studentchar name20; long ID;float Score3; float fAve; float fSum;stN;int main(void)FILE *fpIn,*fpOut; int
i,j,iPos=0;struct student sTem; fpIn = ,r); if(fpIn = NULL)printf(error !); return 1;fpOut = ,w);
if(fpOut = NULL)printf(error !);return 1; for(i = 0; i stj.fSu。
27、m) iPos = j;sTem = stiPos ; stiPos = sti;sti = sTem;for(i = 0; i N; i +)fprintf(fpOut,%st%ldt,sti.name,sti.ID); for(j = 0; j 3; j +)fprintf(fpOut,%5.2ft,sti.Scorej);fprintf(fpOut,%5.2ft%5.2f,sti.fAve,sti.fSum); fprintf(fpOut,n);printf(FINISH !); fclose(fpIn); fclose(fpOut); return 0;“”“”At the end, 。
28、Xiao Bian gives you a passage. Minand once said, people who learn to learn are very happy people. In every wonderful life, learning is an eternal theme. As a professional clerical and teaching position, I understand the importance of continuous learning, life is diligent, nothing can be gained, only。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论