CODE SNIPPET:
#include <stdio.h>int main(){int arr[100]={0}; //created for our program logicint given[6]={9,3,0,5,9,0};int target= 9; int ok=0;for(int i; i<6; i++) // 6 is the number of members in "given" array{if(given[i]<=target){if(arr[given[i]]==0){arr[target-given[i]]+=given[I];}else{int a= target-given[i];arr[given[i]]-=a;printf("[%d %d]",given[i],a);ok=1; // "ok" used here to tell if any pairs found or not}}elsecontinue;}if(!ok) // if "ok" is 0, that means no pair found!{printf("No pair found!");}return 0;}
NOTE: THIS CODE WILL SUCCESSFULLY RUN IN ONLINEGDB.COM, change the inputs and try now.
CODE ANALYSIS:
I am going to upload the video tutorial real soon!
CODE OUTPUT:
[0 9] [0 9]
>> Download the .c file (coming soon)
>> Download the .exe file (coming soon)
0 Comments
Thank You for your Kind attention.