Sixth time Assignment

Source: Internet
Author: User
Tags clear screen

First, the contents of the experiment

1. There is a four-bit positive integer that makes up the four digits of this four-digit number, and if they are swapped first and last, the second is swapped with the third, forming a new four-digit number. The original four-digit number is 4 times times the new four-digit number, please find a such four-digit number.

#include <stdio.h> #include <math.h>int main () {int num;int a,b,c,d,i;for (i=1000;i<10000;i++) {a=i%10;b = (I/10)%10;c= (i/100)%10;d=i/1000;if (a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d {num=a*1000+b*100+c*10+d*1;if (i*4==num) {                printf ("%d*4=%d\n", I,num);}}} return 0;}

  

2. Enter any number of digits to sum the numbers. If within "1,12", output the English name of the month corresponding to the number, otherwise output * * *.

Example: Input 123, output 6 June

Input 12345, Output 15 * * *

#include <stdio.h>int main () {int i=0,sum=0;printf ("Please enter a positive number: \ n"), while (1) {scanf ("%d", &i), if (i<=0) { printf ("Input error, re-enter: \ n"); continue;} Else{break;}} while (i>0) {sum=sum+ (i%10);        I=I/10;} printf ("%d", sum), if (sum==1) {printf ("January");} else if (sum==2) {printf ("February");} else if (sum==3) {printf ("March");} else if (sum==4) {printf ("April");} else if (sum==5) {printf ("may");} else if (sum==6) {printf ("June");} else if (sum==7) {printf ("July");} else if (sum==8) {printf ("August");} else if (sum==9) {printf ("September");} else if (sum==10) {printf ("October");} else if (sum==11) {printf ("November");} else if (sum==12) {printf ("December");} ELSE{PRINTF ("* * *");} return 0;}

  

3. Given a positive integer of not more than 6, consider 4 consecutive digits starting from a. Please output all 3 digits of the non-repeating number made up of them.

Input format: The input is given a in a row.

Output format: Outputs a 3-digit number that satisfies the criteria and requires 6 integers per line from small to large. Integers are separated by spaces, but there is no extra space at the end of the line.

Input Sample: 2

Output Sample: 234 235 243 245 253 254

324 325 342 345 352 354

423 425 432 435 452 453

523 524 532 534 542 543

#include <stdio.h> #include <stdlib.h>int main () {int a,b,c,d,e,f,i=0;printf ("Enter an integer that requires between 1-6: \ n"); (1) {scanf ("%d", &a); if (a>=7| | a<=0) {printf ("Input error, re-enter: \ n"); continue;} Else{system ("CLS"); break;}} printf ("The number entered is%d:\n", a), for (b=a;b< (a+4); b++) for (c=a;c< (a+4); C + +) for (d=a;d< (a+4);d + +) {f=b*100+c*10+d; if (b!=c&&c!=d&&b!=d) {i++;p rintf ("%d", f), if (i%6==0) {printf ("\ n");}}} return 0;}

  

4. Perpetual calendar, see commodity guessing price, automatic quiz, scissors game. (Completion of individual selected topics)

Scissors Games

#include <stdio.h> #include <stdlib.h> #include <math.h>int main () {char Gamer;int computer;int result , Score=0;while (1) {printf ("This is a scissors little game, please enter the punch you want out.") \ n ");p rintf (" A: Scissors \NB: Stone \nc: Cloth \nd: do not play \ n "); scanf ("%c ", &gamer); switch (gamer) {Case 65:case 97:gamer=4;break;case 66 : Case 98:gamer=7;break;case 67:case 99:gamer=10;break;case 68:case 100:return 0;default:printf ("Your choice for%c, select Error, exit. \ n ", gamer); GetChar (); System (" CLS "); return 0;break;}   Computer=rand ()%3;//gets 0~2 random number result= (int) gamer+computer;printf ("Computer out"), switch (computer) {case 0:printf ("Scissors \ n");   Break   Case 1:printf ("Stone \ n");   Break   Case 2:printf ("cloth \ n"); break;}   printf ("You Out"); switch (gamer) {Case 4:printf ("Scissors \ n");   Break   Case 7:printf ("Stone \ n");   Break   Case 10:printf ("cloth \ n"); break;} if (result==6| | result==7| | result==11) {printf ("you won.") \ n "); score++;} else if (result==5| | result==9| | result==10) {printf ("you lost.") \ n ");} Else{printf ("Draw. \ n ");} printf ("Go on to the next round of the game?" Reply N exit the game, reply to other continuation games. \ n "), scanf ("%c ", &gamer);p rintf (" battle sentimentStatus: \ n ");p rintf (" You scored%d ", score);}  return 0;}

  

Second, the Knowledge point summary (to the order structure, the choice structure, the circulation structure makes the synthesis summary)

1. header file #include<math.h> the use of the #include <stdlib.h>, four-digit transposition method, single-digit and 10 to seek redundancy, Chichong each other than 10 to take the remainder.

2. Output format Note that the first question of the new composition is the original number of four times times printf ("i*4==%d\n", I,new num);.

3. When programming the first to judge the situation, force the output, if the implementation of compliance, clear, clear thinking, examples of the second problem of the format, pay attention to the sentence inside the curly braces.

4. In the longer programming, the middle can use the Clear screen statement, System ("CLs");.

Third, the experimental summary (the problems encountered in the experiment and solutions)

1. The problem encountered in the first question is the use of curly braces, the IF statement of the loop nesting, in the future to pay special attention.

2. The second problem is the main use while statement

3. Do scissors game programming encountered more problems, and then solve is to determine the computer out fist, and then set a value for the player and the computer punch refers to the sum of values, and then make a judgment, and then the score situation also appeared error, the input time did not assign value, in the program also did not loop up, this is to pay attention to the place

Sixth time Assignment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.