write a \'c\' program for each problems seperately, PROBLEM 1: Declare a variabl
ID: 3781105 • Letter: W
Question
write a 'c' program for each problems seperately,
PROBLEM 1:
Declare a variable of type float
Assign it the value 3.6
Print it to ten decimal places
PROBLEM 2:
Declare a variable of type float
Assign it the value 1.0/10.0 (exactly as shown here)
Print it to ten decimal places
PROBLEM 3:
Declare a variable of type double
Assign it the value 1/2 (exactly as shown here)
Print it
Assign it the value 1.0/2.0 (exactly as shown here)
Print it
PROBLEM 4:
Declare a variable of type double
Assign it the value 9999999.4499999999 (exactly as shown here)
Print it
Cast it to a float
Print the float
PROBLEM 5:
Declare a variable of type int
Assign it the value 30000*30000 (exactly as shown here)
Print it
Assign it the value 40000*40000 (exactly as shown here)
Print it
Assign it the value 50000*50000 (exactly as shown here)
Print it
Assign it the value 60000*60000 (exactly as shown here)
Print it
PROBLEM 6:
Use floats for this problem
Assign the value 1e20 to a float and print it
Assign the value (1e20 + 3500000000) to a float and print it
Assign the value (1e20 + (3500000000 * 1000000000)) to a float and print it
Declare a variable of type float
Assign it the value of 1e20
Use a loop to add 3500000000 to that variable 1000000000 times.
Print the result after the loop
Note: Don't just multiply then add for that last part above. Use a loop to add 3500000000 at each iteration
Explanation / Answer
Problem 1:
#include <stdio.h>
int main() {
float value;
value = 3.6;
printf("%.10f ", value);
return 0;
}
Problem 2:
#include <stdio.h>
int main() {
float value;
value = 1.0/10.0;
printf("%.10f ", value);
return 0;
}
Problem3:
#include <stdio.h>
int main() {
double value;
value = 1/2;
printf("%f ", value);
value = 1.0/2.0;
printf("%f ", value);
return 0;
}
Problem 4:
#include <stdio.h>
int main() {
double value;
value = 9999999.4499999999;
printf("%f ", value);
float casted_value = (float) value;
printf("%f ", casted_value);
return 0;
}
Problem 5:
#include <stdio.h>
int main() {
int value;
value =30000*30000;
printf("%d ", value);
value =40000*40000;
printf("%d ", value);
value =50000*50000;
printf("%d ", value);
value =60000*60000 ;
printf("%d ", value);
return 0;
}
Problem 6:
#include <stdio.h>
int main() {
float value;
value =1e20;
printf("%f ", value);
value =(1e20 + 3500000000);
printf("%f ", value);
value =(1e20 + (3500000000 * 1000000000));
printf("%f ", value);
value = 1e20;
int i;
for (i = 0; i < 1000000000 ; i++)
{
value = value + 3500000000;
}
printf("%f ", value);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.