Previous answer was in C++, please learn the difference.
/**********************************************************
*josephus.c: Solve the josephus problem for an arbitrary number of players *and an arbtitrary number of players missed each time.
*
*Author: XXX
*
*Input1:Number of players
*Input2:Number of players to miss each time
*Output:The lucky Survivor
**********************************************************
#include <stdlib.h> /*For calloc, free and sizeof*/
#include <stdio.h> /*For printf, scanf*/
/*---Global structure to hold player details and a pointer to the next player---*/
struct player{
int player_num;
struct player *next;
};
int main (void) {
int i, j; /*Loop counters*/
int n; /*Number of players*/
int k; /*Number to skip each time*/
struct player *firstplayer; /*Hold firstplayer, so list can be circular linked*/
struct player *current_player; /*Hold current player*/
struct player *victim; /*Hold victim, for freeing*/
/*---Welcome statement---*/
printf("\njosephus.c: Program to solve the Josephus problem for an arbitrary number of "
"\n players and an arbitrary choice of count. The output will be the "
"\n number of the surviving player.\n\n");
/*---Request the number of players and assign to n---*/
printf("Please input the number of players.\n>>");
scanf("%d", &n) ;
/*---Request how many players to miss and assign to k---*/
printf("Please input the number of players you want to miss before execution.\n>>");
scanf("%d", &k);
/*---Alert the user, and exit the program, if they entered the wrong type of input---*/
if (n<=0 k<=0) {
printf("\a\n\nPlease enter positive integers only for the player and count!! "
"\nExiting...\n\n");
return 0;
}
/*---Set initial current player and firstplayer to be the same and assign space dynamically to hold them---*/
firstplayer=current_player=(struct player *)calloc(1, sizeof(struct player));
/*---Detect allocation failure---*/
if (current_player==NULL) {
printf("\a\nAllocation failure. Program terminates...\n\n");
exit(1);
}
current_player->player_num=1; /*Set the first/initial current players number to one*/
/*---Loop over n, assigning space for all the players and linking each successive one to
* the previous. Note: we do not count from 1, since already done above---*/
for (i=2; i<=n; ++i) {
current_player->next=(struct player *)calloc(1, sizeof(struct player));
/*---Detect allocation failure---*/
if (current_player->next==NULL) {
printf("\a\nAllocation failure. Program terminates...\n\n");
exit(1);
}
current_player=current_player->next; /*Current player now points to the next player*/
current_player->player_num=i; /*Define each player number*/
}
/*Finally link the final current player to the firstplayer, to make the list circular*/
current_player->next=firstplayer;
/*---Loop over n, counting up one every time a player dies---*/
for (i=1; i<n; ++i) {
/*Cycle through players until the one just before the unlucky one is reached*/
for (j=1; j<k; ++j) {
current_player=current_player->next;
}
/*Victim is the player just after the current player*/
victim=current_player->next;
/*Set the current player to point at the space just after where the victim was*/
current_player->next=current_player->next->next;
/*Set space now pointed to by victim free*/
free(victim);
}
/*Notify user of the game survivor*/
printf("\nThe lucky survivor is = %d\n\n", current_player->player_num);
/*---Set the final players space free---*/
free(current_player);
return 0;
}
C= pi * D This is the formula for circumference.
C=1.80g
I'm sorry, but I don't have access to specific problems or textbooks, including "stretching and shrinking 3.3 problem c." However, if you can provide the details or context of the problem, I'd be happy to help solve it or explain the concepts involved!
y = mx + c m = slope = rise/run c = y intercpt
DRQFOSAC is a math problem solving strategy. The letters are an anagram for the steps used to solve math problems. D = do (you have decided to do to problem). R = read (read the problem and any graphs/diagrams that go with the problem). Q = question (what question is being asked so you know what unit to use). F = facts (what are the facts given). O = operation (what operation) will you use to solve the problem). S = solve (time to solve the problem). A = answer (write the answer with units). C = check (check your work to make sure there are no silly mistakes). Good luck and happy computing!
in case of the c languages we are very flexible to to solve the problems in the step by step order (because of using the c-functions,other variables,other operators), debugging also so very easy because trace the exact steps which are given in the problem domains.
An Algorithm
algorithm is a step by step procedure to solve a problem in c,
a,b,c 123! that's your answer. XD
when government decides to solve a problem, it does so through a. lobbying b. bargaining c. lawmaking d. public policy
C= pi * D This is the formula for circumference.
C=1.80g
Solve and explain your steps on how you solve this problem. A cube has six sides, six edges and six faces. Each face represents a square. The area of one of the surfaces is equal to c² - 25 ( A= c² - 25). What is the measure of the side of a cube?
Well, darling, to solve for c when it's divided by 3 and equals 8, you simply multiply both sides by 3. This gives you c = 24. So, there you have it, c is 24. Math problem solved, next!
If a + b = cThen a = c -b
C++ is a programming language which gives the user the chance to create working applications through creating source code.
y = mx + c m = slope = rise/run c = y intercpt