Before attending this lab, you should have read and be familiar with Chapter S s
ID: 3606103 • Letter: B
Question
Before attending this lab, you should have read and be familiar with Chapter S section 5.1 of Delores Etter's Engineering Problem Solving with C Answer the questions below in a typed document, numbered appropriately. Print out this sheet as a cover page. Bring the completed assignment to your next lab class. Write a declaration statement for an array with 10 elements. Assume that the array is going to contain double-precision floating-point temperature data in units of Kelvins. Initialize the array with values of 0 in all elements. 1) Write the same declaration, but for an array with n elements, where n is a pre-declared integer variable (In other words, has already been declared in advance.) Do not give the array initial values in this case. (You cannot initialize variable-length arrays in a declaration statement) 2) Write a for loop that will run a total of n times, and in each iteration will set one of the elements of your temperature array to zero. (Remember that arrays in c go from subscript (0) to (n-1). 3) Write a for loop that will run a total of n times, and in each iteration will ask the user for an input value and will store it in a different element of your temperature array. It should also feature a statement that adds the new element to a running sum which is stored in a separate variable called T sum. 4) Write a statement that calculates the percent error between a variable containing an average measured temperature and a defined symbolic constant containing the boiling point of an unspecified substance 5) A -B Percent Error- * 100% (B is the known constant)Explanation / Answer
1) double temp[10]={0,0,0,0,0,0,0,0,0,0};
above statement will declare array of double data type with 10 elements and all intitalized to zero which we have assigned on the right side of the assignment of above statement. As it is double data type it can hold double precision flaoting point values
2)int n;
double temp[n];
in the above statement we are declaring array of double data type with n elements and here we cannot assign default values to them as we didnt know the value of n in advance
3)for(int i=0;i<n;i++)
{
temp[i]=0;
}
In the above statement the loop will run for n times and each time it will set value zero to array temp at index i
4) double t_sum=0.0;
for(int i=0;i<n;i++)
{
printf("Enter element in to array");
scanf("%lf",&temp[i]);
t_sum+=a[i];
}
In the above code loopp will run for n times and each time it will prompt user to enter an element in to array and then it will store the value entered by user in ith index of temp array and in each iteration it will add values entered by user to t_sum variable that is at the end of loop it have sum of all temperature values entered by user
5)double PercentError;
A=t_sum/n;
PercentError=abs((A-B)/B)/100;
we already have computed thse sum of all temperatures entered by user into t_sum so to get average of temperatures we just need to divide it by n(size of array) and B is a somw known constant above we have all the values so above formula will calculate the PercentError and in the above statement we are dividing by 100 to get in percentage value.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.