Question

C Programming Language

Jo Number Jojo likes Jo numbers. A Jo numbers are positive integers whose decimal representation contains only 7 and 8. For example, 8 and 778 are Jo while 18 and 286 are not. Jojo calls a number semi-Jo if it could be evenly divided by some Jo number. Given integer N, help him find out if its an semi-Jo number Format Input The input begins with an integer T indicating the number of test cases. In each test case, there is an integer N, the number that needs to be checked Format Output For each test case, output YES if number N is semi-Jo. Otherwise, output NO Constraints 1N <- 1000000000 Sample Input Sample Output Case #1: YES Case #2 : YES Case #3: NO 28 5605

The code below matches the sample input/output but is marked wrong. Are there other ways to do this problem? The focus is on recursion and functions.

#include<stdio.h>

int joCheck(unsigned long long int number)

{

if(number % 7 == 0 || number % 8 == 0)

{

return 1;

}

else return 0;

}

int main()

{

int cases = 0;

scanf("%d", &cases);

for(int i = 1; i<=cases; i++)

{

unsigned long long int number;

scanf("%d", &number);

if(joCheck(number) == 1)

{

printf("Case #%d: YES ", i);

}

else printf("Case #%d: NO ", i);

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

int joCheck(unsigned long long int number)

{

if (number % 7 == 0 || number % 8 == 0)

{

return 1;

}

else

return 0;

}

int main()

{

int cases = 0;

unsigned long long int number;

printf("enter the number of cases \n");

scanf("%d", &cases);

for(int i = 1; i<=cases; i++)

{

printf("enter number \n");

scanf("%d", &number);

if (joCheck(number) == 1)

{

printf("Case #%d: YES\n", i);

}

else printf("Case #%d: NO \n", i);

}
return 0;
}

The second method is

#include<stdio.h>

int isDivisibleBy7( int num )
{

// If number is negative, make it positive

if ( num < 0 )

return isDivisibleBy7( -num );

  

// Base cases

if ( num == 0 || num == 7 )

return 1;

if ( num < 10 )

return 0;

  

// Recur for ( num / 10 - 2 * num % 10 )  

return isDivisibleBy7( num / 10 - 2 * ( num - num / 10 * 10 ) );
}

int isDivisibleBy8( int num )
{

// If number is negative, make it positive

if ( num < 0 )

return isDivisibleBy8( -num );

  

// Base cases

if ( num == 0 || num == 8 )

return 1;

if ( num < 10 )

return 0;

  

// Recur for ( num / 10 - 2 * num % 10 )  

return isDivisibleBy8( num / 10 - 2 * ( num - num / 10 * 10 ) );
}

int main()

{

int cases = 0,se,ei;

unsigned long long int number;

printf("enter the number of cases \n");

scanf("%d", &cases);

for(int i = 1; i<=cases; i++)

{

printf("enter number \n");

scanf("%d", &number);

se=isDivisibleBy7(number);

ei=isDivisibleBy8(number);

if (se==1|ei==1)

{

printf("Case #%d: YES\n", i);

}

else printf("Case #%d: NO \n", i);

}
return 0;
}

6:10 PM 1.95K/s TAB enter the number of cases enter number Case #1: YES enter number 28 Case #2: YES enter number 5605 Case #3: No Program finished]

6:10 PM 1.95K/s TAB enter the number of cases enter number Case #1: YES enter number 28 Case #2: YES enter number 5605 Case #3: No Program finished]

Add a comment
Know the answer?
Add Answer to:
C Programming Language The code below matches the sample input/output but is marked wrong. Are there...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C Programming Language Problem Title: Discount Jojo is browsing the internet while suddenly he sees an...

    C Programming Language Problem Title: Discount Jojo is browsing the internet while suddenly he sees an ad about the new cafe. The promotion is if the price of an item is N dollars, then you can buy the second item for half the price, the third item for a quarter of the original price, and so on, but if it becomes less than M dollars, then you have to pay M dollars. He wonders how much he has to pay...

  • C Programming Language Problem Title: Jojo’s Hardest Problem (?) Jojo is enjoying his vacation with his...

    C Programming Language Problem Title: Jojo’s Hardest Problem (?) Jojo is enjoying his vacation with his family. Suddenly an instant message came in. Apparently there is a message from Lili : ”Jojo, don’t forget to check the forum. Who knows if there is an assignment before the exam” Jojo finally took the time to check the discussion forum and sure enough, there were some assignments given to his class. He immediately told his classmates. Jojo finds out one difficult problem...

  • Java code INNER PRODUCT 4E Input Standard input Output Standard output Topic Array & Array Processing!...

    Java code INNER PRODUCT 4E Input Standard input Output Standard output Topic Array & Array Processing! Problem Description The inner product (also known as the dot product or scalar product) of the elements of set A and the elements of set B of size is defined as the sum of the products of corresponding terms. For example, given set A as the array (2, 3, 4, 5, 6, 7, 8, 9; and set B as 6,5, 4, 3, 2, 7,...

  • Java code ABOVE AVERAGE 40 Input Standard input Output Standard output Topic Array & Array Processing...

    Java code ABOVE AVERAGE 40 Input Standard input Output Standard output Topic Array & Array Processing Problem Description Understanding how to interpret test scores is a valuable skill for every teacher. That's because test score interpretation enables teachers to understand how their students' performance for each tests of the course. Average test score is one of the indicators to determine the class performance for the test. For each test, we need to calculate the average score and determine the percentage...

  • Write in C language . Thank you Count Sheep Jojo is having problem to sleep at...

    Write in C language . Thank you Count Sheep Jojo is having problem to sleep at night. He can't fall asleep and it makes him feel tired every day. Having this problem, Jojo told his friend Bibi, and Bibi advised him to do sheep counting while he tries to sleep. Jojo decided to try using this trick for N nights, to test its effectiveness. Jojo realized that he would fall asleep if he imagined a total of 10 white sheep....

  • write in C language Decoration Lights Jojo is currently working in an office as a security....

    write in C language Decoration Lights Jojo is currently working in an office as a security. Every night, after everyone returned home, he needs to make sure all decoration lights in the office is turned off. The decoration lights are unique: each of them has a timer that will switch the light on or off every two seconds. The lights are also arranged so well that each two neighboring lights will have different state (on/off). As long as the timer...

  • C language Thank you Jojo is going to a restaurant. There are N foods listed in...

    C language Thank you Jojo is going to a restaurant. There are N foods listed in the menu, and the items are sorted increasingly based on its price. Now Jojo is wondering how many foods are there with price P. As the number of food in the menu can be a lot, Jojo will need your help to answer his questions. Jojo knows you can count really fast, so he will give you M questions. Format Input Input begins with...

  • Java code COCONUT KELAPA4 4A. Input Standard input Output Standard output Topic Array & Array Processing...

    Java code COCONUT KELAPA4 4A. Input Standard input Output Standard output Topic Array & Array Processing Problem Description Ali Wali owns a coconut plantation and a number of monkeys for bringing down coconuts. Every day, Ali would record the number of coconuts brought down by his monkeys. At the end of a certain time period, he would determine from the data recorded, the lowest and the highest number of coconuts as well as their number of occurrences. Write a program...

  • Programming C....... function code is clear but compile is wrong .. I input 8 and compiled...

    Programming C....... function code is clear but compile is wrong .. I input 8 and compiled 2 0 1 1 2 3 5 8 13.. look first number 2 is wrong. The correct answer 8 is 0 1 1 2 3 5 8 13 21.. Need fix code to compile correctly.. Here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[1000]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for (...

  • C Programming Language Problem Title: Introduction to Computer Vision Jojo is an outstanding student who is...

    C Programming Language Problem Title: Introduction to Computer Vision Jojo is an outstanding student who is currently pursuing his Computer Science degree. In one of his Computer Vision lectures, his lecturer tackled a topic about binary thresholding. For simplicity, binary thresholding is an image filtering method used to separate low val- ued pixels (dark) from high valued pixels (bright). Each pixels in an image is classified as low or high based on a certain threshold K. If a pixel Pij...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT