任务一
#include <stdio.h>
#define N 4
int main() {
int a[N] = { 1, 9, 8, 4 };
char b[N] = { '1', '9', '8', '4' };
int i;
printf("sizeof(int) = %d\n", sizeof(int));
printf("sizeof(char) = %d\n", sizeof(char));
printf("\n");
for (i = 0; i < N; ++i)
printf("%p: %d\n", &a[i], a[i]);
printf("\n");
for (i = 0; i < N; ++i)
printf("%p: %c\n", &b[i], b[i]);
printf("\n");
printf("a = %p\n", a);
printf("b = %p\n", b);
return 0;
}
1:int型数组a,在内存中是连续存放的。每个元素占用4个字节。
2:char型数组b,在内存中是连续存放的。每个元素占用1个字节。
3:是;是。
#include <stdio.h>
#define N 2
#define M 4
int main() {
int a[N][M] = { {1, 9, 8, 4}, {2, 0, 2, 2} };
char b[N][M] = { {'1', '9', '8', '4'}, {'2', '0', '2', '2'} };
int i, j;
for (i = 0; i < N; ++i)
for (j = 0; j < M; ++j)
printf("%p: %d\n", &a[i][j], a[i][j]);
printf("\n");
for (i = 0; i < N; ++i)
for (j = 0; j < M; ++j)
printf("%p: %c\n", &b[i][j], b[i][j]);
return 0;
}
1:是;4。
2:是;
1任务二
#include<stdio.h>
#define N 13
int days_of_year(int, int, int);
int main()
{
int day, month, year;
int days;
while (scanf_s("%d%d%d", &year, &month, &day) != EOF) {
days = days_of_year(year, month, day);
printf("%4d-%02d-%02d是这一年的第%d天.\n\n", year, month, day, days);
}
return 0;
}
int days_of_year(int year, int month, int day)
{
int x[12] = { 31,0,31,30,31,30,31,31,30,31,30,31 };
int leapyear;
leapyear = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
x[1] = 28 + leapyear;
int s = 0, i;
for (i = 0; i < month - 1; i++)
{
s = s + x[i];
}
return s + day;
}
任务三
标签:int,31,printf,month,++,实验,year From: https://www.cnblogs.com/skf123/p/16927208.html