Sunday, 12 June 2016

C++ Program of Exponential using Functions

In this program we will learn how to take exponential of a variable e.g 10^2.
The code is given below.

//Code starts
#include<iostream>
#include<conio.h>

using namespace std;

int expo(int b, int p)
{
 int temp=1;        //taking a temporary variable

 for(int i=1; i<=p; i++) //for loop starts
 {
  temp=temp*b;
 }

 return temp;  //returning value of temporary variable
}


int main()   //main starts

{

 int c,d;

 cout<<"Enter Base to Find its Exponential : ";
 cin>>c;

 cout<<"Enter Power to Find its Exponential : ";
 cin>>d;

 cout<<"Answer = "<<expo(c,d); // Function calling
getch();
}
//Code ends
OUTPUT:



Share:

C++ Program of Sum, Multiplication, Average Program in Array

In this program we will learn how to calculate sum, multiply and average of numbers stored in array.
The code is given below.

//Code Starts
#include<iostream>
#include<conio.h>

using namespace std;

int main()

{
  int n,a[n],sum=0,mul=1;
  float avg;

 
  cout<<"Enter Size of Array : ";
  cin>>n;
 
  for(int i=0;i<n;i++)
  {
    cout<<"Enter Number at "<<i<<" index : ";
    cin>>a[i];
  
    sum=sum+a[i];

    mul=mul*a[i];
  }

 cout<<"Sum = "<<sum<<endl;

 cout<<"Multiplication = "<<mul<<endl;

 avg=sum/n;

 cout<<"Average = "<<avg;

 getch();

}
//Code Ends

OUTPUT:


Share:

C++ Program of Binary search in Array

In this program we will learn how to search a number from indexes of array.
The code is given below.

//Code Starts
#include <iostream>
#include<conio.h>

using namespace std;

int main()

{
int n,a[n],search,j;

cout<<"Enter Size of Array : ";
cin>>n;

for(int i=0;i<n;i++)
{
cout<<"Enter "<<i<<" element = ";
cin>>a[i];
}

for(int b=0;b<n;b++)

{
cout<<"Number at index ["<<b<<"] = ";
cout<<a[b]<<endl;
}

cout<<"Enter Number to search : ";
cin>>search;

for(int j=0;j<n;j++)

{
if(search==a[j])
{
cout<<"Number found at index : "<<j<<endl;
break;
}
}
getch();
}
//Code Ends

OUTPUT:



Share:

C++ structure program of person

In this program we will create structure of person enter data in structure and also show the entered data.
The code is given below.

//Code Starts

#include<iostream>
#include<conio.h>

using namespace std;

struct person
{
char name[15];
char age[2];
char father_name[20];
char adress[40];
char phone[11];
};

int main()
{
person p;
cout<<"Enter Name "<<endl;
cin>>p.name;
cout<<"Enter Father's Name "<<endl;
cin>>p.father_name;
cout<<"Enter Age "<<endl;
cin>>p.age;
cout<<"Enter Adress "<<endl;
cin>>p.adress;
cout<<"Enter Mobile Number "<<endl;
cin>>p.phone;
cout<<"Your Entered Data :"<<endl;
cout<<p.name<<endl;
cout<<p.age<<endl;
cout<<p.father_name<<endl;
cout<<p.adress<<endl;
cout<<p.phone<<endl;
getch();
}
//Code Ends

OUTPUT:





Share: