Printing formula examples using For Loop in C++


Example Program

Here is the simple program for printing formula Examples in C++.

Source Code Example : 1

#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

Output

Enter the limit:5
Total value:2.70833

Source Code Example : 2

#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

Output

Enter the limit:5
Total value:2.28333

Source Code Example : 3

#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

Output

Enter the limit:5
Total value:1.53333

Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes