Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Programming Assignment 5 For Loops Due Wednesday, October 11,2017 For each of

ID: 3590348 • Letter: C

Question

C Programming Assignment 5 For Loops Due Wednesday, October 11,2017 For each of the programs assigned below, submit a copy of the source code (.c ) saved as an electronic attachment to Homework 5 located in Canvas under Assignments. Observe the usual guidelines regarding the initial comment section, indenting, and so on. In addition, In if-else statements, indent statements to be executed for if or else condition three spaces. Align else or else if with corresponding if. Indent statements within loops. Do not use global variables.

Explanation / Answer

#include<stdio.h>
#include<math.h> //To calculate power and actual ln(10) at the end

int main() {
  
int m=0; // No. of Terms
double sum=0; //To store sum
  
//while loop to check range
while(1)
{
printf("Enter No. of Terms ");
scanf("%d",&m);
if(m<10 || m>50)
{
printf("Invalid Entry "); //false entry
}
else{
break; //Correct entry so come out of loop
}
}
  
printf("Term No Term value Sum ");
  
double term; // to store each term
double num=0.9; // to simplify numerator as 9/10 = 0.9
  
//calculating sum
for(int n=1;n<=m;n++){
term=pow(num,n)/n;
sum=sum+term;
printf("%d %.5lf %.5lf ",n,term,sum);
}

printf(" Value of ln(10) from given formula is %.5lf ",sum);
printf("Actual value of ln(10) from c library is %.5lf",log(10));

return 0;
}