Pages

Friday, 9 February 2018

In an inter-college competition, various sports and games are played between different colleges like cricket, basketball, football, hockey, lawn tennis, table tennis, carom and chess. The information regarding the games won by a particular college is stored in bit numbers 0, 1, 2, 3, 4, 5, 6, 7 and 8 respectively of an integer variable called game. The college that wins in 5 or more than 5 games is awarded the Champion of Champions trophy. If a number is entered through the keyboard, then write a program to find out whether the college won the Champion of the Champions trophy or not, along with the names of the games won by the college.


In an inter-college competition, various sports and games are played between different colleges like cricket, basketball, football, hockey, lawn tennis, table tennis, carom and chess. The information regarding the games won by a particular college is stored in bit numbers 0, 1, 2, 3, 4, 5, 6, 7 and 8 respectively of an integer variable called game. The college that wins in 5 or more than 5 games is awarded the Champion of Champions trophy. If a number is entered through the keyboard, then write a program to find out whether the college won the Champion of the Champions trophy or not, along with the names of the games won by the college.

#include<stdio.h>
#include<conio.h>
void main() {

int game;
int i,won=0,name;

clrscr();


printf("Enter number: ");

scanf("%d",&name);

printf("\n\n");

for(i=1;i<=8;i++) {

game=i&name;


if(game==1) {
printf("Cricket\n");

won++;
}

if(game==2) {
printf("Basketball\n");

won++;
}

if(game==3) {
printf("Football\n");

won++;
}

if(game==4) {
printf("Hockey\n");

won++;
}

if(game==5) {
printf("Lawn-tennis\n");

won++;
}

if(game==6) {
printf("Table-tennis\n");

won++;
}

if(game==7) {
printf("Carrom\n");

won++;
}

if(game==8) {
printf("Chess\n");

won++;
}

}

if(won>=5) {

printf("\n\n\nCollege %d has won the champions trophy\n",name);

}

else {

printf("\n\n\nCollege %d didn't win the champions trophy\n",name);

}

getch();
}