topics are as follows:
Lucky lottery
Lottery number has 6 digits, if a lottery ticket on the former three on three several must equal the sum of the number, says that the ticket is lucky, please bear on the judgment of the given lottery is lucky,
Input format:
Input in the first row is given a positive integer N (100) or less, then N rows, each row is given a lottery ticket 6 digits,
The output format:
For each ticket, if it is lucky, in the output You are in the line of lucky! ; Otherwise the output Wish you good luck.,
Input the sample:
2
233008
123456
The output sample:
You are lucky!
Wish you good luck.
# include "stdio.h"
Int main ()
{
Int n, a [100], [6], I, j, sum1=0, sum2=0;
The scanf (" % d ", & amp; N);
For (I=0; I & lt; N; I++)
The scanf (" % d ", & amp; A [I]);
For (I=0; I & lt; N; I++)
{
Sum1=0, sum2=0;
For (j=0; J & lt; 6; J++)
{
If (j & lt;
=2)Sum1 +=a, [I] [j].
The else
Sum2 +=a, [I] [j].
}
If (sum1==sum2)
Printf (" You are lucky! \n");
The else
Printf (" Wish you good luck. \ n ");
}
return 0;
}
CodePudding user response:
# include & lt; stdio.h>
Int main ()
{
# if 0
int i, j;
Int num, n, sum1, sum2;
The scanf (" % d ", & amp; N);
For (I=0; I & lt; n; I++) {
The scanf (" % d ", & amp; Num);
J=sum1=0;
While (j & lt; 3) {
Sum1 +=num % 10;
Num/=10;
j++;
}
Sum2=0;
While (num) {
Sum2 +=num % 10;
Num/=10;
}
Printf (" sum=% d, sum2=% d \ n ", sum1, sum2);
If (sum1==sum2) {
Printf (" You are lucky! \n");
} else {
Printf (" Wish you good luck. \ n ");
}
}
# the else
# define MAX_NUMS 100
Int n, a, [MAX_NUMS].
Int I, j, sum1=0, sum2=0;
The scanf (" % d ", & amp; N);
If (n & gt; MAX_NUMS)
N=MAX_NUMS;
For (I=0; I & lt; N; I++)
The scanf (" % d ", & amp; A [I]);
For (I=0; I & lt; N; I++)
{
Sum1=0, sum2=0;
For (j=0; J & lt; 6; J++)
{
If (j & lt;
=2)Sum1 +=a [I] % 10;
The else
Sum2 +=a [I] % 10;
A [I]/=10;
}
If (sum1==sum2)
Printf (" You are lucky! \n");
The else
Printf (" Wish you good luck. \ n ");
}
# endif
return 0;
}
For your reference ~
CodePudding user response:
For (I=0; I & lt; N; I++)The scanf (" % 1 d ", & amp; A [I]);
CodePudding user response:
Integer need to deal with, can directly take over, see you define should be want to define a ballast a number, a number six in the address, but is unable to do so, even if you define char individual can lose in character also need to be processed into digital computing, or int type Numbers stored separately, but then you are saved six Numbers is not a numberCodePudding user response: