Thread: Help me pleaseeeeeee ,I have a very hard problem in C language.

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    4

    Help me pleaseeeeeee ,I have a very hard problem in C language.

    Help me to write this program please.
    Last edited by Danlittleboy; 02-18-2009 at 12:39 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Please refer to the homework policy.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Hmmm.

    As a clue I would mention modulus again.
    Code:
    if (m%k==0)
    that's the remainder.
    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

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    4
    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.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Danlittleboy
    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 Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    That's what I thought...

  8. #8
    Registered User
    Join Date
    Feb 2009
    Posts
    4
    Omg !!!!

  9. #9
    Registered User
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    14
    "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...

  10. #10
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    - 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);

  11. #11
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    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.

  12. #12
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    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"

  13. #13
    Registered User
    Join Date
    Feb 2009
    Posts
    4
    Code:
    #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 ");
     }
    }
    yes or no

  14. #14
    Registered User
    Join Date
    Feb 2009
    Posts
    10
    its not yes or no question its your homework

  15. #15
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem and Solution
    By DavidP in forum Tech Board
    Replies: 3
    Last Post: 08-18-2003, 02:23 AM
  2. hard drive problems continually increasing
    By DavidP in forum Tech Board
    Replies: 5
    Last Post: 11-21-2002, 10:48 PM
  3. Hard Drive Problem
    By MethodMan in forum Tech Board
    Replies: 3
    Last Post: 10-08-2002, 05:13 PM
  4. Hard Problem :(
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-13-2002, 03:16 AM
  5. What can I do?
    By Unregistered in forum C++ Programming
    Replies: 27
    Last Post: 07-16-2002, 11:44 PM