Dear all,

There are two problems that I have written a code for:

1. Program to determine whether a number is a factorial number or not.

A. I am getting the errors: (a) Linker error - undefined reference to 'WinMain@16' (b) Id return 1 exit status (c) Build Error. My code for this problem is:

Code:

#include<stdio.h>
int main()
{
int i,n,prod=1;
printf("Enter n to be checked");
scanf("%d",&n);
if(n==1 || n==2)
{
printf("n is a factorial number");
}
else if(n>2)
{
for(i=1;i<=n/2;)
{
while (prod<=n)
{
prod*=i;
i++;
}
}
}
if(prod==n)
{
printf("factorial");
}
else
printf("not factorial");
system("pause");
return(0);
}

2. Program to calculate all the coefficients of x for a given value of n. Here nCr in the rth power of x in the expansion of (x+1)^n is given by

nCr = n! / r! (n-r)!

A. I am getting the errors: (a) Linker error - undefined reference to 'WinMain@16' (b) Id return 1 exit status (c) Build Error. My code for this problem is:

Code:

#include<stdio.h>
int main()
{
int n,r,i,num,*coefficients,*den1,*den2;
printf("enter the value of n");
scanf("the values are %d",&n);
//for calculating r!
for(r=0;r<=n;r++)
{
if(r==0)
{
den1[r]=1;
}
else for(i=1;i<=r;i++)
{
den1[r]*=i;
}
}
//for calculating n-r!
for(r=0;r<=n-r;r++)
{
if(r==0)
{
den2[r]=1;
}
else for(i=0;i<=n-r;i++)
{
den2[r]*=i;
}
}
//for calculating n!
for(i=1;i<=n;i++)
{
num*=i;
}
//for calculating coefficients
for(i=0;i<=n;i++)
{
coefficients[i]=(num/(den1[i]*den2[i]));
printf("the %dth coefficient is %d\n",i,coefficients[i]);
}
system("pause");
return 0;
}

3. Generating the numbers of the Lucas sequence which is a variation of fibonacci sequence. The lucas sequence is:

1 3 4 7 11 18 29 ...

A. This code for this is successfully compiled but on running the program it hangs after entering the value of integer 'n'. My code for this problem is:

Code:

#include<stdio.h>
int main()
{
int i,n,*a;
printf("number of terms of the lucas sequence to be calculated");
scanf("%d",&n);
for(i=3;i<=n;i++)
{
a[i-1]=3;
a[i-2]=1;
a[i]=a[i-1]+a[i-2];
printf("the lucas sequence to n terms is 1 3 %d",a[i]);
}
system("pause");
return

Thank you for you help.