C Programming Language
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);
}
}
#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]
C Programming Language The code below matches the sample input/output but is marked wrong. Are there...
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...
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 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....
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,...
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 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...
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...
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 (...
Here is the code I made, but the test case is not working, it goes wrong when the binary string convert to decimal. please help. #include "stdafx.h" #include <iostream> #include <string> #include <math.h> #include <locale> using namespace std; // function for option 1 void decToBin(int number) { int array[16]; int i = 0; for (int counter = 0; counter < 16; counter++) { array[counter] = 0; } while (number > 0) {...
The programming language has to be C. Do you remember rand()? Do you remember how it can use srand() for a seed? Did you know that rand uses that seed as the initial state of their random number generator. Did you know that a random number generator is really a deterministic sequence generator? Yeah! So your next random number might be calculated using a recursive equation like: rand_n = rand_(n-1) * coeffecient1 + coeffecient2 That is the random number produced...