Computer Science, asked by Gauravbhardwaj7431, 1 year ago

Write a program to find the sum of three selected number is divisible by 3

Answers

Answered by iahan144
4
don't know
go and Google it please
Answered by amitkuntal15
0
Method 1 (Naive)
A simple method is to generate all possible triplets and compare the sum of every triplet with the given value. The following code implements this simple method using three nested loops.

Method 2 (Use Sorting)
Time complexity of the method 1 is O(n^3). The complexity can be reduced to O(n^2) by sorting the array first, and then using method 1 of this post in a loop.
1) Sort the input array.
2) Fix the first element as A[i] where i is from 0 to array size – 2. After fixing the first element of triplet, find the other two elements using method 1 of this post.

amitkuntal15: G blkl itna typ krne ka leye tym chaiya hota hai or apne pass hai nahi
Similar questions