Write a program that calls a function to scale a real number
Write a program that calls a function to scale a real number x into its scientific notation so that 1 lessthanorequalto x
Solution
#include <stdio.h>
void sci_notation(double *x, int *n); //prototype
int main(){
double x = 0.00025; //any random value
int n = 0; //initializing n
sci_notation(&x, &n); //calling function
printf(\"%f\", x);
printf(\"\ %d\", n);
}
void sci_notation(double *x, int *n){
while (*x>=10){ //loop if x>10
*x = *x/10.0;
*n = *n - 1;
}
while(*x<1){ //loop if x<1
*x = *x * 10;
*n = *n + 1;
}
}
