Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- /* function prints "hello" */
- /*declaration */
- void print_hello();
- /* function prints current year */
- void print_current_year();
- /* function prints the specific year */
- void print_this_year(int y);
- /* function tells, if value 1 can be divided by value 2 */
- void can_that_be_divided(int v1, int v2);
- /* function rounds a decimal value with given decimals, value is printed then */
- void round_up_this(double value, int decimals);
- /* function rounds a decimal value with given decimals and returns the result */
- double round_up_this_and_return(double value, int decimals);
- int main()
- {
- /* call */
- print_hello();
- print_current_year();
- print_this_year(2020);
- can_that_be_divided(6,3);
- round_up_this(23.45555 ,2);
- double result = round_up_this_and_return(1234.6666,2);
- printf("result is %lf \n",result);
- printf("result is now %lf \n", round_up_this_and_return(8.8888,3));
- double x = 345.678;
- int d = 3;
- print("result is now %lf \n",round_up_this_and_return(x,d));
- return 0;
- }
- double round_up_this_and_return(double value, int decimals)
- {
- int p = 1;
- int k;
- for (k = 0; k < decimals; k++);
- p = p * 10;
- value = (int)(value * p + 0.5)/(1.0*p);
- return value;
- }
- void round_up_this(double value, int decimals)
- {
- int p = 1;
- int k;
- for (k = 0; k < decimals; k++);
- p = p * 10;
- printf("%d \n",p);
- value = (int)(value * p + 0.5)/(1.0*p); /* 23.444 => 2344.4 + 0.5 => 2344.9 */
- printf("result is %lf \n",value);
- /* 23.45555 => 2345.55 => 2346.15 => 2346 => 23.46 */
- }
- void can_that_be_divided(int v1, int v2)
- {
- if (v1%v2 == 0)
- printf("yeah \n");
- else
- printf("nope \n");
- }
- void print_this_year(int y)
- {
- printf("%d \n", y);
- }
- void print_current_year()
- {
- printf("2017 \n");
- }
- /* definition, implementation */
- void print_hello()
- {
- printf("hello \n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement