Computer Science, asked by jerinaxavier0, 17 hours ago

write a c program to find the sum of the series 1! /1+ 2! /2+ 3! /3+ 4! /4+ 5! /5 using the concept of functions.​

Answers

Answered by samarthkrv
0

Answer:

#include<stdio.h>

int factorial(int n){

  Int fact = 1;

For(int i = 1; i <= n; i++){

fact *= i;

}

return fact;

}

int main(){

int sum = 0;

for(int i = 1; i <= 5; i++){

sum = sum + (factorial(i)/i);

}

printf(“%d \n” , sum);

}

Explanation:

Answered by syed2020ashaels
0

Explanation:

The code is:

#include <stdio.h>

int factorial(int n) {

 int i, f = 1;

 for (i = 1; i <= n; i++) {

   f = f * i;

 }

 return f;

}

int main() {

 int i;

 float sum = 0;

 for (i = 1; i <= 5; i++) {

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

 }

 printf("Sum of the series = %f", sum);

 return 0;

}

In this program, a function named factorial is defined which takes an integer n as input and returns the factorial of n. The factorial function is called inside the main function to calculate the factorial of the numbers 1 to 5. The sum of the series 1! /1 + 2! /2 + 3! /3 + 4! /4 + 5! /5 is calculated inside the main function by iterating over the numbers 1 to 5 and adding the result of the division of the factorial of each number by the same number. The final result is displayed using the printf function.

#SPJ3

For more similar questions: https://brainly.in/question/26907798

Similar questions