answersLogoWhite

0

C program for the power operation?

Updated: 8/10/2023
User Avatar

Wiki User

13y ago

Best Answer

WARNING: This program will not work for x power y where the resulting value is greater than 32767. Example: 10 power 10 will give you an incorrect value.

#include <stdio.h>

int main()

{

int num, power,i,ans;

printf("Enter number and power\t");

scanf("%d%d",&num,&power);

ans=num;

for(i=1;i<power;i++)

ans=ans*num;

printf("%d to the power %d = %d",num,power,ans);

return 0;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#include<iostream.h>

#include<conio.h>

class abc

{

public:

int a,b,ans;

void show();

void display();

};

void abc::show()

{

cout<<"enter base value:- ";

cin>>a;

cout<<"enter power value:- ";

cin>>b;

}

void abc::display()

{

if(b==0)

{

cout<<1;

}

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

{

ans=ans*b;

}

cout<<"Answer is= "<<ans;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

You can use the 'pow' function. From the 'man' page:

POW(3) Linux Programmer's Manual POW(3)

NAME
pow, powf, powl - power functions

SYNOPSIS
#include

double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);

Link with -lm.

DESCRIPTION
The pow() function returns the value of x raised to the power of y.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program for the power operation?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a c program to perform stack operation?

int top=-1; int stack[10];


Formula of power in c program?

There is a function called pow in header math.h


Basic engine operation can be divided into four stages these stages are?

C. intake, compression, power, and exhaust


What has the author Valluru Rao written?

Valluru Rao has written: 'Power programming-- Turbo C++' -- subject(s): C++ (Computer program language), Turbo C++ 'Power programming'


When was Operation C created?

Operation C was created on 1991-01-08.


When did Operation C happen?

Operation Cobra happened on 1944-07-31.


What is a basic automatic operation of turbo c?

If you are going to program in turbo c (for DOS) you might be better using DJGPP. Google DJGPP for downloading and a whole host of good info.


What has the author C T Hirshfeld written?

C. T. Hirshfeld has written: 'Economic operation of steam turbo-electric stations' -- subject(s): Electric power-plants, Fuel, Management, Steam power-plants


What do you have to major in to become a C and C operator?

C and C operation


Features of c program?

the features of a C program


C program was introduced in the year?

c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.


What is executive a c program?

I think it is 'execution of a C program'.