Write a C-program to add entered terms of the following series: 1/(1!) + 2/(2!) + 3/(3!) + 4/(4!) + …

 TASK-

Write a C-program to add entered terms of the following series:  1/(1!) + 2/(2!) + 3/(3!) + 4/(4!) + …

CRACKING:

  • Each number is divided by its factorail
  • Algorithm to find factorail
  • To get more clear concept about factorail finding Click here: 👉👉 Factorail

CODE:

#include<stdio.h>

int main(){

int r,fact=1;

float sum=0;

printf("\tNumber of terms? : ");

scanf("%d",&r); //asking for number of terms

printf("\n");

for (int i=1;i<=r;i++)

{

//factorail calculation is here

for (int j=1;j<=i;j++)

{

fact=fact*j;

}

printf("\t%d/%d!",i,i);

if (i!=r)

printf(" + ");

sum=sum+(float(i)/fact);

fact=1;

}

printf("\n\tSum of %d terms is %0.2f",r,sum);

getchar();

return 0;

}

Expected Output:






NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

Post a Comment (0)
Previous Post Next Post