Calculate Power by function :-
This function have not used any built in function. First power function will calculate power Then this function will called in main function, Source code is available here
#include "stdafx.h" // Header file for MS VS
#include <iostream> // Some compiler used < iostream.h>
#include <conio.h> // header file
using namespace std ;
int power (int num , int exp)
{
int a = num ;
for (int i = 2 ; i <= exp ; i ++)
{
a = a * num ;
}
return a ;
}
int main ()
{
int num ;
int exp ;
cout << "Enter num : " ;
cin >> num ;
cout << "Enter exp : " ;
cin >> exp ;
cout << power(num , exp) ;
_getch() ; \\ Some compiler uses getch() ;
return 0 ;
}
This function have not used any built in function. First power function will calculate power Then this function will called in main function, Source code is available here
#include "stdafx.h" // Header file for MS VS
#include <iostream> // Some compiler used < iostream.h>
#include <conio.h> // header file
using namespace std ;
int power (int num , int exp)
{
int a = num ;
for (int i = 2 ; i <= exp ; i ++)
{
a = a * num ;
}
return a ;
}
int main ()
{
int num ;
int exp ;
cout << "Enter num : " ;
cin >> num ;
cout << "Enter exp : " ;
cin >> exp ;
cout << power(num , exp) ;
_getch() ; \\ Some compiler uses getch() ;
return 0 ;
}
0 comments:
Post a Comment