+ Reply to Thread
Results 1 to 6 of 6

Thread: C programming

  1. #1
    ChatIndia's Avatar
    ChatIndia is offline Community Advocate ChatIndia is on a distinguished road
    Join Date
    Sep 2009
    Location
    Exam Time. I won't tell you
    Posts
    1,320

    C programming

    Code:
    #include <stdio.h>
    main()
    {
    int r,s;
    printf("Enter Roll Number\n");
    scanf("%d",&r);
    printf("Enter Serial Number\n");
    scanf("%d",&s);
    system("clear");
    printf("%d\n",r);
    printf("%d\n",s);
    }
    When I enter Roll No = 3332810074 and Serial Number = 14 the output roll number is wrong and the output serial number is right. Can you help me to detect the error.
    Your appreciation is extremely Important. Click on the button at the bottom left corner of my post.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: C programming

    if int ---> unsigned int ---> max value 2147483647 ...
    Nothing is always absolutely so.

  3. #3
    ChatIndia's Avatar
    ChatIndia is offline Community Advocate ChatIndia is on a distinguished road
    Join Date
    Sep 2009
    Location
    Exam Time. I won't tell you
    Posts
    1,320

    Re: C programming

    so what should i use for a number up to 4000000000
    Your appreciation is extremely Important. Click on the button at the bottom left corner of my post.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: C programming

    Assuming you are only going to have positive numbers, unsigned int should work.
    Nothing is always absolutely so.

  5. #5
    LostHorizon's Avatar
    LostHorizon is offline x10Hosting Member LostHorizon is an unknown quantity at this point
    Join Date
    Dec 2010
    Posts
    35

    Re: C programming

    For your information:

    short, unsigned short -- 2 bytes
    int, unsigned int -- 4 bytes
    long, unsigned long -- 4 bytes

    (http://msdn.microsoft.com/en-us/libr...(v=VS.71).aspx)


    NOTES:
    1. The maximum value of any UNSIGNED integer type = (2 ^ number of storage bits) - 1. Hence:

      the maximum value of unsigned short = (2 ^ 16) - 1 = 65,535 (0xFFFF),
      the maximum value of unsigned int & unsigned long = (2 ^ 32) - 1 = 4,294,967,295 (0xFFFFFFFF).

    2. Also, the maximum value of any SIGNED integer type = (2 ^ (number of storage bits - 1)) - 1. Hence:

      the maximum value of signed short = (2 ^ 15) - 1 = 32,767,
      the maximum value of signed int & signed long = (2 ^ 31) - 1 = 2,147,483,647.
    Hope this helps.
    Website: http://losthorizon.cz.cc/

    "Genius is one percent inspiration and ninety-nine percent perspiration" -- Thomas Alva Edison.

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: C programming

    Quote Originally Posted by LostHorizon View Post
    long, unsigned long -- 4 bytes
    That's only to be expected on a 32-bit machine, or when using a Microsoft compiler. For example, a long on a 64-bit machine running Linux in a program compiled in 64 bit mode will use 8 bytes. To get the minimum and maximum integer values on a system, consult limits.h.
    Last edited by misson; 08-15-2011 at 03:55 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Help, I don't know programming!!!
    By aircar in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 11-20-2009, 09:58 AM
  2. Need help in programming with vb6
    By lordskid in forum Computers & Technology
    Replies: 2
    Last Post: 05-15-2008, 03:31 AM
  3. New in the web programming
    By oregonsv in forum Introductions
    Replies: 3
    Last Post: 11-15-2007, 05:59 AM
  4. PHP Programming!!
    By darkuranium in forum The Marketplace
    Replies: 4
    Last Post: 11-25-2005, 04:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers