program without usingfunctions from math library

Hello,Good day!
I am trying to make a program that is about to accept number and display it's floor and ceiling value.Here's the example of the output

Enter number: 5.7
Floor of 5.7 is 5
Ceiling of 5.7 is 6
Do you want to quit? <y/n>: y
//end

My main problem here is that i dont know how to get the floor and ceiling value without using functions from math library ..

Its a great pleasure for those who can help me..Thanks in advance:)
To get the floor cast the number to int
To get the ceiling add 1.0 and cast to int
closed account (18hRX9L8)
Example:

test.h
1
2
3
4
5
6
7
#include <iostream>

void test(void);
void test(void)
{
     std::cout<<"is a test."<<std:endl;
}


test.c
1
2
3
4
5
6
7
#include "test.h"

main()
{
      std::cout<<"This program ";
      test();
}


New test.c without functions
1
2
3
4
5
6
7
#include <iostream>

main()
{
     std::cout<<"This program ";
     std::cout<<"is a test."<<std::endl;
}


1. Find function from library.
2. Copy function insides.
3. Paste it where you call the functions.
4. Switch your variables with library variables. (If there are any/if they are different.)
Last edited on
> i dont know how to get the floor and ceiling value without using functions from math library

For a beginner's exercise, something like this should be acceptable:

1
2
3
double floor( double v ) { return v < 0 ? -int(-v) - 1 : int(v) ; }

double ceil( double v ) { return int( floor(v) + 1 ) ; }


> To get the ceiling add 1.0 and cast to int
No.
if n \in Z, the ceiling and the floor are the same number.
Topic archived. No new replies allowed.