Results 1 to 6 of 6

Thread: Ceil function in C

  1. #1
    Join Date
    Aug 2006
    Posts
    148

    Ceil function in C

    I am not having much knowledge about the C language, so thought asking you guys will might solve my problem. I am trying to get the ceil function working in Dev-C++. And I am using the C language for that. I know that the Dev-C++ is compatible for C and C++ languages. When I type in a recognized word for example int or double it turns bold. But when typing in the ceil function it does not turn bold, I am including the <math.h> header file.!! Why is it that i can't seem to get it to work what am i doing wrong.?? Is it that its not a proper function in Dev-C++?? Please help me for solving the issue.
    The Gaming Machine:
    Processor: Core 2 Duo E6400
    Motherboard: Asus P5W DH Deluxe
    RAM: 2GB XMS2 Corsair PC2-6400
    Video: ATI Radeon X1900XT 512MB w/ Arctic Accellero
    Drive: 74GB "WD Raptor" 10000RPM
    Sound: Creative SoundBlaster X-Fi
    Watercooling: *Soon* Zalman Reserator

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Ceil function in C

    You can use the following example of the Ceil Function :
    Code:
    /* ceil example */
    #include <stdio.h>
    #include <math.h>
    
    int main ()
    {
      printf ("ceil of 2.6 is %.1lf\n", ceil (2.6) );
      printf ("ceil of 3.7 is %.1lf\n", ceil (3.7) );
      printf ("ceil of -2.6 is %.1lf\n", ceil (-2.6) );
      printf ("ceil of -3.7 is %.1lf\n", ceil (-3.7) );
      return 0;
    }
    Check using this example and I am sure that your problem will be fixed.

  3. #3
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Ceil function in C

    I was facing the similar problem in C language. Later I realized that the problem was coming because I set my variable x of ceil(x) as int. I then set that variable x of ceil(x) as double. So when I input a double number, it was reading the first digit only, leaving me the incorrect output. Hope that will help too. I don't think that there is some problem with your Dev-C++. Since it is good compiler and supports both C and C++ language. I think that you will have to make some changes in your code.

  4. #4
    Join Date
    Mar 2008
    Posts
    672

    Re: Ceil function in C

    Even I don't think that your Dev-C++ is having some problem. Even if you think that there is some problem with that then try to reinstall the application. You can also the following code, which can fix your problem.
    Code:
    #include <math.h>
    
    double result = ceil( 0.5 );
    // result now contains 1.0.

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Ceil function in C

    I am providing you with an another example. Hope that it helps you. Here is the code for that :
    Code:
    int CEIL(double var)
    {
    int integer = (int)var;
    if(var - integer == 0) return integer;
    else return integer + 1;
    }
    Also you can write your own macro, if you think that compiler is causing some issue. It will look like this :
    Code:
    #define CEIL(VARIABLE) ( (VARIABLE - (int)VARIABLE)==0 ? (int)VARIABLE : (int)VARIABLE+1 )

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: Ceil function in C

    I have tried to do declare an array (arr[4]) and use ceil and floor function. The result came out fine, if the number is not zero. Here is the coding for that :
    Code:
    # include <math.h> 
    int main(){
    float arr[4],c[4];
    int i;
     
    arr[0]=-2.828427; arr[1]=-0.707107; arr[2]=0.000000;arr[3]=-0.707107;
     
    for (i=0;i<4;i++){
    c[i]=ceil (arr[i]);
    printf ("%f\n",c[i]);
    }
      
    }
    Hope that you will get some hint after looking at this example.

Similar Threads

  1. c++ equivalent function to the c-function 'sprintf
    By Dilbert in forum Software Development
    Replies: 6
    Last Post: 13-12-2011, 04:03 PM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  4. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  5. Function keys don't function under windows XP
    By GunFighter in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-04-2009, 11:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,293,585.26412 seconds with 17 queries