Given N numbers from 1,2,3 ... N-1 and one other number... Find that one.
#include<iostream>
using namespace std;
#define N 11
int main()
{
int array[N] = {1,2,3,4,5,6,7,8,9,10,5};
int total = 0, sumOfN;
sumOfN = (N * (N-1)) / 2;
for(int i=0; i<n; i++)
{
total = total + array[i];
}
cout << total - sumOfN <<endl;
}
#include<iostream>
using namespace std;
#define N 11
int main()
{
int array[N] = {1,2,3,4,5,6,7,8,9,10,5};
int total = 0, sumOfN;
sumOfN = (N * (N-1)) / 2;
for(int i=0; i<n; i++)
{
total = total + array[i];
}
cout << total - sumOfN <<endl;
}
No comments:
Post a Comment