You are to write a C program that inputs a value N and outpu
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
#include <stdio.h>
int main()
{
int N;
printf(\"Enter N: \");
scanf(\"%d\",&N); //read number N
int a=0,b=0,c=0,d=0; //initialize 4 variables to 0, to store the numbers of which cubic sums = N
for(int i=1; i<N; i++){ //outer loop
for(int j=i; j<N; j++){ //inner loop starts from i, in order to avoid inverse repetation
if( (i*i*i) + (j*j*j) == N){ //checking whether the cubic sums of i & j are = N
if(a!=0 && b!=0){ //if a & b are already populated with values, then we have 2 pairs to print one line of output
c = i; //save the third and fourth numbers to c and d
d = j;
printf(\"%d = %d^3 + %d^3 = %d^3 + %d^3\ \",N,a,b,c,d); //print output
a=0; b=0; c=0; d=0; //if one line is printed, then resets all 4 variables to 0, to start again the process to print next pairs
}
if(a==0 && b==0){ //if a & b are 0, then this i & j are the first pairs we got, so save it to a & b
a = i;
b = j;
}
}
}
}
return 0;
}
----------------------------------
OUTPUT:
Enter N: 1729
1729 = 1^3 + 12^3 = 9^3 + 10^3
Enter N: 4104
4104 = 2^3 + 16^3 = 9^3 + 15^3
