Question 3
a) Using C or C++ or a program of your choice, write a program that list the storage size of a float, list the minimum and maximum float values, and the precision of the float.
[10 marks]
b) Describe the steps of how you will compile the program written in Question a) above in a typical compiler such as gcc or a compiler of your choice. [10 marks]
c) Show the output (screenshot) of how you have compiled the program written in Question a) above and attach all files (screenshot) generated where applicable. [5 marks]
A)
#include<stdio.h>
int main(){
float numbers[10];
int i;
float minimum;
float maximum;
for(i=0;i<10;i++){
printf("Enter the number %d: ",(i+1));
scanf("%f",&numbers[i]);
}
minimum=numbers[0];
maximum=numbers[0];
for(i=0;i<10;i++){
if(numbers[i]>maximum){
maximum=numbers[i];
}
if(numbers[i]<minimum){
minimum=numbers[i];
}
}
printf("\nThe minimum float value: %.2f\n",minimum);
printf("the maximum float value: %.2f\n",maximum);
scanf("%d",&i);
return 0;
}
B)
To run the program use the following command (linux):
g++ -Wall -pedantic -std=c++11 -g *.cpp && valgrind --leak-check=full ./a.out
C)
Comments
Leave a comment