没有合适的资源?快使用搜索试试~ 我知道了~
(完整word版)经典C语言源代码.doc
需积分: 5 0 下载量 127 浏览量
2022-10-24
01:31:23
上传
评论
收藏 61KB DOC 举报
温馨提示
试读
35页
(完整word版)经典C语言源代码.doc
资源推荐
资源详情
资源评论
(完整 word 版)经典 C 语言源代码
.
经典 C 语言源代码
1、(1)某年某月某日是星期几
#include<stdio.h>
int main()
{
int year, month, day;
while (scanf_s("%d%d%d", &year, &month, &day) != EOF)
{
if (month == 1 || month == 2)//判断 month 是否为 1 或 2
{
year--;
month += 12;
}
int c = year / 100;
int y = year - c * 100;
int week = (c / 4) - 2 * c + (y + y / 4) + (13 * (month + 1) / 5) +
day - 1;
while (week<0) { week += 7; }
week %= 7;
switch (week)
{
case 1:printf("Monday"); break;
case 2:printf("Tuesday"); break;
(完整 word 版)经典 C 语言源代码
.
case 3:printf("Wednesday\n"); break;
case 4:printf("Thursday\n"); break;
case 5:printf("Friday\n"); break;
case 6:printf("Saturday\n"); break;
case 0:printf("Sunday\n"); break;
}
}
return 0;
}
1、(2)某年某月某日是第几天(一维数组)
#include "stdio.h"
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("%d/%d/%d", &year, &month, &day);
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];
(完整 word 版)经典 C 语言源代码
.
printf("%d/%d/%d 是第%d 天\n", year, month, day, dayth);
}
2、30 个数中找最小的数及其位置
#include "stdio.h"
# define SIZE 30
void main() {
int i;
float data[SIZE];
int min;
printf("请输入%d 个浮点数:\n",SIZE);
for (i = 0; i < SIZE; i++) {
//scanf_s("%f", &data[i]);
data[i] = rand() % 30 + 1;
printf("%f、", data[i]);
}
min = 0;
for (i = 1; i < SIZE; i++) {
if (data[i] < data[min])
min = i;
}
printf("最小值是%5.2f,位置是%5d\n", data[min], min);
(完整 word 版)经典 C 语言源代码
.
}
3、30 个数从小到大排序
(1)
#include "stdio.h"
# define SIZE 30
void main() {
int i,j;
float data[SIZE],temp;
int min;
printf("请输入%d 个整型数:\n",SIZE);
for (i = 0; i < SIZE; i++) {
scanf_s("%f", &data[i]);
}
for (i = 0; i < SIZE; i++) {
min = i;
for (j = i + 1; j < SIZE; j++)
if (data[j] < data[min])
min = j;
temp = data[min];
data[min] = data[i];
data[i] = temp;
(完整 word 版)经典 C 语言源代码
.
}
printf("\n 排序后的结果是:\n");
for (i = 0; i < SIZE; i++)
printf("%5.2f", data[i]);
}
(2)模块化程序(数组名作为函数参数)
#include "stdio.h"
# 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);
printf("排序后:");
show_array(score, SIZE);
}
void accept_array(float a[], int size) {
int i;
剩余34页未读,继续阅读
资源评论
智慧安全方案
- 粉丝: 3650
- 资源: 59万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功