Write a C C++ program to find power of given number

 

Flowchart

Power of given number flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num,pow,c=1,res=1;
printf(“Enter number: “);
scanf(“%d”,&num);
printf(“Enter power : “);
scanf(“%d”,&pow);
while(c<=pow)
{
res=res*num;
c++;
}
printf(“Result = %d”,res);
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num,pow,c=1,res=1;
cout<<“Enter number: “;
cin>>num;
cout<<“Enter power : “;
cin>>pow;
while(c<=pow)
{
res=res*num;
c++;
}
cout<<“Result = “<<res;
return 0;
}

 

Output

Power of given number output

 

Published by

admin

I am a computer teacher, programmer and web developer