This program calculates the sum of the series 1/1! + 2/2! + 3/3! + ... + n/n!. The program starts by initializing four variables: i, j, n, and fact. j and fact are initialized to 0 and 1 respectively. The program then prompts the user to enter the value of n.
In the for loop, the program calculates the factorial of each number from 1 to n and stores it in fact. It then calculates the value of i/fact and adds it to j. This is repeated for each value of i from 1 to n. Finally, the program prints out the value of j, which is the sum of the series.
#include<iostream> using namespace std; int main() { float i,j=0,n,fact=1; cout<<"\nEnter the limit:"; cin>>n; for(i=1;i<=n;i++) { fact=fact*i; j=j+i/fact; } cout<<"\nTotal value:"<<j; return 0; }To download raw file Click Here
Enter the limit:5 Total value:2.70833
This program calculates the sum of the series 1 + 1/2 + 1/3 + ... + 1/n. The program starts by initializing two variables: i and j. j is initialized to 0. The program then prompts the user to enter the value of n.
In the for loop, the program calculates the value of 1/i for each value of i from 1 to n and adds it to j. This is repeated for each value of i. Finally, the program prints out the value of j, which is the sum of the series.
#include<iostream> using namespace std; int main() { float i,j=0,n; cout<<"\nEnter the limit:"; cin>>n; for(i=1;i<=n;i++) { j=j+1/i; } cout<<"\nTotal value:"<<j; return 0; }To download raw file Click Here
Enter the limit:5 Total value:2.28333
This program calculates the sum of the series 1/1 + 1/3 + 1/5 + ... + 1/n. The program starts by initializing two variables: i and j. j is initialized to 0. The program then prompts the user to enter the value of n.
In the for loop, the program calculates the value of 1/i for each odd value of i from 1 to n and adds it to j. This is repeated for each odd value of i. Finally, the program prints out the value of j, which is the sum of the series.
#include<iostream> using namespace std; int main() { float i,j=0,n; cout<<"\nEnter the limit:"; cin>>n; for(i=1;i<=n;i=i+2) { j=1/i+j; } cout<<"\nTotal value:"<<j; return 0; }To download raw file Click Here
Enter the limit:5 Total value:1.53333
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions