目录
题目二:输入年月日,输出year=,month=,date=
题目四:打印printf("Hello world!\n"); \n"); printf("cout << "Hello world!" << endl;");
题目一:将数组里的内容用字符的形式打印来
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int arr[] = { 73,32,99,97,110,32,100,111,32,105,116,33, };
int sz = sizeof(arr)/sizeof(arr[0]);
int i = 0;
while (i<sz)
{
printf("% c", arr[i]);
i++;
}
return 0;
}
题目二:输入年月日,输出year=,month=,date=
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int year = 0;
int month = 0;
int date = 0;
scanf("%4d%2d%2d", &year, &month, &date);
printf("year = %d年\n", year);
printf("month = %02d月\n", month);
printf("date = %02d日", date);
return 0;
}
题目三:打印一串字符,并输出字符个数
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int n = printf("Hello world!");
printf("\n%d", n);
return 0;
}
题目四:打印printf("Hello world!\n"); \n");
printf("cout << "Hello world!" << endl;");
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
printf("printf(\"Hello world!\\n\"); \n");
printf("cout << \"Hello world!\" << endl;");
return 0;
}
题目五:输入四个数字,打印出四个数字中最大的元素
方法一:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int arr[4] = {0};
int i = 0;
while(i<4)
{
scanf("%d", &arr[i]);
i++;
}
int max = arr[0];
i = 1;
while (i< 4)
{
if(arr[i]>max)
{
max = arr[i];
}
i++;
}
printf("%d", max);
return 0;
}
方法二:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int i = 1;
int n = 0;
int max = 0;
scanf("%d", &max);
while (i<4)
{
scanf("%d", &n);
if (n > max)
max = n;
i++;
}
printf("%d", max);
return 0;
}
题目六:计算球的体积
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
double r = 0.0;
double v = 0.0;
double pi = 3.1415926;
scanf("%lf", &r);
v =4 / 3.0 * pi * (r * r * r);
printf("%.3lf", v);
return 0;
}
题目七:输入身高体重,输出BMI
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int height = 0;
int weight = 0;
float BMI = 0.0f;
scanf("%d %d", &height,& weight);
BMI = weight / (height /100.0 )/ (height/100.0);
printf("%.2f", BMI);
return 0;
}