Vartika
Vartika

Reputation: 77

C Program for Ramanujan-like Number Series

1729 is known as the Ramanujan number, after an anecdote of the British mathematician G. H. Hardy when he visited Indian mathematician Srinivasa Ramanujan in hospital. He related their conversation:
"I remember once going to see him when he was ill at Putney. I had ridden in taxi cab number 1729 and remarked that the number seemed to me rather a dull one, and that I hoped it was not an unfavourable omen. "No," he replied, "it is a very interesting number; it is the smallest number expressible as the sum of two cubes in two different ways."
The two different ways are:
1729 = 1^3 + 12^3 = 9^3 + 10^3
(Source: https://en.wikipedia.org/wiki/1729_(number))
Next such number is 4104.
4104 = 16^3 + 2^3 = 9^3 + 15^3
I want to find more such numbers. I have tried several time but not able to write code for it. The codes I have written didn't run.

Upvotes: -2

Views: 7182

Answers (1)

GIRISH
GIRISH

Reputation: 101

Although, You must have shown your work.
Try it:

#include <stdio.h>
int main(){
int i, a, b, x, y, k;

printf("Input nos. between which you want to find Ramanujan No.: ");
scanf("%d %d", &a, &b);

for(i=a;i<b;i++){
    k=0;
    for(x=1;x*x*x<i;x++){
        for(y=x+1;x*x*x+y*y*y<=i;y++){

            if(x*x*x+y*y*y==i){
                 k++;
                 x++;           
            }
        }

    }
     if(k==2){
            printf("%d ", i);
        }
    }

return 0;
}

Upvotes: 4

Related Questions