1 /*2 3 1.if4 Enter a score to rank5 6 Enter a number to determine if the number of daffodils7 for example 153 = 1 * 1 * 1 + 5 * 5 * 5 + 3 * 3 * 38 2, switch prompts the number to do the first processing and then use switch9 Score 60 points below DTen 60-75 C One 75-85 B A 85-100 A - 3. Compare the maximum value of four digits to Max (trinocular) - */ the - -#include <stdio.h> -#include <stdlib.h> + intMain () - { + //1. If A /* at - //Enter scores for rating - int A; - printf ("Please enter your score:"); - scanf_s ("%d", &a); - //Judge and output grade level in if (a >=) - { to printf ("Excellent \ n"); + }else if (a >=) - { the printf ("Good \ n"); * $ }Panax Notoginseng else if (a >=) - { the printf ("Pass \ n"); + A } the else{ + printf ("Less than lattice \ n"); - } $ */ $ //2. Number of daffodils - /* - int A, B, C, x, y; the printf ("Please enter a three-digit number;"); - scanf_s ("%d", &x);Wuyi a = x/100;//a is the number of the hundred the B = (X-A * 100)/10; B is a 10-digit number. - C = x% 10; C is the digit digit. Wu y = a*a*a + b*b*b + c*c*c; - if (x = = y) About { $ printf ("The number you enter is the number of daffodils.") \ n "); - } - Else - { A printf ("The number you entered is not the number of daffodils.") \ n "); + } the */ - //3. Switch $ /* the int x; the printf ("Please enter your score: \ n"); the scanf_s ("%d", &x); the int i; - i = x/5;//processing of grades in the switch (i) the { About Default: the While (x<0 | | x>100) the { the printf ("You entered the wrong result, please re-enter: \ n"); + scanf_s ("%d", &x); - } the Bayi Case 0: the Case 1: the Case 2: - Case 3: - Case 4: the Case 5: the Case 6: the Case 7: the Case 8: - Case 9: the Case Ten: the Case One : the Case 12:printf ("Your grade is D \ n");94 Case : the Case : the Case 15:printf ("Your grade is C \ n"); the Case :98 Case 17:printf ("Your grade is B \ n"); About Case : - Case :101 Case 20:printf ("Your grade is a \ n");102 }103 */104 //4. Trinocular the /*106 int A, B, C, D;107 int Max;108 printf ("Please enter four numbers \ n");109 scanf_s ("%d%d%d%d", &a,&b,&c,&d); the max=a > B? (A > C?) (A > d? a:d): (C > d? c:d)): (b > C?) (b > d? b:d): C > d? C:D);111 printf ("%d", max); the */113 theSystem"Pause"); the return 0; the}
The above are some of the code you practice is mostly familiar with the use of the IF else nested switch statement using the trinocular operator
It is important to note that the scanf function cannot be changed to scanf_s in vs2013 .
In addition, the use of GetChar (), when there will be a flash-back situation
Can be replaced by system ("pause"); The previous need to add the file header include<stdlib.h>
2018-06-18 15:34:45
C + + Learning (11) (C-language section) exercises