Did you know that in lotteries, a 3-digit number with the same numbers in all digits like 777 will hit the jackpot in a casino? In the same manner, let's make a program that will test if a certain 3-digit number hits a jackpot or not by identifying if all the digits of a given number is the same as the second inputted number. If it is, print "Jackpot!"; else, print "Nah".
Let's try this out now!
Input
A line containing two integers separated by a space.
777·7
Output
A line containing a string.
Jackpot!
#include <stdio.h>
#include <stdlib.h>
int main(){
char digitNumbers[4];
char digit;
int i;
int counter=0;
scanf("%s %c",digitNumbers,&digit);
for(i=0;i<3;i++){
if(digitNumbers[i]==digit){
counter++;
}
}
if(counter==3){
printf("Jackpot!\n");
}else{
printf("Nah\n");
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment