1. Judge whether a three digit number is the number of daffodils
two Do you really sleep or pretend to sleep
3. Convert decimal number to eight digit binary number
four The maximum value of the absolute value of the relationship between three numbers
5. Fishing for three days and drying the net for two days
1, Judge whether a three digit number is the number of daffodils
This problem requires writing a program to judge whether a given three digit number is the number of daffodils. The three digit daffodil number, that is, the cubic sum of its single digit, ten digit and hundred digit number is equal to the number itself.
Input format:
Input gives an integer to be judged in one line N(100≤N≤999).
Output format:
If N is the number of daffodils, Yes is output in one line, otherwise No is output. If N is not three digits, Invalid Value is output.
#include<stdio.h> #include<math.h> int main() { int a; int b, c, d,e; int m=0; scanf("%d", &a); e = a; if (a < 100 || a>999) { printf("Invalid Value."); return 0; } b = a / 100; //Take hundreds b = b * b * b; a = a % 100; c = a / 10; //Take ten c = c * c * c; a = a % 10; //Take a bit d = a * a * a; m = b + c + d; if (m == e) { printf("Yes"); } else { printf("No"); } }
two Do you really sleep or pretend to sleep
You can never wake up a person who pretends to sleep - but by analyzing a person's breathing rate and pulse, you can find out who is pretending to sleep! The doctor told us that the breathing rate of normal people during sleep is 15-20 times per minute and the pulse is 50-70 times per minute. Given a person's breathing rate and pulse below, please judge whether he really sleeps or pretends to sleep (that is, at least one index is not within the normal sleep range).
Input format:
Enter two integers separated by spaces in one line to represent a person's respiratory rate and pulse respectively (both positive integers no more than 100).
Output format:
If it is determined that the person is really asleep, output T. Otherwise, it is installed sleep and output F.
#include<stdio.h> int main() { int m, n; scanf("%d %d", &m, &n); if (m >= 15 && m <= 20 && n >= 50 && n <= 70) { printf("T"); } else { printf("F"); } return 0; }
3. Convert decimal number to eight digit binary number
#include<stdio.h> #define N 8 / / fixed digits int main() { int arr[N] = { 0 };//Initialize the array to 0 (when the number of bits is not enough, 0 will be output) int i; int n; printf("Please output an integer:\n"); scanf_s("%d", &n); if (n > 255) { printf("Input error\n"); return 0; } for (i = N - 1; i >= 0; i--) //Assign a value to the array from back to front { arr[i] = n % 2; n = n / 2; } printf("Output an eight bit binary:\n"); for (i = 0; i <= N - 1; i++) { printf("%d", arr[i]); } return 0; }
four The maximum value of the absolute value of the relationship between three numbers
Input three integers from the keyboard and output the number with the largest absolute value. If the number with the largest absolute value is not unique, the first one will be output.
Input format:
Contains 3 integers in the int range, separated by spaces.
Output format:
An integer representing the number with the largest absolute value.
#include<stdio.h> #include<math.h> void main() { int m, n, p; int a, b, c; scanf("%d %d %d", &m, &n, &p); a = abs(m); b = abs(n); c = abs(p); if (a ==b && a > c) { printf("%d", m); } else if (b == c && b > a) { printf("%d", n); } else if (a == c && a > b) { printf("%d", m); } else if (a==b&&b==c) { printf("%d",m); } else { if (a <= b) { a = b; m = n; if (a <= c) { a = c; m = p; } } printf("%d", m); } }
5. Fishing for three days and drying the net for two days
There is a Chinese proverb called "fishing in three days and drying the net in two days". Suppose someone starts "fishing for three days and drying the net for two days" from one day, and asks this person whether to "fish" or "dry the net" on the next N day?
Input format:
The input gives a positive integer N of no more than 1000 in one line.
Output format:
In one line, output whether the person is "Fishing" or "Drying" on day N, and output "in day N".
#include<stdio.h> int main() { int N,m; scanf("%d",&N); m=N%5; if(m==4||m==0) if(m==1||m==2||m==3) return 0; }