Skip to main content
How to calculate power of a number in c

How to write power in c

#include<stdio.h>
int main(){
  int pow,num,i=1;
  long int sum=1;
  printf("\nEnter a number: ");
  scanf("%d",&num);
  printf("\nEnter power: ");
  scanf("%d",&pow);
  while(i<=pow){
            sum=sum*num;
            i++;
  }
  printf("\n%d to the power %d is: %ld",num,pow,sum);
  return 0;
}


 output:
Enter the number: 5

Enter the  Power:6
  5 to the power 6 is :  15625
 

Comments

Popular posts from this blog

FACTORIAL OF A NUMBER USING RMI IN JAVA

CLIENT PROGRAM: import java.io.*; import java.rmi.*; public class client { public static void main(String args[])throws Exception { try { String s="rmi://"+args[0]+"/abc"; serverint f=(serverint)Naming.lookup(s); DataInputStream m=new DataInputStream(System.in); int n1=Integer.parseInt(m.readLine()); System.out.println("the factorial is"+f.fact(n1)); } catch(Exception e) { System.out.println(e); } } } INTERFACE PROGRAM: import java.rmi.*; public interface serverint extends Remote { int fact(int n)throws Exception; } IMPLEMENTATION PROGRAM: import java.rmi.*; import java.rmi.server.*; public class serverimpl extends UnicastRemoteObject implements serverint { public serverimpl()throws Exception { } public int fact(int n) { int i,c=1; for(i=1;i<=n;i++) { c=i*c; } ret...

creating simple graphics appletviewer java

import java.awt.*; import java.applet.*; import java.awt.event.*; //<applet code="Appletdemo" height=500 width=500></applet> public class Appletdemo extends Applet implements ActionListener {             String s;             Button b1,b2;             public void init()             {                         b1= new Button("Test");                         b2=new Button("circle");                         add(b1);                         add(b2);                         b1.addActionListener(this);              ...