Thread: need to solve simple c problem

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    8

    Exclamation need to solve simple c problem

    Problem Name: Y = MX
    Everyone know that the equation of a straight line is Y = MX + C. But if C = 0, then the straight line is passing through the origin. Here I always put C = 0. So our equation will be always Y = MX. Straight line is a geometrical term but my problem is not geometrical. I just use the equation Y = MX. Since Y = MX, so Y is must be divisible by M and X, and for a specific value of Y and various value of M and X, the equation must be satisfy.
    But in this problem we find (N) the number of M and X that satisfy the equation with condition M must be less than X (M16 = 1 * 16 (1<16) so it is countable.
    16 = 2 * 8 (2<8) so it is countable.
    16 = 4 * 4 (4 = 4) so it is not countable.
    16 = 8 * 2 (8>2) so it is not countable.
    16 = 16 * 1 (16>1) so it is not countable.
    So our answer N=2.

    So your duty is to find out how many way to find M and X (M
    Input: You have to provide an integer Y (1<=Y<=10000).

    Output: You just print the value of N.

    Sample input:
    16

    Sample output:
    2

    what output i'll get for following those input 128,500,666,1000,10000?
    i need code and solution

    i tried many time but can't get logic. how i improve my logic?
    help to clera this program logic concept. ... Shift+R improves the quality of this image. Shift+A improves the quality of all images on this page.
    Code:
    #include<stdio.h>
    int main()
    {
        
        int a,b,c=1,i;
        scanf("%d",&a);
        for(i=2;i<=a;i+=2)
        {
            if((a%i)==0)
            {
            printf("%d ",i);
            b=(a%i);
            }
    
            if(b>i)
             c++;
    
        }
    
        printf("\n%d",c);
    }
    Last edited by raihan004; 09-15-2012 at 02:00 PM.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    i need code and solution
    Are you joking? please read the forum FAQ.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    Quote Originally Posted by root4 View Post
    Are you joking? please read the forum FAQ.
    sorry am new. can't i ask any problem solution code ? what is my fault?

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    can't i ask any problem solution code ?
    Indeed. You can get some help, here, with programming issues, but nobody is going to solve any assignment.
    Work on your problem first, show us some code and possible problems you face, then we'll help.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I have been feverishly looking for a silver platter with a gold rim - something suitable for the delivery of this code and solution.

    All in vain.

  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
    You can only get so far by looking at code.
    The real learning starts when you actually try and write some yourself.

    Make an actual effort, and then we'll help you.
    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
    Sep 2012
    Posts
    8
    now i inlcude my tried attetmp code . now make me my code fullfill and make clear concept

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    1. Your assignment gives you explicit names for the objects so use them in your code, that gives a readability bonus (e.g. what you named "a" is "y").
    2. Indent correctly your code.

    You have all the pieces, but not composed correctly: to increment your counter (c), Y has to be divisible by your current M (Y%M==0) and that M must be less than (Y/M) so you have to merge your two conditionals.
    I don't know why you increment M by 2.
    Last edited by root4; 09-15-2012 at 03:04 PM.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    The problem comes from asking the equivalent of "do it for me" when you should be asking the equivalent of "teach me".
    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"

  10. #10
    Registered User
    Join Date
    Sep 2012
    Posts
    8

    Cool [solved] problem solve

    i solve this problem . if any wrong about my logic please repaly or notify me thanks all
    Code:
      
    
    #include<stdio.h>
    int main()
    {
    
        int y,m,n=0,i,x=0;
        scanf("%d",&y);
        for(i=1;i<=y;i++)
        {
            if((y%i)==0)
            {
    
    
    x=y/i;
    
            if(x>i)
            {
                printf("%4d",i);
             n++;
            }
            }
        }
    
        printf("\ntotal %d step need to do this",n);
    }
    
    :redface:

  11. #11
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    Looks ok.
    Indent your code properly.
    You can merge the two conditionals with a logical 'and' operator (&&).
    Your variable 'm' is unused so far, simply replace 'i' with 'm'.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. switch statement. simple to solve but i dunno whats wrong.
    By ingeniousreader in forum C Programming
    Replies: 2
    Last Post: 05-17-2012, 09:43 AM
  2. C++problem to solve
    By truetrini20 in forum C++ Programming
    Replies: 9
    Last Post: 06-29-2010, 03:19 AM
  3. Simple loop problem I cant seem to solve
    By LightYear in forum C Programming
    Replies: 8
    Last Post: 03-21-2010, 06:59 PM
  4. simple i/o error that I cannot solve
    By CodeMonkey in forum C++ Programming
    Replies: 10
    Last Post: 12-17-2006, 04:07 PM
  5. problem cant solve please help.
    By sarah in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 01:32 PM

Tags for this Thread