write a program using a function to calculate the value of "a " raised to the power " b".
Answers
Answer:
Write a function power ( a, b ), to calculate the value of a raised to b.
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main()
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){int a,b,value;
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){int a,b,value;printf("enter the value of a and b: ");
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){int a,b,value;printf("enter the value of a and b: ");scanf("%d%d",&a,&b);
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){int a,b,value;printf("enter the value of a and b: ");scanf("%d%d",&a,&b);value=power(a,b);
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){int a,b,value;printf("enter the value of a and b: ");scanf("%d%d",&a,&b);value=power(a,b);printf("the value of a = %d raised to b = %d is %d",a,b,value);
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){int a,b,value;printf("enter the value of a and b: ");scanf("%d%d",&a,&b);value=power(a,b);printf("the value of a = %d raised to b = %d is %d",a,b,value);getch();
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){int a,b,value;printf("enter the value of a and b: ");scanf("%d%d",&a,&b);value=power(a,b);printf("the value of a = %d raised to b = %d is %d",a,b,value);getch();return 0;
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){int a,b,value;printf("enter the value of a and b: ");scanf("%d%d",&a,&b);value=power(a,b);printf("the value of a = %d raised to b = %d is %d",a,b,value);getch();return 0;}
Write a function power ( a, b ), to calculate the value of a raised to b.#include<stdio.h>#include<conio.h>int power(int a,int b);int main(){int a,b,value;printf("enter the value of a and b: ");scanf("%d%d",&a,&b);value=power(a,b);printf("the value of a = %d raised to b = %d is %d",a,b,value);getch();return 0;}int pow
Answer:
Java program -------
// you can also use predefined method i.e pow(base , exponent) of Math class
import java.util.*;
class A{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int p,q;
System.out.println("enter 2 numbers");
p = sc.nextInt();
q= sc.nextInt();
power(p,q);
}
static void power(int a ,int b) // here base is a and b is exponent
{
int result=1;
// this loop keep on multiplying the result by base until exponent is zero
while(b!= 0)
{
result*=a;
b--;
}
System.out.println("Result = " + result);
}
In python ----------------
def power(a,b):
result = 1
while(b!=0):
result*=a
b = b-1
print(result)
power(5,3) #method call
----------------------------
input : 2 , 3
output: Result = 8