RSS
 

Poor Programmer I am

13 Aug

the 12th question in ProjectEuler.net is about triangle numbers…

I must found the first triangle which have 500 factors…

My thought is so poor, and I code very dirty: I just, keep dividing the numbers below the triangle numbers one by one… can anyone have any other ideas?

Though my code is not complete yet, I post it below:

#include

int trinum(int topMax){
    int i, result;
    result = 0;
    for(i = 1; i <= topMax; i++){
	result += i;
	printf("%-3d:", result);
	factor(result);
    }
    return 1;
}
int factor(number){
    int j = 1;
    for(; j<= number; j++){
	if(number % j == 0){
	    printf("%d,", number / j);
	}
    }
    printf("\n");
}

int
main()
{
    int top;

    printf("Input your top:\n");
    scanf("%d", &top);
    printf("================================\n");
    trinum(top);
    printf("\n");

    return 0;
}
 
No Comments

Posted in web

 

Tags: , ,

Leave a Reply

 
Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).