Hi i am writing a c program to check for the number of A+B=C relationships in an input array where A, B and C are 3 distinct elements in the array. Lets say the user is to input two lines. The first line is the number of integer elements he wish to enter, the second line is the integer elements in the array.

So far , my method is:

1) Assign the user input to input[size] where size is specified by the user.

2) Next , i will add input[0] to input[1] and then input[0] to input[2], then input[0] to input[3] and so on till the size specified by user. I will then continue the same procedure of adding input[1] to input[2],input[1] to input [3] till the size entered by user.You get the idea.

Subsequently, i will check the sum of each result and match it with the remaining elements in the array. If there is a match, then counter++.

I cant get my code to work though, i need help.

Or can someone suggest a better method .. Thanks a million.

Code:/* This program caluclates the number of relations in the form A + B= C, given the user input of number of elements and arrary content*/ #include<stdio.h> #define SIZE 100 int main() { int input[SIZE],A[SIZE],B[SIZE],size,i,n=0,sum=0,counter_plus=0,k=0; printf("Please enter the number of integers in your selection: "); scanf("%d",&size); printf("\n"); printf("Please enter your integers: "); for(i=0;i<size;i++) scanf("%d",&input[i]); //initialise the arrays while(k<size) { for(i=0;i<size;i++) { sum=input[k]+input[i+1]; if(i==size-1)// means it has reached the end of the seq of numbers ++k; while(n<size) { if(sum==input[n])//check if the sum obtained is equal to any of the numbers in the seq { ++counter_plus; break; } ++n; } } } printf("%d",counter_plus); return 0; }