Help me to write this program please.
Help me to write this program please.
Last edited by Danlittleboy; 02-18-2009 at 12:39 PM.
Please refer to the homework policy.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Hmmm.
As a clue I would mention modulus again.
that's the remainder.Code:if (m%k==0)
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
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.Originally Posted by Danlittleboy
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Wow, 16MB in which to do it as well.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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.
long time no C; //seige
You miss 100% of the people you don't C;
Code:if (language != LANG_C && language != LANG_CPP) drown(language);
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.
Last edited by iMalc; 02-21-2009 at 06:04 PM.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
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!