first question:
Title description:
Write a program, the user enters any 3 decimals; add these 3 decimals and display the result; convert the result to an integer by rounding and display.
Input and output format:
input: 3 decimals, space separated;
output: and, rounded integer, 1 line display, space separated
Sample input:
1.1 2.2 3.3
Sample output:
6.6 7
参考代码
: (This code originally used double and float, and neither% lf nor% f was used for output, but changed to AC after% g)
#include <stdio.h>
#include <math.h>
int main ()
{
float a,b,c;
scanf("%f%f%f",&a,&b,&c);
printf("%g %.0f",a+b+c,a+b+c);
return 0;
}
* Special notes:
Function name | Function description | 2.1 | 2.9 | -2.1 | -2.9 |
---|---|---|---|---|---|
Floor() | The largest integer not greater than the independent variable | 2 | 2 | -3 | -3 |
Ceil() | The largest integer not less than the independent variable | 3 | 3 | -2 | -2 |
Round() | Round to the nearest integer | 2 | 3 | -2 | -3 |
Information from https://blog.csdn.net/inter_peng/article/details/51397646
The second question:
Title description:
Enter a decimal integer (int type), output the hexadecimal form of the number, and then output the corresponding values of the upper 2 bytes and lower 2 bytes of the number in hexadecimal form, separated by commas.
Input and output format:
Input: an integer (decimal)
Output: hexadecimal of the number in the first line; high-end 2 bytes of the hexadecimal number (comma separated) in the second line (lower-end 2 bytes of the hexadecimal number)
Tip: int a = 1; printf ("% 04d", a); then the output is: 0001
Sample input:
-32768
Sample output:
ffff8000
ffff,8000
参考代码
:
#include<stdio.h>
int main()
{
int a;
scanf("%d", &a);
printf("%x\n", a);//%x是以十六进制数形式输出整数
int b = a >> 16;// >>右移16位,此时b=00000000 00000000
printf("%04x,%04x", b & 0x0000FFFF, a & 0x0000FFFF);//int a=1;printf("%04d",a);则输出为:0001
return 0;
}
The third question:
Title description:
Write a program, input a three-digit positive integer, output one digit, ten digits and hundred digits respectively, separated by commas (comma).
Input and output format:
Input: positive integer (between 100 and 999)
Output: single digits, tens digits, hundreds digits (comma separated three digits)
Sample input:
103
Sample output:
3,0,1
参考代码:
#include <stdio.h>
int main()
{
unsigned int n;
char c1,c2,c3;
scanf("%d",&n);
c1=(n%100)%10+'0';
c2=(n/10)%10+'0';
c3=n/100+'0';
printf("%c,%c,%c",c1,c2,c3);
return 0;
}
The fourth question:
Title description:
Input a capital English letter, and output the adjacent letter string (consider the letter AZ as a ring-like arrangement with the ending).
Input and output format:
Input: Uppercase English letters
Output: the letter before the letter, the letter, the letter after the letter. (No space between three letters)
Sample input:
V
Sample output:
UVW
参考代码:
#include<stdio.h>
int main()
{
char a, m, n; int b, c, d;
scanf("%c", &a);
switch (a)
{
case 'A':
printf("ZAB");
break;
case 'Z':
printf("YZA");
break; //容易考虑不周全
default:
b = a;
c = b - 1, d = b + 1;
m = c, n = d; //强制类型转换
printf("%c%c%c", m, b, n);
}
return 0;
}