You are on page 1of 5

/*2013-6376

*Apple Mae P. Sarillana


* BS ECT-B III
* csit.a

*2013-5697
*Michelle E. Raterta
* BS ECT-A III
* csit.a */

#include <stdio.h>
#include <string.h>

int main ()
{
int i, Hostages = 5, Counts, target[5], HostageNumber[5] = {0, 1, 2, 3,
4};
char HostageName[5][10];
strcpy (HostageName[0], "Johnny");
strcpy (HostageName[1], "John");
strcpy (HostageName[2], "Jun");
strcpy (HostageName[3], "James");
strcpy (HostageName[4], "Jay");

while(Hostages > 1)
{
printf("\n\n\nEnter the number of counts: ");
scanf("%d", &Counts);

target[Hostages] = (Counts % Hostages) - 1;


if (target[Hostages] == -1)
{
target[Hostages] = Hostages - 1;
}

printf("\n\nHostage number %s is dead.\n\n",


HostageName[HostageNumber[target[Hostages]]]);

for(i = target[Hostages]; i<5 ; i++)


{
HostageNumber[i] = HostageNumber[i + 1];
HostageNumber[i + 1] = HostageNumber[i + 2];
}

--Hostages;
if (Hostages == 1)
{
printf("\n\n\nOnly Hostage number %s is left.\n\n\n",
HostageName[HostageNumber[0]]);
return 0;
}
}

}
Michelle E. Raterta
Apple Mae P. Sarillana
CSC 101-Csit.A

ALGORITHMS:

Step 1:
Write a program that will store the save hostage into an
array and then will display the output of the last hostage.

Step 2:
Input the number of count.

Step 3:
Any number of counts will be entered

Step 4:
Number %s hostage will be dead and so it follows when we
enter any number of counts

Step 5 :
Number %s will be the output

Step 6:
Save

#include <stdio.h>
#include <string.h>

int main ()
{
int i, j, Hostages, Counts;

printf("\n\nEnter number of hostages: ");


scanf("%d", &Hostages);

int HostageNumber[Hostages], target[Hostages];


char HostageName[Hostages][100];

for(j=0; j<Hostages; j++)


{
printf ("\nEnter the name of hostage number %d:", j + 1);
scanf(" %[^\n]s", HostageName[j]);
HostageNumber[j] = j;
}

while(Hostages > 1)
{
printf("\n\n\nEnter the number of counts: ");
scanf("%d", &Counts);

target[Hostages] = (Counts % Hostages) - 1;


if (target[Hostages] == -1)
{
target[Hostages] = Hostages - 1;
}

printf("\n\nHostage number %s is dead.\n\n",


HostageName[HostageNumber[target[Hostages]]]);

for(i = target[Hostages]; i<5 ; i++)


{
HostageNumber[i] = HostageNumber[i + 1];
HostageNumber[i + 1] = HostageNumber[i + 2];
}

--Hostages;
if (Hostages == 1)
{
printf("\n\n\nOnly Hostage %s is left.\n\n\n",
HostageName[HostageNumber[0]]);
return 0;
}
}
}

You might also like