
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to determine if any two integers in array sum to given integer
The following is our array −
int[] arr = new int[] { 7, 4, 6, 2 };
Let’s say the given intger that should be equal to sum of two other integers is −
int res = 8;
To get the sum and find the equality.
for (int i = 0; i < arr.Length; i++) { for (int j = 0; j < arr.Length; j++) { if (i != j) { int sum = arr[i] + arr[j]; if (sum == res) { Console.WriteLine(arr[i]); } } } }
Example
using System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { int[] arr = new int[] { 7, 4, 6, 2 }; // given integer int res = 8; Console.WriteLine("Given Integer {0}: ", res); Console.WriteLine("Sum of:"); for (int i = 0; i < arr.Length; i++) { for (int j = 0; j < arr.Length; j++) { if (i != j) { int sum = arr[i] + arr[j]; if (sum == res) { Console.WriteLine(arr[i]); } } } } } } }
- Related Questions & Answers
- C Program to Add two Integers
- How to sum two integers without using arithmetic operators in C/C++ Program?
- Program to determine if two strings are close in Python
- C# program to determine if Two Words Are Anagrams of Each Other
- 8086 program to determine sum of corresponding elements of two arrays
- C Program to find sum of two numbers without using any operator
- Write Code to Determine if Two Trees are Identical in C++
- How to sum two integers without using arithmetic operators in C/C++?
- Sum of Two Integers in Python
- Program to check if two given matrices are identical in C++
- Java program to swap two integers
- Java program to add two integers
- Print all integers that are sum of powers of two given numbers in C++
- C# Program to convert integer array to string array
- Java Program To Determine If a Given Matrix is a Sparse Matrix
Advertisements