Here is the question: Write a function which accepts an integer N and returns the sum of first N numbers.
and here are my codes:
#include<stdio.h>
#include<stdlib.h>
int Myfun(int x);
int main()
{
int a, sum;
printf("Enter an integer: ");
scanf("%d", &a);
printf("sum is %d\n", sum);
system("pause");
return (1);
}
int Myfun(int x)
{
int a, count, sum=0;
for(count=1;count<=a;count++){
sum=sum+count;
}
return (sum);
}
The problem here is i do not get the correct output. If i enter 4 it should have give the output 10 but it gives a 0. I need help if there are missing codes are any mistake help me.