- Get link
- X
- Other Apps
Featured Post
write a c program to calculate the summation of a series of numbers using function | Functions in C | C programing examples
- Get link
- X
- Other Apps
write a c program to calculate the summation of a series of numbers using function | Functions in C | C programing examples
C program that calculates the summation of a series of numbers using a function.
Here mathematical series of the form:
S = 1 + 2 + 3 + ......... + n
Where n is given by the user, and the function computes the sum.
C Program to Calculate Summation of a Series (1 + 2 + ... + n):
#include <stdio.h>
// Function to calculate the summation of a series from 1 to n
int calculateSummation(int n)
{
int sum = 0;
for(int i = 1; i <= n; i++)
{
sum += i;
}
return sum;
}
int main()
{
int n;
// Input the value of n
printf("C Program to Calculate Summation of a Series (1 + 2 + ... + n)\n");
printf("Enter the value of n : ");
scanf("%d", &n);
// Call the function to calculate the summation
int result = calculateSummation(n);
// Display the result
printf("The summation of the series 1 + 2 + ... + %d is: %d\n", n, result);
return 0;
}
More Links:
c programing
Computer Science class 10
functions in c
write a c program to calculate the summation of a series of numbers using function
- Get link
- X
- Other Apps
