Sunday 10 June 2018

C++ program examples:- Mathematics

1.Program to calculate area of a triangle..

Concepts you should know to write this program
:-Float
Formula of area of triangle = 1/2 base x height of trainge

#include <iostream>
using namespace std;
int main ()

{



    float b,h,a;


    cout<<"enter base of triangle"<<endl;

    cin>> b;

cout <<"enter height of triangle"<<endl;

cin>>h;

a=(b*h)/2 ;


cout <<"The area of the triangle is " <<a <<" units";


return 0;

}





























































2.Program to calculate area of circle

Formula of area of triangle = pi *r* r



#include <iostream>
using namespace std;
int main ()

{


    float a,r;


    cout<<"enter radius"<<endl;

    cin>> r;

a=3.14*r*r;


cout <<"THe area of the circle is" <<a <<" units";


return 0;

}































3.Program to find discriminant of a quadratic equation


Concepts you should know to write this program:-


  • Float
  • If else statements
  • Formula:= d is discriminant and is equal to 
    (b^2) -(4*a*c)




#include <iostream>
using namespace std;
int main ()

{
    float a,b,c,d;

    cout<<"enter a";
    cin>>a;

    cout<<"enter b";
    cin>>b;

    cout<<"enter c";
    cin>>c;

d=b*b-4*a*c;

cout<< "discriminant is"<< d ;


    return 0 ;


}




















































4.Program to find sum of arithmetic progression



#include <iostream>
using namespace std;
int main ()

{
int a,d,n;
float sum;

cout<< "enter the first number of ap series";
cin>>a;


cout<< "enter the difference between the terms";
cin>>d;


cout<< "enter the total terms in the ap series";
cin>>n;

sum=(n*(2*a+(n-1)*d)) /2;

cout <<"The sum of ap series is"<<sum;

    return 0;

}




















































5.Program to find whether number iss even or odd


#include <iostream> using namespace std; int main()

{ int a; cout << "Enter the number: ";
cin >> a; if (a % 2 == 0) { cout << "The given number is EVEN" << endl; }


else { cout << "The given number is ODD" << endl; }
return 0; }

































No comments:

Post a Comment