Implementing command line power function in C

#include<stdio.h>
#include<stdlib.h>
int power(int num, int ex)
{
  int x=1;
  for(int i=1; i <= ex; i++)
    x=x*num;
  return x;
}
int main(int argc, char **argv)
{
  int num, ex;
  num = atoi(argv[1]);
  ex  = atoi(argv[2]);
  printf("%3d %3d %3d \n",num,ex,power(num,ex));
}

About Sumant Sumant

I love Math and I am always looking forward to collaborate with fellow learners. If you need help learning math then please do contact me.
This entry was posted in Algorithm, Computer Program and tagged , . Bookmark the permalink.

Leave a comment