1.入门与顺序结构

第一题:输出helloworld

学习了输出语句,请参照例题,编写一个程序,输出以下信息:

**************************
Hello World!
**************************

注意:Hello与World之间有一个空格以及大小写问题
*也是输出的一部分,别光打印Hello World!

输入格式:
无需输入

输出格式:
**************************
Hello World!
**************************

代码:

#include<stdio.h>
int main()
{
    printf("**************************\n");
    printf("Hello World!\n");
    printf("**************************");
    return 0;
}

第二题:三个数最大值

编写一个程序,输入a、b、c三个值,输出其中最大值。

输入格式:
一行数组,分别为a b c

输出格式:
a b c其中最大的数

代码:
#include<stdio.h>
int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a < b)  a = b;
    if(a < c) a = c;
    printf("%d\n", a);
    return 0;
}

第三题:密码破译

要将"China"译成密码,译码规律是:用原来字母后面的第4个字母代替原来的字母.
例如,字母"A"后面第4个字母是"E"."E"代替"A"。因此,"China"应译为"Glmre"。
请编一程序,用赋初值的方法使cl、c2、c3、c4、c5五个变量的值分别为,’C’、’h’、’i’、’n’、’a’,经过运算,使c1、c2、c3、c4、c5分别变为’G’、’l’、’m’、’r’、’e’,并输出。

输入格式:
China

输出格式:
加密后的China

样例输入
China

样例输出
Glmre

#include <stdio.h>
#include <string.h>
int main()
{
	char str[100];
	scanf("%s", str);
	int len = strlen(str);
	for(int i = 0; i < len; i ++)
	{
	    printf("%c", str[i] + 4);
	}
	return 0;
}

第四题:温度转化

题目描述
输入一个华氏温度,要求输出摄氏温度。公式为 c=5(F-32)/9,取位2小数。

输入格式
一个华氏温度,浮点数

输出格式
摄氏温度,浮点两位小数

样例输入
-40
样例输出
c=-40.00

#include <stdio.h>
int main()
{
	double h, c;
	scanf("%lf", &h);
	c = 5 * (h - 32) / 9;
	printf("c=%.2f", c);
	return 0;
}
posted @ 2024-10-10 10:11  ericf  阅读(20)  评论(0)    收藏  举报