WEEK:4 PROGRAMMING ASSIGNMENT 1 SOLUTION (Jan 2020-Apr2020) An Introduction to Programming through C++ NPTEL 2020

  

               An Introduction To Programming Through C++


IIT Bombay.

Week 4- Programming Assignment 1:


Write a program that takes as input two numbers n (integer) and x (double), and prints cos(x) evaluated by taking n terms of the Taylor series (using x0 =0):
cos(x)=1−x2/2!+x4/4!−x6/6!...

Sample Test Cases
                              Input          Output
Test Case 1            10 1         0.540302
Test Case 2            100 1.8   -0.227202

WRITE/COPY THESE CODE DIRECTLY IN NPTEL TERMINAL AND COMPILE AND RUN THEN SUBMIT.

PROGRAM:
#include<iostream>

int main()

{
 double i,j,n,fact,sign=-1;
 double x, p,sum=0;
 cin>>n;
 cin>>x;
 for(i=2;i<=n;i+=2)
 {
  p=1;
  fact=1;
  for(j=1;j<=i;j++)
  {
   p=p*x;
   fact=fact*j;
  }
  sum+=sign*p/fact;
  sign=-1*sign;
 }
 cout<<1+sum;
 return 0;
}

WEEK-4 :PROGRAMMING ASSIGNMENT 2  AND QUIZ 4
CLICK ON BELOW LINK.
<<CLICK HERE FOR  WEEK 4:PROGRAMMING -02>>

<<CLICK HERE FOR  WEEK 4: QUIZ>> FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100%  correct solutions.

No comments:

Post a Comment

If you have any problems related to solutions or any concept please let me know.

Copyright (c) 2020 Custom Programs All Right Reserved

Pages