c program to check whether the given number is a power of an integer - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Friday, November 29, 2019

c program to check whether the given number is a power of an integer - My CS Tutorial

c program to check whether the given number is a power of an integer - My CS Tutorial


in this tutorial we will learn how to write a program that check given number is a power or not of a integer.




C PROGRAM CODE


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
 int num,power,temp;
 printf("\n Enter a Number:\n ");
 scanf("%d",&num);
 printf("\n Enter Power you want to check:\n ");
 scanf("%d",&power);
 temp=num;
 if(num==0 || num==1)
 {
    printf("\n Enter Number other than zero and 1:\n");
    exit(0);
 }
 while(num>1)
 {
  if(num%power!=0)
  {
   printf("\n Given Number %d is not power of %d\n",temp,power);
   exit(0);
  }
  num=num/power;
 }
 printf("\n Given Number %d is power of %d\n",temp,power);
 return(0);
}


OUTPUT 1:





OUTPUT 2:




In first output,enter a number as 169
and enter the power that you want to check as 13

given number 169 is power of  13


In second output,,enter a number as 625
and enter the power that you want to check as 20

given number 625 is power of  20


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.

Created by-- HARSH CHAUHAN

No comments:

Post a Comment