Loops – Physics – Problem #1

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: Hard

Problem Statement

The infinite series for cos(x): cos(x) = 1 – x2 /2! + x4 /4! – x6 /6! + ............; where x is a floating point number. Write a C program which does the following: 1. (a) Takes in 3 floating point numbers x,y,z and a positive integer n. (b) The program then keeps reading floating point numbers from the keyboard till it gets a floating point number a, -1 < a <1, (c) It then continues to read floating point numbers till it gets a floating point number b, -0.5 < b < 0.5. 2. (a) The program then computes cos(x), cos(y), cos(z) upto n terms of the infinite series. (b) It also computes cos(a) and cos(b) using the infinite series, upto terms having magnitude 10-5, and remembers for each a and b the number of terms that had to be computed. 3. (a) The program then prints cos(x), cos(y), cos(z) calculated upto n terms. (b) It also prints cos(a), cos(b) calculated upto terms with magnitude 10-5, as well as the number of terms that had to be calculated for each of a and b.

Back to Lab Problems
Loops/Physics/Problem #1

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #1

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.