Write a C program to compute the value of X ^ N given X and N as inputs
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { signed int x , n ; signed int power; printf("Enter The Value Of X Then N :\n"); scanf("%d%d",&x,&n); power=pow(x,n); printf("%d",power); return 0; }
#include <stdio.h> #include <stdlib.h> signed int c_power (signed int a ,int b) { signed int c=1 ; int i; if (b==1){ return a; } else if (b==0) { return 1; } else for (i=0;i<b;i++){ c*=a; } return c; } int main() { signed int x , power ; int n; printf("Enter The Value Of X Then N :\n"); scanf("%d%d",&x,&n); power=c_power(x,n); printf("%d",power); return 0; }
0 Comment to "Compute X^n"
Post a Comment