repl.it
@SylvianBryan/

Number Enter, Returns as an Int and Float

C

No description

fork
loading
Files
  • main.c
  • main
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Student Number: Nxxxxxxxx
Coder: Sylvian Bryan 
Date: 20019/04/12
Title: Convert Number'
Description: Whole to decimal number, return whole number. 
*/

#include <stdio.h>

void convert (float a, int* b, float* c);// function   

int main(void) 
{

int num;// Number entered is stored here 

//function declarations 
float one;//reflects variable type a "float a"  in function 
int two;//reflects variable type pointer b "int* b" in function  
float three;//reflects variable type pointer c "float* c" in function

printf("Enter a Number:");
scanf("%d", &num); 

convert(num, &two, &three);// Ampersand is used to send address to "int* b,  float* c" 

printf("\n%d \n%.3f", two, three);   

return 0;
}

void convert(float a, int*b, float* c)// Function that convert the numbers
{ 

// Number is brought in as a decimal number.  
*b=(int)a;// "b* in-direct points by putting case "(int)a"
*c=a-*b; //"*c" in-direct points by putting substraction expression.  

}