第一范文网 - 专业文章范例文档资料分享平台

经典C语言源代码

来源:用户分享 时间:2025/11/15 9:48:11 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

经典C语言源代码

1、(1)某年某月某日是星期几 #include int main() {

int year, month, day;

while (scanf_s(\{

if (month == 1 || month == 2)//判断month是否为1或2 { }

int c = year / 100; int y = year - c * 100;

int week = (c / 4) - 2 * c + (y + y / 4) + (13 * (month + 1) / 5) + year--; month += 12;

day - 1;

while (week<0) { week += 7; } week %= 7; switch (week) {

case 1:printf(\

}

}

case 2:printf(\case 3:printf(\case 4:printf(\case 5:printf(\case 6:printf(\case 0:printf(\}

return 0;

1、(2)某年某月某日是第几天(一维数组) #include \void 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(\dayth = day;

flag = (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); if (flag)

month_day[2] = 29;

}

for (i = 1; i < month; i++)

dayth = dayth + month_day[i];

printf(\是第%d天\\n\

2、30个数中找最小的数及其位置 #include \# define SIZE 30 void main() { int i;

float data[SIZE]; int min;

printf(\请输入%d个浮点数:\\n\for (i = 0; i < SIZE; i++) { } min = 0;

for (i = 1; i < SIZE; i++) {

if (data[i] < data[min]) //scanf_s(\data[i] = rand() % 30 + 1; printf(\、\

}

min = i;

printf(\最小值是%5.2f,位置是]\\n\

}

3、30个数从小到大排序 (1)

#include \# define SIZE 30 void main() { int i,j;

float data[SIZE],temp; int min;

printf(\请输入%d个整型数: for (i = 0; i < SIZE; i++) { scanf_s(\

}

for (i = 0; i < SIZE; i++) { min = i;

for (j = i + 1; j < SIZE; j++)

if (data[j] < data[min])

\\n\

}

min = j;

temp = data[min]; data[min] = data[i]; data[i] = temp;

}

printf(\排序后的结果是:\\n\for (i = 0; i < SIZE; i++)

printf(\

(2)模块化程序(数组名作为函数参数) #include \# define SIZE 5

void accept_array(float a[], int size); void sort(float a[], int size); void show_array(float a[], int size); void main() {

float score[SIZE]; accept_array(score, SIZE); printf(\排序前:\show_array(score, SIZE); sort(score, SIZE);

搜索更多关于: 经典C语言源代码 的文档
经典C语言源代码.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c88lud9difn8jj329nz0t2wkqq4mj6h00m38_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top