top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C Program to find out the exponent value of for a given input?

+4 votes
424 views
C Program to find out the exponent value of for a given input?
posted Dec 3, 2014 by Manikandan J

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+4 votes
 
Best answer
#include<stdio.h>
#define ACCURACY 0.0001

int main() {
   int n, count;
   float x, term, sum;

   printf("\nEnter value of x :");
   scanf("%f", &x);

   n = term = sum = count = 1;

   while (n <= 100) {
      term = term * x / n;
      sum = sum + term;
      count = count + 1;

      if (term < ACCURACY)
         n = 999;
      else
         n = n + 1;
   }

   printf("\nTerms = %d Sum = %f", count, sum);
   return 0;
}

Output :

Enter value of x:0
Terms = 2 Sum = 1.000000

Enter value of x:0.1
Terms = 5 Sum = 1.105171

Enter value of x:0.5
Terms = 7 Sum = 1.648720

Enter value of x:0.75
Terms = 8 Sum = 2.116997

Enter value of x:0.99
Terms = 9 Sum = 2.691232

Enter value of x:1
Terms = 9 Sum = 2.718279
answer Dec 3, 2014 by Shivaranjini
Similar Questions
+1 vote

Given an array of integers (possibly some of the elements negative), write a C program to find out the *maximum product* possible by adding 'n' consecutive integers in the array, n <= ARRAY_SIZE.

Also give where in the array this sequence of n integers starts.

+2 votes
0 votes

For given list of numbers find out triplets with sum 0 using C?
Input : arr[] = {0, -1, 2, -3, 1}
Output : 0 -1 1
2 -3 1

0 votes

Enter character: r
Enter string: programming
Output: Positions of 'r' in programming are: 2 5
Character 'r' occurred for 2 times

...