//
// main.m
// 第四次作业低能儿版本
//
// Created by YIem on 15/11/13.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import <Foundation/Foundation.h>
define SIZE (20)
define string
int main(int argc, const char * argv[]) {
if 0
//第一题
int a[SIZE] = {0}, i = 0;
for(i = 0; i < SIZE; i++)
{
a[i] = i + 10;
printf("a[%d] = %d\n", i, a[i]);
}
endif
if 0
//第二题
int a[SIZE] = {0}, i = 0;
for(i = 0; i < SIZE; i++)
{
a[i] = 10 - i;
printf("a[%d] = %d\n", i, a[i]);
}
endif
if 0
// 第三题
int a[SIZE] = {0}, i = 0, sum = 0;
for(i = 0; i < SIZE; i++)
{
a[i] = i + 10;
printf("a[%d] = %d\n", i, a[i]);
sum += a[i];
}
printf("sum = %d\n", sum);
endif
if 0
// 第四题
int a[SIZE] = {0}, i = 0, sum = 20;
for(i = 0; i < SIZE; i++)
{
a[i] = i + 10;
printf("a[%d] = %d\n", i, a[i]);
sum -= a[i];
}
//sum = sum + (2 * a[0]); //或者 写成这样
printf("sum = %d\n", sum);
endif
if 0
// 第五题
int a[SIZE] = {0}, i = 0, sum = 0, max = 0, min = 0;
for(i = 0; i < SIZE; i++)
{
a[i] = arc4random() % (50 -10 +1) +10;
printf("a[%d] = %d\n", i, a[i]);
sum += a[i];
if (max < a[i]){//最大值
max = a[i];
}
if (0 == i || min > a[i]){//最小值
min = a[i];
}
}
printf("最大值=:%d\n", max);
printf("最小值=:%d\n", min);
printf("元素之和= %d\n", sum);
endif
if 0
//第六题
int a1[5] ={0}, a2[5] = {0}, temp = 0, a3[10] = {0};
for (int i = 0; i < 5 - 1; i++) {
a1[i] = arc4random() % (40 - 20 + 1) + 20;
a2[i] = arc4random() % (40 - 20 + 1) + 20;
}
for (int i = 0; i < 5 - 1; i++) {
for (int j = 0; j < 5 - 1 - i; j++) {
if (a1[j] > a1[j + 1]) {
int temp = a1[j];
a1[j] = a1[j + 1];
a1[j + 1] = temp;
}
}
}
for (int i = 0; i < 5; i++) {
printf("%d ", a1[i]);
}
printf("\n");
for (int i = 0; i < 5 - 1; i++) {
for (int j = 0; j < 5 - 1 - i; j++) {
if (a2[j] > a2[j + 1]) {
int temp = a2[j];
a2[j] = a2[j + 1];
a2[j + 1] = temp;
}
}
}
for (int i = 0; i < 5; i++) {
printf("%d ", a2[i]);
}
printf("\n");
for (int i = 0; i < 10; i++) {
if (i < 5) {
a3[i] = a1[i];
}
else {
a3[i] = a2[i - 5];
}
}
for (int i = 0; i < 10; i++) {
printf("%d ", a3[i]);
}
printf("\n");
endif
// a3[i] = a1[i] a2[i];
if 0
// 第七题
int a = 0, b = 0, c = 0;
printf("输入年月日(如20150101):\n");
scanf("%d %d %d", &a, &b, &c);
endif
if 0
// 第八题
int a[10] = {2, 5, 9, 6, 4, 1, 5, 8, 0, 30};
for (int i = 0; i < 10 - 1; i++) {
for (int j = 0; j < 10 - 1 - i; j++) {
if (a[j] > a[j + 1]) {
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
for (int i = 0; i < 10 ; i++) {
printf("%d", a[i]);
printf("\n");
}
endif
if 0
// 第九题
int a[] = {5, -9, 32, 77, 64, -24, 14, 0, 21, 45}, max = 0, min = 0, min5 = 0, max4 = 0;
for(int i = 0; i < 10; i++)
{
if (max < a[i]){//最大值
max = a[i];
max4 = i;
}
if (0 == i || min > a[i]){//最小值
min = a[i];
min5 = i;
}
}
printf("从0开始>%d\n从0开始>%d\n", max4, min5);
printf("最大值=:%d\n", max);
printf("最小值=:%d\n", min);
endif
if 0
//第十题
for (int i = 0; i < 50; i++) {
char result[50] = {0};
char str1[] = "Lanou ";
char str2[] = "1129_class ";
char str3[] = " is a fantastic 伐木累!";
strcat(str1, str2);
strcat(str1, str3);
strcpy(result, str1);
printf("%s", result);
}
endif
int year,month,day,maxday,daily;
printf("请输入年份:");
scanf("%d",&year);
loop:printf("请输入月份:");
scanf("%d",&month);
printf("请输入日:");
scanf("%d",&day);
switch(month){
case 1:daily=0,maxday=31;
break;
case 2: daily = 31, maxday = 28;
break;
case 3: daily = 59, maxday = 31;
break;
case 4: daily = 90, maxday = 30;
break;
case 5: daily = 120, maxday = 31;
break;
case 6: daily = 151, maxday = 30;
break;
case 7: daily = 181, maxday = 31;
break;
case 8: daily = 212, maxday = 31;
break;
case 9: daily = 243, maxday = 30;
break;
case 10: daily = 273, maxday = 31;
break;
case 11: daily = 304, maxday = 30;
break;
case 12: daily = 334, maxday = 31;
break;
}
daily += day;
printf("%d年%d月%d日是这年的第%d天!!!\n",year,month,day,daily);
return 0;