C语言程序设计——大连理工大学第一次上机作业(纸质作业)
第一题 (法一)
#include <stdio.h>
void repetition()
{
printf("||");
printf("\n");
printf("||");
}
int main()
{
int i=0;
printf("============================================================");
printf("\n");
printf("||");
for (i = 0; i < 24; i++)
{
printf("\ ");
}
printf("学生信息");
for (i = 0; i < 24; i++)
{
printf("\ ");
}
repetition();
printf("========================================================");
printf("||");
printf("\n");
printf("||");
printf("姓名:张三");
for (i = 0; i < 46; i++)
{
printf("\ ");
}
repetition();
printf("学号:2019097654321");
for (i = 0; i < 37; i++)
{
printf("\ ");
}
repetition();
printf("电话:15140115678");
for (i = 0; i < 39; i++)
{
printf("\ ");
}
repetition();
printf("========================================================");
printf("||");
printf("\n");
return 0;
}
第一题 (法二)
#include <stdio.h>
int main()
{
int i = 0;
for (i = 0; i < 60; i++)
{
printf("=");
}
printf("\n");
printf("||");
for (i = 0; i < 24; i++)
{
printf("\ ");
}
printf("学生信息");
for (i = 0; i < 24; i++)
{
printf("\ ");
}
printf("||");
printf("\n");
printf("||");
for (i = 0; i < 56; i++)
{
printf("=");
}
printf("||");
printf("\n");
printf("||");
printf("姓名:张三");
for (i = 0; i < 46; i++)
{
printf("\ ");
}
printf("||\n");
printf("||");
printf("学号:2019097654321");
for (i = 0; i < 37; i++)
{
printf("\ ");
}
printf("||\n");
printf("||");
printf("电话:15140115678");
for (i = 0; i < 39; i++)
{
printf("\ ");
}
printf("||\n");
printf("||");
for (i = 0; i < 56; i++)
{
printf("=");
}
printf("||");
printf("\n");
return 0;
}
第二题
#include <stdio.h>
int main()
{
int i = 0;
int F = 0;
float C = 0;
printf("||");
printf("============================================================");
printf("\n");
printf("||");
printf("请输入要转换的华氏温度:");
scanf_s("%d",&F);
C = 5.0/9*(F-32);
printf("||");
printf("============================================================");
printf("\n");
printf("||");
printf("%.2f 华氏度等于%.2f摄氏度\n",(float)F,C);
printf("||");
printf("============================================================");
return 0;
}
第三题
#include <stdio.h>
int main()
{
char ch;
scanf_s("%c",&ch);
if ((ch >= 65) && (ch <= 90))
{
ch += 32;
printf("%c\n", ch);
}
else
printf("输入错误");
return 0;
}
第四题
#include <stdio.h>
int main()
{
int x;
printf("要转换的数是:");
scanf_s("%d",&x);
printf("%d的十六进制数表示为:%#x,八进制表示为:%#o",x,x,x);
return 0;
}
第五题
#include <math.h>
#include <stdio.h>
int main()
{
int x;
printf("The input is:");
scanf_s("%d",&x);
printf("The square root of %.1f is %.1f",(float)x,(sqrt(x)));
return 0;
}
第六题
#include <stdio.h>
int main()
{
int m, hour, minute;
int time1, time2;
scanf_s("%d%d", &time1, &time2);
if (((time1 >= 0000) && (time1 <= 2359)) && ((time2 >= 0000) && (time2 <= 2359)))
{
m = time2 - time1;
hour = m / 100;
minute = m % 100;
if (minute > 60)
{
minute -= 40;
}
printf("The train journey time is %d hrs %d minute", hour, minute);
}
else
printf("输入错误");
return 0;
}