Home > Back-end >  I am of the new, big help
I am of the new, big help

Time:09-18

From keyboard input their phone number, according to the mobile phone number after more than two to three o, according to their under-pressure sieve analyzer output group, grouping situation is: to pray for more than 1, 3 is the first group; For more than 3 o 2, that is, for the second group; For more than 3 o to 0, for the third group, namely
I was just an introduction to programming,, every brother please help to give directions, thank you

CodePudding user response:

The code is as follows:
 
# include & lt; Iostream>
using namespace std;

Int main ()
{
Char name [50].
int i=0;
int num;
cout <"Please enter the phone number:";
Cin> name;
While (the name [I]) + + I;
Num=name] [I - 1-48;
Num +=(name [2] I - - 48) * 10;
Cout<" Now is the first ";
The switch (num % 3)
{
Case 0: cout<" Three groups "& lt; Case 1: cout<" A set of "& lt; Case 2: cout<" Two groups "& lt; }
return 0;
}

Idea is, enter a string representing a phone number, and then find the end of the string, after a while, I will represent the '\ 0' position, then after the two natural is and I - I - 1, 2, will they add to the num integer variables, and then to take over operation of num, use the switch to branch output can complete the questions

CodePudding user response:

 # include & lt; stdio.h> 

Int main ()
{
Int ch1=0, ch2=0, ch.
int num;

Ch=ch1=ch2=0;
While ((ch=getchar ())! )='\ n' {
Ch2=ch1;//save the number the penultimate number
Ch1=ch;//save rent a number after
}
Printf (" % % c, c \ n ", ch1 and ch2);
Num=((ch2 - '0') * 10 + ch1 - '0') % 3.
Printf (" now is the first group % d \ n ", num==0? 3: num);
return 0;
}

Pure C language code, please test,
  • Related