segmentation fault (core dumped)
i wrote this code to print the sum of following series:
x+x^3/3!
since pow function was not getting recognized, i made a function power to achieve the same function.
#include<stdio.h>
int fact(int a);
int power(int x,int y);
int sum(int a,int b);
main(){
int x=0,n=0,s=0;
printf("**printing sum of x+x^3/3!
printf("enter x and n respectively\n");
scanf(
s=sum(x,n);
printf("the sum is :%d\n",s);
}
int fact(int a){
return a*fact(a-1);
}
int power(int x,int y){
int g=1;
while(y!=0){
g=g*x;
y--;
}
return g;
}
int sum(int x,int n){
int sum=0,i=0;
for(i=1;i<=n;i++){
sum+=
}
return sum;
}
i have two questions:
1. why isnt pow function displayed as undefined even after including math.h?
2. this code written above is getting compiled and even running upto
**printing sum of x+x^3/3!
enter x and n respectively
after entering two numbers it is diplaying "segmentation fault (core dumped)"
please help
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- nabanita
- Solved:
- Last query:
- Last reply: