Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 - write a program to print all the ASCII values and their equivalent character

ID: 3561302 • Letter: 1

Question

1 - write a program to print all the ASCII values and their equivalent characters using a while loop.
the ASCII values vary from 0 to 255.

2 - write a program for a matchstick game being played between the computer and a user.
your program should ensure that the computer always wins.
Rules for the game are as follows:

i-There are 21 matchsticks.

ii-The computer asks the player to pick 1,2,3 or 4 matchsticks.

iii- After the person picks the computer does its picking.

iv- Whoever is forced to pick up the last matchstick loses the game.

Explanation / Answer

1 - /*print ASCII values and their corresponding characters*/

#include<stdio.h>

int main()

{

int i=0;

while(i<=255)

{

printf("%d %c ",i,i);

i++;
}
return 0;
}

2 -

/*matchstick game*/

#include<stdio.h>

int main()

{

int m=21,p,c;

while(1)

{

printf(" no of matches left =%d ",m);

printf("pick up 1,2,3 or 4 matches:");

scanf("%d",&p);

if(p>4||p<1)

continue;

m=m-p;

printf("no of matches left=%d ",m);

c=5-p;

printf("out of which computer picked up %d ",c);

m=m-c;

if(m==1)

{

printf("number of matches left %d ",m);

printf("you lost the game!! ");

break;

}

}

return 0;

}