*Executing code with printf's for each iteration for better understanding.*


#include<stdio.h>
main(){

int n, i, j, k, t1=0, t2=0, t3, a[30];
printf("Enter the number of elements\n");
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d", &a[i]);
}

for(i=0; i<n; i++)
a[i]=a[i]*a[i];

k=n-1;
i=0;
j=k;

for(;k>=0;k--){

printf("iteration %d\n", t2);
for(j=k,i=0;(i<j) && (a[i]+a[j]!=a[k]) ;){

if(a[i]+a[j] < a[k]){
printf("i++\t%d\t%d\t%d\n", a[i], a[j], a[k]);
i++;
}
else{
printf("j--\t%d\t%d\t%d\n", a[i], a[j], a[k]);
j--;
}

}
t2++;
if(a[i]+a[j]==a[k]){
t1=1;
break;
}

}

if(t1)
printf("%d, %d, %d\n", i, j, k);
else
printf("No ans\n");

}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to