+ 1

Why this code is showing 4913 a number like ramanujan number?when showing sets are 17 and 2048, 4096 and 17 . Please answer

#include<stdio.h> int main() { int a,count=0,c,j,k,l,m,x; printf("Enter the number: "); scanf("%d",&a); x=a; for(j=1;j<=a-1;j++){ for(k=1;k<=a-1;k++){ c=(j*j*j)+(k*k*k); if(c==x) break; } if(c==x){ count++; break; } } if(count==1){ for(l=1;l<=a-1;l++){ if(l==j||l==k) continue; else{ for(m=1;m<=a-1;m++){ c=(l*l*l)+(m*m*m); if(c==x) break; } } if(c==x){ count++; break;} } } if(count==2){ printf("%d is a Ramanujan number. sets are %d and %d, %d and %d.",x,j,k,l,m); } else printf("%d is not a Ramanujan number.",x); return 0; }

15th Sep 2022, 5:04 PM
Aditya Ghosh
Aditya Ghosh - avatar
1 ответ
0
I would love to try to understand your code, but I swear I can't, so... There's one solution: nt Ramanujan(int n) { int way = 0; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { int num = i*i*i + j*j*j; if (num == n) { if (!way) printf("%d is a Ramanujan number, sets are: %d and %d", n, i, j); else printf(", %d and %d", i, j); way++; } if (num > n) break; } } if (!way) printf("%d is not a Ramanujan number.\n", n); else printf(".\n"); return way; } I searched about Ramanujan numbers and there is the 1-way, 2-way, ... and seeing your code I guess you want to find the 2-way Ramanujan numbers, if so, you need to see at the end if the way == 2 and then print it, of course this way you need to keep track of the 4 factors like you were doing. I hope I helped
18th Sep 2022, 9:55 AM
Tomás Ribeiro
Tomás Ribeiro - avatar