using c programming please 1 Write a program that calls a fu
using c programming please 1
Write a program that calls a function to scale a real number x into its scientific notation so that 1 lessthanorequalto x lessthanorequalto 10. The amount that x is shifted should be stored into the second argument. Each argument is pass-by-reference. The following function prototype is required. void sci_notation(double *x, int *n); Here is an example of when n would be negative Enter number: 2459.1 x: 2.459 n: -3 Here is an example of when n would be positive Enter number: 0.0002591 x: 2.591 n: 4Solution
#include \"stdio.h\"
void sci_notation(double *x,int *n){
while(*x>10){ // while number greater than 10.
*x = *x / 10; // divide by 10.
*n = *n-1;
}
while(*x<=1){ // while number less than 1.
*x = *x * 10; // multiply by 10.
*n = *n+1;
}
return;
}
int main(void) {
double x;
int n = 0;
printf(\"Enter number:\");
scanf(\"%lf\",&x);
sci_notation(&x,&n); // call the function.
printf(\"x:%f\ n:%d\ \",x,n);
return 0;
}
/*
sample output
Enter number:0.00025491
x:2.549100
n:4
Enter number:2459.1
x:2.459100
n:-3
*/
