Take you to brush (Nioke.com) C language 100 questions (tenth day)

✅Author's introduction: Hello everyone, I am @I have to type code every day, a player who is a material transfer coder, I hope to work hard and make progress together!
📃Personal homepage: @The personal homepage who has to type codes every
day🔥Series of columns: Niuke.com brush questions column 
💬Recommend a mock interview, brush questions artifact, from basic to big factory interview questions 👉Click to jump to the brush questions website to register study

Table of contents

Exercise 1: The Four Seasons

Exercise 2: Health Assessment

Exercise 3: Xiaolele finds the largest number

Exercise 4: Judging whether it is a letter

Exercise 5: Divide by 237 of Niuniu

Exercise 6: Positive and Negative Numbers of Statistical Data

concluding remarks


Exercise 1: The Four Seasons

describe

Meteorologically, spring is usually from March to May, summer is from June to August, autumn is from September to November, and winter is from December to February. Please output the corresponding season according to the input year and month.

Enter description:

The input data format is a fixed YYYYMM format, that is, the year occupies 4 digits, and the month occupies 2 digits.

Output description:

Output the season corresponding to the month (expressed in English words, all in lowercase).

Example 1

Input: 201901

output: winter

Note: The year entered should be 4 digits, and the month entered should be 1~12.

  1. #include<stdio.h>
  2. int main()
  3. {
  4. int year,month;
  5. scanf("%4d%2d", &year, &month);
  6. if(month >= 3 && month <= 5)
  7. printf("spring\n");
  8. else if(month >= 6 && month <= 8)
  9. printf("summer\n");
  10. else if(month >= 9 && month <= 11)
  11. printf("autumn\n");
  12. else
  13. printf("winter\n");
  14. return 0;
  15. }

Exercise 2: Health Assessment

describe

The BMI index (ie body mass index) is a number obtained by dividing the weight in kilograms by the square of the height in meters. For example: a person is 1.75 meters tall and weighs 68 kg, his BMI=68/(1.75^2)=22.2 (kg/m^2). When the BMI index is 18.5 to 23.9, it is normal, otherwise it means that the body has a health risk. Program to judge human health.

Enter description:

On one line, enter a person's weight (kg) and height (m), separated by a space.

Output description:

One line, output body Normal (normal) or Abnormal (abnormal).

Example 1

Input: 68 1.75

Output: Normal

Example 2

Input: 67.5 1.65

Output: Abnormal

  1. #include <stdio.h>
  2. int main()
  3. {
  4. float w,h;
  5. scanf("%f %f",&w,&h);
  6. float BMI=w/(h*h);
  7. if(BMI>=18.5 && BMI<=23.9)
  8. printf("Normal");
  9. else
  10. printf("Abnormal");
  11. return 0;
  12. }

Exercise 3: Xiaolele finds the largest number

describe

Xiaolele got 4 maximum numbers, please help him find the maximum number by programming.

Enter description:

One line, 4 integers, separated by spaces.

Output description:

A line, an integer, is the largest integer among the four input integers.

Example 1

Input: 5 8 2 5

output: 8

 

  1. #include <stdio.h>
  2. int main()
  3. {
  4. // method 1
  5. int a,b,c,d;
  6. scanf("%d%d%d%d",&a,&b,&c,&d);
  7. if(a<b)
  8. {
  9. int tmp=a;
  10. a=b;
  11. b=tmp;
  12. }
  13. if(a<c)
  14. {
  15. int tmp=a;
  16. a=c;
  17. c=tmp;
  18. }
  19. if(a<d)
  20. {
  21. int tmp=a;
  22. a=d;
  23. d=tmp;
  24. }
  25. printf("%d",a);
  26. // method 2
  27. int main()
  28. {
  29. int arr[4]={0};
  30. for(int i =0;i<4;i++)
  31. scanf("%d",&arr[i]);
  32. int max = arr[0];
  33. for(int i=0;i<4;i++){
  34. if(max<arr[i]){
  35. max = arr[i];
  36. }
  37. }
  38. printf("%d\n",max);
  39. return 0;
  40. }

Exercise 4: Judging whether it is a letter

describe

KiKi wants to determine whether the input character is a letter or not, please help him program it.

Enter description:

Multiple sets of input, one character per line.

Output description:

For each group of input, the output occupies a separate line to determine whether the input character is a letter. For the output content, see the output example.

Example 1

enter:

A

6

output:

A is an alphabet.

6 is not an alphabet.

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int ch=0;
  5. while((ch=getchar()) != EOF)
  6. {
  7. if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
  8. {
  9. printf("%c is an alphabet.\n",ch);
  10. getchar();
  11. }
  12. else
  13. {
  14. printf("%c is not an alphabet.\n",ch);
  15. getchar();
  16. }
  17. }
  18. return 0;
  19. }

Exercise 5: Divide by 237 of Niuniu

describe

Niu Niu input an integer from the keyboard, please judge which number of 2 3 7 this integer can be divided by, and output it in ascending order. If it is not divisible by any number 2 3 7 then output n.

Enter description:

enter an integer

Output description:

Output which numbers are divisible by 2 3 7 and output in ascending order.

Example 1

Input: 6

Output: 2 3

Example 2

Input: 3

output: 3

Example 3

Input: 14

Output: 2 7

Example 4

Input: 11

output: n

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int n=0;
  5. scanf("%d",&n);
  6. if(n%2==0)
  7. printf("2 ");
  8. if(n%3==0)
  9. printf("3 ");
  10. if(n%7==0)
  11. printf("7 ");
  12. if(n%2!=0 && n%3!=0 && n%7!=0)
  13. printf("n ");
  14. return 0;
  15. }

Exercise 6: Positive and Negative Numbers of Statistical Data

describe

Input 10 integers, and output the number of positive and negative numbers respectively.

Enter description:

Enter 10 integers (ranges -2^{31}-2^{31}-1), separated by spaces.

Output description:

Two lines, the first line contains positive numbers, and the second line contains negative numbers. See the example for the specific format.

Example 1

Input: -1 2 3 -6 7 8 -1 6 8 10

output:

positive:7

negative:3

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int arr[10]={0};
  5. int i=0;
  6. int count1=0,count2=0;
  7. for(i=0;i<10;i++)
  8. {
  9. scanf("%d ",&arr[i]);
  10. }
  11. for(i=0;i<10;i++)
  12. {
  13. if(arr[i]>0)
  14. count1++;
  15. else
  16. count2++;
  17. }
  18. printf("positive:%d\n",count1++);
  19. printf("negative:%d",count2++);
  20. return 0;
  21. }

concluding remarks

Today's sharing is here!

Sign up to join the quiz army through the link below! The real interview questions of various big factories are waiting for you!

Tags: Take you to brush (Nioke.com) C language 100 questions (tenth day)

Niuke.com C language brushing column c language algorithm Development language

Related: Take you to brush (Nioke.com) C language 100 questions (tenth day)