Help me to write this program please.
Help me to write this program please.
Please refer to the homework policy.
Hmmm.
As a clue I would mention modulus again.
that's the remainder.Code:if (m%k==0)
I'm sorry.But it is not homework.It was old examination ( examination of 2007 ) so don't have the answer.Thus, I would like to ask the answer here.
Great. I am now assigning it to you as homework. Carry on and do your homework, and then post your attempt here so we can grade it and offer suggestions for improvement.Quote:
Originally Posted by Danlittleboy
Wow, 16MB in which to do it as well.
That's what I thought...
Omg !!!!
"Hey dude, could you build free house for me?" Pointless to even ask, when you know the answer or maybe there really is a santa claus out there...
- For the second point you could try converting (a copy of) the number to a character array & test each digit individually.
- s < 1e19
- use modulus
Good luck, concentrate on doing one point at a time, not worrying about the limitations, then optimise.
Wow, that homework is so easy, and you have a whole second to do it in...
So like, do you not understand the problem? Or are you having a problem with your code?
Basically its asking you to return some number OUTPUT (aka S) of which INPUT (aka N) is a factor, and S has to contain only the decimal digits 7 2 and 0.
I see two obvious ways to attack this problem. Either test successive multiples of n until you find one with the right digits, or recursively generate all acceptable combinations of the allowed digits until you find one with a zero remainder.
Either way, you'd need a 64-bit data type to do it since the problem description allows up to 20 digits.
Well, that's just off the top of my head anyway.
The best way to solve it is to try. Don't try and pretend, after being reminded of the homework policy, that it isn't homework. So many people do this that we get enough practice to see right through it every time.
yes or noCode:
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
void main(void)
{
unsigned long inp,out;
int NumString,nub=0,answer,Mod1,Mod2,Mod3;
char string[10];
printf("Enter input : ");
scanf("%d",&inp);
printf(" ");
for(out=1;out<=4000000;out++)//unsign long = 4294967
{
nub=0;//Reset nub=0
answer=out%inp;//Mod =0
if(answer==0)
{
ultoa(out,string,10);//change unsigned long to string
NumString=strlen(string);//Length of string
for(int i=0;i<=NumString;i++)//Loop
{
Mod1=(string[i]=='7');//check char compare 7,2,0
Mod2=(string[i]=='2');
Mod3=(string[i]=='0');
if((Mod1||Mod2||Mod3)==1)//if it has 7,2,0
nub++;//add value
}
if(nub==NumString)//check Length
{
printf("Output is %s ",string);//output
exit(1);//Exit loop
}
}
}
if(nub==0)//case : not output
{
printf("Nav or Not output ");
}
}
its not yes or no question its your homework:)
Does this compile?
If no, what errors do you get? What do you think might be causing this?
If yes, does it work as intended?
If no, in what way? What do you think might be causing this?
If yes, congratulations!