Hi I have very little knowledge of programming. Please help me with this program.
1) Sholey Program
In Ramghad there are 100 people including U
U are a food inspector.
Gabbar wants to kill all the people except one.
He tells samba to make the people of Ramghad to stand in a line one by one.
He tells samba to kill people in odd fashion
e.g if there are people say:
123456789.......then only odd will be killed
2468 .........will remain
now kill odd of them (2,6)
4 8 ......will remain now
then 4 will be killed since 4 is odd now
....survivor is 8
Now the problem is U should create a program to find the survivor for
N number instead of 100
#include<iostream.h>
int main()
{
int a[100];
int n=0;
cout<<" Enter The Size Of Array ";
cout<<" Enter The number ";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
Let the people in the beginning be 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
After 1st kill: 2,4,6,8,10,12,14,16
After 2nd kill: 4,8,12,16
After 3rd kill: 8,16
After 4th kill: 16
The survivor will be the man in the 16th position
Notice that after nth kill, survivors are at a position which is a multiple of 2^{n}.
Last survivor will be the person standing at the position number which is a multiple of the largest power of 2 (if there are 100 people, answer is 64th person)
You shouldn't have put the Babbar Singh story in the post, it would just confuse people.