amicable number

please help me about this error

Page 1 of 1

5 Replies - 2343 Views - Last Post: 10 November 2009 - 03:44 PM Rate Topic: -----

#1 mounikasiva   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 17-October 09

amicable number

Posted 26 October 2009 - 03:42 AM

#include<stdio.h>
#include<stdlib.h>
struct amicable			
{
	int **amicablePair;
	int size;
};

int main()
{
		int startnum =10,i,endnum =1000;
		struct amicable* ami=(struct amicable*)malloc(sizeof(struct amicable));
		struct amicable* getAmicablePairs(int,int);
		ami=getAmicablePairs(startnum, endnum);
		if(ami->size==0)
		 printf("NULL");
		 else
		 {
		 printf("{");
		for(i = 0; i<ami->size; i++)
		{
			printf("{%d, %d}",ami->amicablePair[i][0], ami->amicablePair[i][1]);
		}
		printf("}");
		}
		free(ami);
		

}

struct amicable* getAmicablePairs(int startnum,int endnum)
{
	int i,j,size=0,factsumi,factsumj;
	int sumfactors(int);
	struct amicable* record=(struct amicable*)malloc(sizeof(struct amicable));
	for(i=startnum;i<=endnum;i++)
	{
	  factsumi=sumfactors(i);
	  for(j=endnum;j>i;j--)
	   {
	  factsumj=sumfactors(j);
	  if((factsumi==j)&&(factsumj==i)&&(i!=j))
	   {
		 record->amicablePair[size][0]=i;
		 record->amicablePair[size][1]=j;
		 size++;
		}
	}
	 }

	record->size=size;

	return record;
	
}


  int sumfactors(int number)
   {
	 int k,sum=0;
	 for(k=1;k<number;k++)
	 {
	   if(number%k==0)
	   sum +=k;
	  }
	 return sum;
   }





the error is :

ERROR: 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.

This post has been edited by mounikasiva: 26 October 2009 - 03:45 AM


Is This A Good Question/Topic? 0
  • +

Replies To: amicable number

#2 moopet   User is offline

  • binary decision maker
  • member icon

Reputation: 345
  • View blog
  • Posts: 1,190
  • Joined: 02-April 09

Re: amicable number

Posted 26 October 2009 - 03:55 AM

Hello again.

main() returns an int. You don't;

int main()
{
// do shizzle
   return 0;
}


Was This Post Helpful? 0
  • +
  • -

#3 mounikasiva   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 17-October 09

Re: amicable number

Posted 26 October 2009 - 04:36 AM

View Postmoopet, on 26 Oct, 2009 - 02:55 AM, said:

Hello again.

main() returns an int. You don't;

int main()
{
// do shizzle
   return 0;
}




i put "return 0;" but same error is generating

i think in the below code
struct amicable			
{
	int **amicablePair;
	int size;
};



in the above code we can allocate memory for "int **amicablePair"
but i dont know how to allocate and where the allocation statement put in the above whole program

so plzzzzzzzzzzz help me
Was This Post Helpful? 0
  • +
  • -

#4 mounikasiva   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 17-October 09

Re: amicable number

Posted 26 October 2009 - 10:44 PM

plzz help me to rectify this error
Was This Post Helpful? 0
  • +
  • -

#5 mounikasiva   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 17-October 09

Re: amicable number

Posted 27 October 2009 - 09:18 PM

View Postmounikasiva, on 26 Oct, 2009 - 09:44 PM, said:

plzz help me to rectify this error

plzzz help meee p;lzzzzzzzzzzzzzzzzzzzzzzzz
Was This Post Helpful? 0
  • +
  • -

#6 prabindatta   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-November 09

Re: amicable number

Posted 10 November 2009 - 03:44 PM

View Postmounikasiva, on 27 Oct, 2009 - 08:18 PM, said:

View Postmounikasiva, on 26 Oct, 2009 - 09:44 PM, said:

plzz help me to rectify this error

plzzz help meee p;lzzzzzzzzzzzzzzzzzzzzzzzz



I am getting the same problem........if you got the solution plz plz send me...
Runtime: Amicable Number

This post has been edited by prabindatta: 10 November 2009 - 03:46 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1