The Artima Developer Community
Sponsored Link

Java Buzz Forum
C programming power function example program

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
C programming power function example program Posted: May 20, 2017 7:14 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: C programming power function example program
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
  • C program to find power of a number using function.
  • Write a c program to find power of a number using function recursion



 Program #1 : Write a c program to find power of a number without using function recursion

  1.  #include<stdio.h>
  2. int main(){
  3.   int power,num,i=1;
  4.   long int sum=1;
  5.   printf("Enter a number:\n ");
  6.   scanf("%d",&num);
  7.   printf("\nEnter power:\n ");
  8.   scanf("%d",&power);
  9.   while(i<=power){
  10.             sum=sum*num;
  11.             i++;
  12.   }
  13.   printf("\n%d to the power %d is: %ld",num,power,sum);
  14.   getch();
  15. }

  Output:


power of number in c



  Program #2 : Write a c program to find power of a number using function recursion


  1.  #include<stdio.h>
     
  2. void powerofnumber(int power, int num);
  3. int main(){
  4.   int power,num,i=1;
  5.   long int sum=1;
  6.   printf("Enter a number:\n ");
  7.   scanf("%d",&num);
  8.   printf("\nEnter power:\n ");
  9.   scanf("%d",&power);
  10.   powerofnumber(power,num);
  11.   return 0;
  12. }
  13.  
  14. void powerofnumber(int power, int num){
  15.      int i=1,sum=1;
  16.      while(i<=power){
  17.             sum=sum*num;
  18.             i++;
  19.   }
  20.   printf("\n%d to the power %d is: %ld",num,power,sum);
  21.  
  22. }
 

Output:


  1. Enter a number:
  2.  23
  3.  
  4. Enter power:
  5.  3
  6.  
  7. 23 to the power 3 is: 12167

Read: C programming power function example program

Topic: Mocking Spring Security Context for Unit Testing Previous Topic   Next Topic Topic: Convert string to integer c programming

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use