need some help with a c program

Discussion in 'OT Technology' started by conduit, Sep 25, 2006.

  1. conduit

    conduit sup

    Joined:
    Oct 27, 2001
    Messages:
    7,023
    Likes Received:
    0
    Location:
    on the interwebs
    I have a c programming class in college using powerc and for our first lab it asks us to display some numbers in hex notation, and play around with field width and the percision.
    I got that with out a problem, but than it asks us to display the largest possible value in variable number 1 and display it. I know how to display it with printf but how do i put the largest possible value in variable number1?

    Here is the little program.

    #include <stdio.h>
    /int main(void){
    int number1, number2;
    float number3, number4;
    number1 = largest value;
    number2 = 123;
    number4 = 23.345987;
    number3 = 1456.2;
    printf("%5d %x %7.2f %7.2f\n", number1, number2, number3, number4);
    printf("The number of bytes in a signed integer is %d\n", sizeof(number1));
    system("PAUSE");
    return 0;

    }

    /*


    Thanks for the help

    When i asked the teacher what he ment he went on saying the number of 2^16 - 1 so 65535
     
  2. kilamasta

    kilamasta New Member

    Joined:
    Aug 14, 2006
    Messages:
    108
    Likes Received:
    0
    #include <stdio.h>
    #include <stdlib.h>
    int main(void)
    {


    unsigned int number1;
    int i;

    number1=2;
    i=sizeof(number1)*8;

    while(i>1)
    {
    number1*=2;
    i--;
    printf("\n%u",number1);
    }

    number1--;
    printf("\nBiggest value a int can take : %u=%x hex\n",number1,number1);
    system("PAUSE");
    return 0;

    }
     
    Last edited: Sep 26, 2006
  3. StevesVR4

    StevesVR4 Get Arrested

    Joined:
    Jul 1, 2003
    Messages:
    7,328
    Likes Received:
    0
    Add these to your program in the appropriate places:
    Code:
    #include <limits.h>
    
    int number1 = INT_MAX;
     

Share This Page