//Get the SUM of top 3 Numbers.
var foo = "23,45,21,09,33,98,36,89,-11,09,4";
Get the SUM of Top 3 numbers
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
//Get the SUM of top 3 Numbers.
var foo = "23,45,21,09,33,98,36,89,-11,09,4";
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Oct 26, 2022, 12:16 PM EDT
Hi Javed,
Use the following code to get your result.
var foo = "23,45,21,09,33,98,36,89,-11,09,4"; int[] numbers = Array.ConvertAll(foo.Split(','), int.Parse); int sum = 0; for (int i = 0; i < 3; i++) // more obvious about N elements (i.e: First 3) sum += numbers[i]; Console.WriteLine("Sum of first 3 Numbers: {0}", sum);Rajanikant HawaldarRank #110 · 20.3K reputationPosted Oct 27, 2022, 10:10 AM EDT
var foo = "23,45,21,09,33,98,36,89,-11,09,4"; int[] numbers = Array.ConvertAll(foo.Split(','), int.Parse); Console.WriteLine("Sum of first 3 Numbers: {0}", numbers.Take(3).ToList().Sum());Abhishek YadavRank #217 · 11.3K reputationPosted Oct 27, 2022, 4:40 AM EDT
int sum = 0; for (int i = 0; i < 3; i++) // more obvious about N elements (i.e: First 3) sum += numbers[i];