电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

经典C语言源代码

49页
  • 卖家[上传人]:大米
  • 文档编号:511651452
  • 上传时间:2022-11-17
  • 文档格式:DOCX
  • 文档大小:186.21KB
  • / 49 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、经典C语言源代码1、(1)某年某月某日是星期几#includeint main()int year, month, day;while (scanf_s(%d%d%d, &year, &month, &day) != EOF)if (month = 1 | month = 2)/判断month是否为1或2year-;month += 12;int c = year / 100;int y = year - c * 100;整理为word格式int week = (c / 4) - 2 * c + (y + y / 4) + (13 * (month + 1) / 5) + day - 1;while (week0) week += 7; week %= 7;switch (week)case 1:printf(Mondayn); break;case 2:printf(Tuesdayn); break;case 3:printf(Wednesdayn); break;case 4:printf(Thursdayn); break;case 5:printf(Fridayn); brea

      2、k;case 6:printf(Saturdayn); break;case 0:printf(Sundayn); break;return 0;整理为word格式1、(2)某年某月某日是第几天(一维数组)#include stdio.hvoid main() int i, flag, year, month, day, dayth;int month_day = 0,31,28,31,30,31,30,31,31,30,31,30,31 ;printf(请输入年/月/日:n);scanf_s(%d/%d/%d, &year, &month, &day);dayth = day;flag = (year % 400 = 0) | (year % 4 = 0 & year % 100 != 0);if (flag)month_day2 = 29;for (i = 1; i month; i+)dayth = dayth + month_dayi;printf(%d/%d/%d是第%d天n, year, month, day, dayth);整理为word格式2、30个数中找最小的数及其位

      3、置#include stdio.h# define SIZE 30void main() int i;float dataSIZE;int min;printf(请输入%d个浮点数:n,SIZE);for (i = 0; i SIZE; i+) /scanf_s(%f, &datai);datai = rand() % 30 + 1;printf(%f、, datai);min = 0;整理为word格式for (i = 1; i SIZE; i+) if (datai datamin)min = i;printf(最小值是%5.2f,位置是%5dn, datamin, min);3、30个数从小到大排序(1)#include stdio.h# define SIZE 30void main() int i,j;float dataSIZE,temp;int min;printf(请输入%d个整型数:n,SIZE);整理为word格式for (i = 0; i SIZE; i+) scanf_s(%f, &datai);for (i = 0; i SIZE; i+) min = i;f

      4、or (j = i + 1; j SIZE; j+)if (dataj datamin)min = j;temp = datamin;datamin = datai;datai = temp;printf(n排序后的结果是:n);for (i = 0; i SIZE; i+)printf(%5.2f, datai);整理为word格式(2)模块化程序(数组名作为函数参数)#include stdio.h# define SIZE 5void accept_array(float a, int size);void sort(float a, int size);void show_array(float a, int size);void main() float scoreSIZE;accept_array(score, SIZE);printf(排序前:);show_array(score, SIZE);sort(score, SIZE);printf(排序后:);show_array(score, SIZE);void accept_array(float a, int size

      5、) int i;整理为word格式printf(请输入%d个分数:, size);for (i = 0; i size; i+)scanf_s(%f, &ai);void show_array(float a, int size) int i;for (i = 0; i size; i+)printf( %5.2f, ai);printf(n);void sort(float a,int size) int i, min, j;float temp;for (i = 0; i SIZE; i+) min = i;for (j = i + 1; j SIZE; j+)if (aj amin)整理为word格式min = j;temp = amin;amin = ai;ai = temp;4、(1)指针加减:#include stdio.h#define SIZE 10void main() int aSIZE = 1,2,3,4,5,6,7,8,9,10 ;int *pa, i;pa = &a0; /pa=a;printf(n);整理为word格式for (i = 0; i SIZE;

      6、i+) printf( %d, *pa);/printf( %d, *(pa+1);pa+;(2)指针比较:#include stdio.h#define SIZE 10void main() int aSIZE = 1,2,3,4,5,6,7,8,9,10 ;int *pa, i;int *qa;pa = qa = &a0;printf(请输入%d整型数:,SIZE);for (; pa qa + SIZE; pa+)整理为word格式scanf_s(%d, pa);for (pa-; qa = pa; pa-)printf( %d, *pa);5、两字符串相连:#include stdio.h#include string.hvoid str_cat(char str1, char str2);void main() int i, j;char str1160;char str280;printf(请输入第一个字符串:);gets(str1);printf(请输入第二个字符串:);gets(str2);整理为word格式str_cat(str1, str2);puts(str1);

      7、void str_cat(char str1, char str2) int i, j;i = 0;while (str1i != 0)i+;j = 0;while (str2j != 0) str1i = str2j;i+; j+;str1i = 0;6、二维数组(a,b转置)整理为word格式#include stdio.hvoid main() int i, j, b23;int a32 = 1,2,3,4,5,6 ;for (i = 0; i 2; i+) for (j = 0; j 3; j+)bij = aji;printf(na:n);for (i = 0; i 3; i+) for (j = 0; j 2; j+)printf(%5d, aij);printf(n);printf(nb:n);for(i = 0; i 2; i+) for (j = 0; j 3; j+)整理为word格式printf(%5d, bij);printf(n);7、输入一个二维数组并输出(指针)#include stdio.hvoid main() int x23;int i, j;for (i = 0; i 2; i+)for (j = 0; j 3; j+)scanf_s(%d, *(x + i) + j);putchar(n);for (i = 0; i 2; i+)for (j = 0; j 3; j+)整理为word格式printf(%d , *(*(x + i) + j);putchar(n);8、冒泡法排序一个数组#include stdio.h#define size 10void maopao(int a);void mai

      《经典C语言源代码》由会员大米分享,可在线阅读,更多相关《经典C语言源代码》请在金锄头文库上搜索。

      点击阅读更多内容
    最新标签
    监控施工 信息化课堂中的合作学习结业作业七年级语文 发车时刻表 长途客运 入党志愿书填写模板精品 庆祝建党101周年多体裁诗歌朗诵素材汇编10篇唯一微庆祝 智能家居系统本科论文 心得感悟 雁楠中学 20230513224122 2022 公安主题党日 部编版四年级第三单元综合性学习课件 机关事务中心2022年全面依法治区工作总结及来年工作安排 入党积极分子自我推荐 世界水日ppt 关于构建更高水平的全民健身公共服务体系的意见 空气单元分析 哈里德课件 2022年乡村振兴驻村工作计划 空气教材分析 五年级下册科学教材分析 退役军人事务局季度工作总结 集装箱房合同 2021年财务报表 2022年继续教育公需课 2022年公需课 2022年日历每月一张 名词性从句在写作中的应用 局域网技术与局域网组建 施工网格 薪资体系 运维实施方案 硫酸安全技术 柔韧训练 既有居住建筑节能改造技术规程 建筑工地疫情防控 大型工程技术风险 磷酸二氢钾 2022年小学三年级语文下册教学总结例文 少儿美术-小花 2022年环保倡议书模板六篇 2022年监理辞职报告精选 2022年畅想未来记叙文精品 企业信息化建设与管理课程实验指导书范本 草房子读后感-第1篇 小数乘整数教学PPT课件人教版五年级数学上册 2022年教师个人工作计划范本-工作计划 国学小名士经典诵读电视大赛观后感诵读经典传承美德 医疗质量管理制度 2
    关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
    手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
    ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.