You have an array having numbers 1 to 100 but one number is missing? find out the missing number?

Questions by rupinder01

Showing Answers 1 - 6 of 6 Answers

Its simple.
1. do calculate the sum of numbers from 1 till 100. is about (1+100)*(100/2)=5050
2. iterate and summarize all elements of container (array).
3. each number is unique in the container, so the difference between 5050 and the sum (from point 2) gives us an answer.

  Was this answer useful?  Yes

harshitha

  • Feb 7th, 2014
 

Calculate the sum of 1 to 100 i.e sum=(1+100)*(100/2)=5050

Code
  1. int main()

  2. {

  3.       int sum=5050,res=0,temp=0,i;

  4.       int str[200]={1,2,3.............99,100};

  5.       for(i=0;i<100;i++)

  6.       {

  7.            res=res+str[i];

  8.        }

  9.        temp=sum-res;

  10.        printf("missing number is %d

  11. ",temp);

  12.        getch();

  13. }      

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions