Write a C program to calculate the following Sum:
Sum=1x^{2}/2! +x^{4}/4!x^{6}/6!+x^{8}/8!x^{10}/10!
Description:
Write a C program to calculate the following Sum: Sum=1x^{2}/2! +x^{4}/4!x^{6}/6!+x^{8}/8!x^{10}/10!
The above equation looks like a COSINE Equation of Taylor Sries i.e.,
Algorithm:
Step 1: Start Step 2: Read x, n values as integers Step 3: Set i = 2, s = 1, pwr = 1, nr = 1 Step 4: Convert x1 into degrees Step 5: Assign x1 as sum Step 6: while (i <= n) begin pwr ← pwr + 2; dr ← dr * pwr * (pwr  1); sum ← sum + (nr DIV dr) * s; s ← s * (1); nr ← nr * x1 * x1; i ← i + 2; end Step 7: Print sum Step 8: Stop
Program:
# include<stdio.h> # include<conio.h> # include<math.h> void main() { int i, n ; float x, val, sum = 1, t = 1 ; clrscr() ; printf("Enter the value for x : ") ; scanf("%f", &x) ; printf("\nEnter the value for n : ") ; scanf("%d", &n) ; val = x ; x = x * 3.14159 / 180 ; for(i = 1 ; i < n + 1 ; i++) { t = t * pow((double) (1), (double) (2 * i  1)) * x * x / (2 * i * (2 * i  1)) ; sum = sum + t ; } printf("\nCosine value of sin %f is : %8.4f", val, sum) ; getch() ; }
Input & Output:
Enter the Value of x: 2
Enter the limit of n: 4
The sum of sin 2.000000 series is 0.9994
Viva Questions:
Q: What is function ?
Ans: A function is a sub program it returns a value.
Q: What is procedure ?
Ans: A procedure is a sub program it does not returns a value.
Q: What are the basic data types in C ?
Ans: int, char, float, double.
Q: How to define preprocessor ?
Ans: By using the # symbal Ex: #include<stdio.h>.

CreatedOct 11, 2014

UpdatedDec 24, 2014

Views22,656
Write a C program to count the lines, words and characters in a given text.
Write a C program to find the roots of a quadratic equation
.
Write a C program to find the sum of individual digits of a positive integer.
Write a C program to generate all the prime numbers
between 1 and n, where n is a value supplied by the user.
Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result. (Consider the operators +,,*, /, % and use switch statement
)
Write C programs that use both recursive
and nonrecursive functions
 To find the
factorial
of a given integer.  To find the
GCD
(greatest common divisor) of two given integers.