Like Tree2Likes
  • 2 Post By rogster001

new C problem

This is a discussion on new C problem within the C Programming forums, part of the General Programming Boards category; Code: Hy. I need help with a problem. To display the first n numbers with figures amount less than or ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    6

    new C problem

    Code:
    Hy.
    I need help with a problem.
    
    To displaythe firstnnumberswithfiguresamountless than orequal tom.
    
    My code : 
    
    #include<stdio.h>
    int main()
    {
        int m, n, nr, p=1, s=0;
        printf("\n  n = ");
        scanf("%d", &n);
        printf("\n  m = ");
        scanf("%d", &m);
        printf("\n");
        while(nr)
          {
              nr=p;
              s+=nr%10;
              nr/=10;
              if(s<=m)
              printf(" %d", p);
              s=0; p++;
          }
        printf("\n");
    }
    
    Thank you.
    

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,403
    nr is not very useful for your while loop when it might contain 134129524564564 or -1002313812 or 0 or 2345234

    andidonthinkitisverygoodtowritequestionslikethisif youwantaproperanswer
    Last edited by rogster001; 02-09-2012 at 03:26 PM.
    Stevan and stahta01 like this.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    Code:
    Sorry.
    
    Hy.
    I need help with a problem.
    
    To  displaythe  firstnnumberswithfiguresamountless  than  orequal  tom.
    
    My code : 
    
    #include<stdio.h>
    int main()
    {
        int m, n, nr, p=1, s=0;
        printf("\n   n =  ");
        scanf("%d",  &n);
        printf("\n   m =  ");
        scanf("%d",  &m);
        printf("\n");
        while( nr )
          {
              nr = p;
              s += nr % 10;
              nr /= 10;
              if (s <= m)
              printf(" %d",  p);
              s = 0; 
              p++;
          }
        printf("\n");
    }
    
    
    

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,403
    well what can one say, april fools day and i just didnt know?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sleep() function problem or logic problem?
    By FernandoBasso in forum C Programming
    Replies: 7
    Last Post: 11-16-2011, 04:50 PM
  2. strcmp problem, whats the problem, i cant figure it out!
    By AvaGodess in forum C Programming
    Replies: 14
    Last Post: 10-18-2008, 06:45 PM
  3. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  4. Visual Studio Linker problem or my problem?
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-13-2004, 12:32 AM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21