hey guys i am struggling with this program since last three days..my compiler is showing
"Your code has stopped its execution with a non-zero (failure) exit value.This is generally due to run time Exceptions like Memory Access Violation and Floating Point Exception. Please check your code for run time Exceptions and try again. "

#include<conio.h>
#include<stdio.h>
struct amicable
{
int **amicablePairs;
int size;
};
struct amicable* getAmicablePairs(int startnum,int endnum);
int main()
{
struct amicable *ami;
int i,startnum,endnum;
clrscr();

ami=getAmicablePairs(100,2000);
printf("{");
for(i=0;i<ami->size;i++)
{
printf("{%d %d}",ami->amicablePairs[i][0],ami->amicablePairs[i][1]);
}
printf("}");
getch();
return 0;
}


struct amicable * getAmicablePairs(int startnum,int endnum)
{
struct amicable *amic;
int i,j,divisor=0,divisor1=0,k=0,l,**p;
p=malloc(15*sizeof(int*));
if(p==NULL)
printf("failed for p");
if(startnum>0&&endnum>0&&startnum<endnum&&endnum<=15000)
{
for(i=startnum;i<=endnum;i++)
{
    for(j=1;j<=i/2;j++)
    {
        if(i%j==0)
        divisor+=j;
    }
    if(divisor<=endnum&&divisor>i)
    {
        for(l=1;l<=divisor/2;l++)
        {
            if(divisor%l==0)
            divisor1+=l;
        }
        if(divisor1==i)
        {
               p[k]=malloc(2*sizeof(int));
               if(p[k]==NULL)
               printf("failed for loop");
               p[k][0]=i;p[k][1]=divisor;
               //amic->amicablePairs[k][0]=i;
               //amic->amicablePairs[k][1]=divisor;
               k++;
        }
    }
divisor=0;divisor1=0;
}
if(k==1)
goto here;
amic->size=k;
amic->amicablePairs=p;
return amic;
}
else
here:return NULL;
}

plzzzz let me know are there any logical errors plzzzzzzzzzz

Edited 3 Years Ago by Dani: Formatting fixed

This article has been dead for over six months. Start a new discussion instead.