Tuesday 5 June 2018

C Program without main() function

#include<stdio.h>   
 #define start main   
void start() {   
   printf("Hello");   
}

OUTPUT:-
                         Hello

C Program to convert Number in Characters

#include<stdio.h>   
#include<stdlib.h> 
int main()

   long int n,sum=0,r;   
   system("cls"); 
   printf("enter the number=");   
   scanf("%ld",&n);   
   while(n>0)   
  {   
    r=n%10;   
    sum=sum*10+r;   
    n=n/10;   
   }   
    n=sum;   
    while(n>0)   
    {   
       r=n%10;   
       switch(r)   
      {   
       case 1:   
        printf("one ");   
        break;   
       case 2:   
       printf("two ");   
       break;   
       case 3:   
       printf("three ");   
       break;   
       case 4:   
      printf("four ");   
      break;   
      case 5:   
      printf("five ");   
      break;   
      case 6:   
      printf("six ");   
      break;   
      case 7:   
     printf("seven ");   
     break;   
     case 8:   
     printf("eight ");   
     break;   
     case 9:   
     printf("nine ");   
     break;   
     case 0:   
     printf("zero ");   
     break;   
     default:   
     printf("Invalid choice!");   
     break;   
    }   
    n=n/10;   
  }   
   return 0; 
}  

C Program to print Alphabet Triangle

#include<stdio.h>   
#include<stdlib.h> 
int main(){ 
  int ch=65;   
    int i,j,k,m;   
  system("cls"); 
    for(i=1;i<=5;i++)   
    {   
        for(j=5;j>=i;j--)   
            printf(" ");   
        for(k=1;k<=i;k++)   
            printf("%c",ch++);   
            ch--;   
        for(m=1;m<i;m++)   
            printf("%c",--ch);   
        printf("\n");   
        ch=65;   
    }   
return 0; 


OUTPUT:-


C PROGRAMMING CODE FOR BANK APPLICATION

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

// Structure declaration
struct acc_type
{
     char bank_name[20];
     char bank_branch[20];
     char acc_holder_name[30];
     int acc_number;
     char acc_holder_address[100];
     float available_balance;   
};
struct acc_type account[20];

/*
     printf("The above structure can be declared using
     typedef like below");

     typedef struct acc_type
     {
        char bank_name[20];
        char bank_branch[20];
        char acc_holder_name[30];
        int acc_number;
        char acc_holder_address[100];
        float available_balance;   
     }Acc_detail;

     Acc_detail account[20];
*/

int num_acc;

void Create_new_account();
void Cash_Deposit();
void Cash_withdrawl();
void Account_information();
void Log_out();
void display_options();

/* main program */
int main()
{
    char option;
    char f2f[50] = "http://fresh2refresh.com/";
    num_acc=0;
    while(1)
    {
       printf("\n***** Welcome to Bank Application *****\n");
       printf("\nThis demo program is brought you by %s",f2f);
       display_options();
       printf("Please enter any options (1/2/3/4/5/6) ");
       printf("to continue : ");

        option = getch();
        printf("%c \n", option);
        switch(option)
        {
          case '1': Create_new_account();
                    break;
          case '2': Cash_Deposit();
                    break;
          case '3': Cash_withdrawl();
                    break;
          case '4': Account_information();
                    break;
          case '5': return 0;
          case '6': system("cls");
                    break;
          default : system("cls");
                    printf("Please enter one of the options");
                    printf("(1/2/3/4/5/6) to continue \n ");
                    break;
        }
    }
    return 0;
}

/*Function to display available options in this application*/

void display_options()
{
    printf("\n1. Create new account \n");
    printf("2. Cash Deposit \n");
    printf("3. Cash withdrawl \n");
    printf("4. Account information \n");
    printf("5. Log out \n");
    printf("6. Clear the screen and display available ");
    printf("options \n\n");
}

/* Function to create new account */

void Create_new_account()
{
   char bank_name[20];
   char bank_branch[20];
   char acc_holder_name[30];
   int acc_number;
   char acc_holder_address[100];
   float available_balance = 0;
   fflush(stdin);   
   printf("\nEnter the bank name              : ");
   scanf("%s", &bank_name);
   printf("\nEnter the bank branch            : ");
   scanf("%s", &bank_branch);
   printf("\nEnter the account holder name    : ");
   scanf("%s", &acc_holder_name);
   printf("\nEnter the account number(1 to 10): ");
   scanf("%d", &acc_number);
   printf("\nEnter the account holder address : ");
   scanf("%s", &acc_holder_address);

   strcpy(account[acc_number-1].bank_name,bank_name);
   strcpy(account[acc_number-1].bank_branch,bank_branch);
   strcpy(account[acc_number-1].acc_holder_name,
   acc_holder_name);
   account[acc_number-1].acc_number=acc_number;
   strcpy(account[acc_number-1].acc_holder_address,
   acc_holder_address);
   account[acc_number-1].available_balance=available_balance;

   printf("\nAccount has been created successfully \n\n");
   printf("Bank name              : %s \n" ,
   account[acc_number-1].bank_name);
   printf("Bank branch            : %s \n" ,
   account[acc_number-1].bank_branch);
   printf("Account holder name    : %s \n" ,
   account[acc_number-1].acc_holder_name);
   printf("Account number         : %d \n" ,
   account[acc_number-1].acc_number);
   printf("Account holder address : %s \n" ,
   account[acc_number-1].acc_holder_address);
   printf("Available balance      : %f \n" ,
   account[acc_number-1].available_balance);

   //num_acc++;

}

// Displaying account informations

void Account_information()
{
     register int num_acc = 0;
     //if (!strcmp(customer,account[count].name))
     while(strlen(account[num_acc].bank_name)>0)
     {
         printf("\nBank name                : %s \n" ,
         account[num_acc].bank_name);
         printf("Bank branch              : %s \n" ,
         account[num_acc].bank_branch);
         printf("Account holder name      : %s \n" ,
         account[num_acc].acc_holder_name);
         printf("Account number           : %d \n" ,
         account[num_acc].acc_number);
         printf("Account holder address   : %s \n" ,
         account[num_acc].acc_holder_address);
         printf("Available balance        : %f \n\n" ,
         account[num_acc].available_balance);
         num_acc++;
     }
}

// Function to deposit amount in an account

void Cash_Deposit()
{
   auto int acc_no;
   float add_money;

   printf("Enter account number you want to deposit money:");
   scanf("%d",&acc_no);
   printf("\nThe current balance for account %d is %f \n",
   acc_no, account[acc_no-1].available_balance);
   printf("\nEnter money you want to deposit :  ");
   scanf("%f",&add_money);

   while (acc_no=account[acc_no-1].acc_number)
   {
         account[acc_no-1].available_balance=
         account[acc_no-1].available_balance+add_money;
         printf("\nThe New balance for account %d is %f \n",
         acc_no, account[acc_no-1].available_balance);
         break;
   }acc_no++;
}

// Function to withdraw amount from an account

void Cash_withdrawl()
{
   auto int acc_no;
   float withdraw_money;

   printf("Enter account number you want to withdraw money:");
   scanf("%d",&acc_no);
   printf("\nThe current balance for account %d is %f \n",
   acc_no, account[acc_no-1].available_balance);
   printf("\nEnter money you want to withdraw from account ");
   scanf("%f",&withdraw_money);

   while (acc_no=account[acc_no-1].acc_number)
   {
         account[acc_no-1].available_balance=
         account[acc_no-1].available_balance-withdraw_money;
         printf("\nThe New balance for account %d is %f \n",
         acc_no, account[acc_no-1].available_balance);
         break;
   }acc_no++;
}


C program to print number from 1 to 500 without using any loop conditions:

1. Using recursive functions:

#include<stdio.h>
int recursive(int value)
{
      int i;
      printf("%d\n", value);
      i = value + 1;
      if (i > 500)
          return 0;
      recursive(i);
}

int main() 
{
      recursive(1);
      return 0;
}

2. Using recursive main functions:

#include<stdio.h>
int main() 
{
      static int i = 1;
      if (i <= 500) 
      {
          printf("%d\n", i++);
          main();
      }
      return 0;
}

3. Using goto statement:

#include<stdio.h>
int main() 
{
      int i = 0;
      Start: i = i + 1;
      printf("%d\n", i);
      if (i < 500)
           goto Start;
      return 0;
}

4. Using printf statement (But it's not preferred for printing big numbers):

Sorting inputs names in alphabetical order

#include <stdio.h>
#include <string.h>
int main()

{

   int i, j, num;

   char name[20][10], t_name[15][10], temp[20];

    printf("Please enter how many number of names to be sorted in alphabetical

order\n");

   scanf("%d", &num);

   printf("Please enter %d names one by one\n", num);

   for(i=0; i< num ; i++)

   {

      scanf("%s",name[i]);

      strcpy (t_name[i], name[i]);

   }


   for(i=0; i < num-1 ; i++)

   {

      for(j=i+1; j< num; j++)

      {

         if(strcmp(name[i],name[j]) > 0)

         {

             strcpy(temp,name[i]);

             strcpy(name[i],name[j]);

             strcpy(name[j],temp);

         }

      }

   }

    printf("Names before sorting in alphabetical order\n");

   for(i=0; i< num ; i++)

   {

      printf("%s\n",t_name[i]);

   }

    printf("Names after sorting in alphabetical order\n");

   for(i=0; i< num ; i++)

   {

      printf("%s\n",name[i]);

   }

 }

OUTPUT:-


Random Numbers generation using C

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main()
{
   int n, max, num, c;

   printf("Enter the number of random numbers you want\n");
   scanf("%d", &n);

   printf("Enter the maximum value of random number\n");
   scanf("%d", &max);

   printf("%d random numbers from 0 to %d are :-\n", n, max);

   randomize();

   for (c = 1; c <= n; c++)
   {
      num = random(max);
      printf("%d\n",num);       
   }

   getch();
   return 0;
}

OUTPUT:-

Find the Frequency of Characters in a given sentence

#include <stdio.h>

int main()
{
   char str[1000], ch;
   int i, frequency = 0;

   printf("Enter a string: ");
   gets(str);

   printf("Enter a character to find the frequency: ");
   scanf("%c",&ch);

   for(i = 0; str[i] != '\0'; ++i)
   {
       if(ch == str[i])
           ++frequency;
   }

   printf("Frequency of %c = %d", ch, frequency);

   return 0;
}

OUTPUT:-

C Program stores a sentence entered by user in a file.

#include <stdio.h>
#include <stdlib.h>  /* For exit() function */
int main()
{
   char sentence[1000];
   FILE *fptr;

   fptr = fopen("program.txt", "w");
   if(fptr == NULL)
   {
      printf("Error!");
      exit(1);
   }
 
   printf("Enter a sentence:\n");
   gets(sentence);

   fprintf(fptr,"%s", sentence);
   fclose(fptr);

   return 0;
}

OUTPUT:-

TO display its own source code using __FILE__ using C program

#include <stdio.h>
int main() {
    FILE *fp;
    char c;
    fp = fopen(__FILE__,"r");
    do {
         c = getc(fp);
         putchar(c);
    }
    while(c != EOF);
    fclose(fp);
    return 0;
}

OUTPUT:-

reverse words in a given string using c

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

void reverse_string(char*);
void reverse_words(char*);

int main() {
  char a[100];

  gets(a);

  reverse_words(a);

  printf("%s\n", a);

  return 0;
}

void reverse_words(char *s) {
  char b[100], *t, *z;
  int c = 0;

  t = s;

  while(*t) {                           //processing complete string
    while(*t != ' ' && *t != '\0') {    //extracting word from string
      b[c] = *t;
      t++;
      c++;
    }
    b[c] = '\0';
    c = 0;

    reverse_string(b);        // reverse the extracted word

    z = b;

    while (*z) {    //copying the reversed word into original string
      *s = *z;
      z++;
      s++;
    }

    while (*s == ' ') {                 // skipping space(s)
      s++;
    }
    /*
     * You may use if statement in place of while loop if
     * you are assuming only one space between words. If condition is
     * used because null terminator can also occur after a word, in
     * that case we don't want to increment pointer.
     * if (*s == ' ') {
     *   s++;
     * }
     */
    t = s;                              // pointing to next word
  }
}

/*
 * Function to reverse a word.
 */

void reverse_string(char *t) {
  int l, c;
  char *e, s;

  l = strlen(t);
  e = t + l - 1;

  for (c = 0; c < l/2; c++) {
    s  = *t;
    *t = *e;
    *e = s;
    t++;
    e--;
  }
}


OUTPUT:-

Decimal to binary number conversion in C

#include <stdio.h>

int main()
{
  int n, c, k;

  printf("Enter an integer in decimal number system\n");
  scanf("%d", &n);

  printf("%d in binary number system is:\n", n);

  for (c = 31; c >= 0; c--)
  {
    k = n >> c;

    if (k & 1)
      printf("1");
    else
      printf("0");
  }

  printf("\n");

  return 0;
}

OUTPUT:-

C program to insert a string with in another string (sub string)

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

void insert_substring(char*, char*, int);
char* substring(char*, int, int);

void main()
{
   char text[100], substring[100];
   int position;
   clrscr();
   printf("Enter some text\n");
   gets(text);

   printf("Enter a string to insert\n");
   gets(substring);

   printf("Enter the position to insert\n");
   scanf("%d", &position);

   insert_substring(text, substring, position);

   printf("%s\n",text);

   getch();
}

void insert_substring(char *a, char *b, int position)
{
   char *f, *e;
   int length;

   length = strlen(a);

   f = substring(a, 1, position - 1 );   
   e = substring(a, position, length-position+1);

   strcpy(a, "");
   strcat(a, f);
   free(f);
   strcat(a, b);
   strcat(a, e);
   free(e);
}

char *substring(char *string, int position, int length)
{
   char *pointer;
   int c;

   pointer = malloc(length+1);

   if( pointer == NULL )
       exit(EXIT_FAILURE);

   for( c = 0 ; c < length ; c++ )
      *(pointer+c) = *((string+position-1)+c);     

   *(pointer+c) = '\0';

   return pointer;
}

OUTPUT:-

Kaun Banega Crorepati quiz game using c

#include<stdio.h>
#include<stdio.h>
void main()
{
int i,a[10],n=0;
printf("WELCOME TO THE GAME""KAUN BANEGA CROREPATHI""It contains10 QUESTIONS each carries 10 LAKHS");

for(i=1;i<=10;i++)
{
n=0;
switch(i)
{
case 1:
printf("In what direction muslim pray 1.East 2.South 3.Nearby Mosque's direction 4.Mecca's direction ");
scanf("%d",&n);
if(n==4)
{
printf("You have entered the correct answer Now you have won Rs.%d00000 Your Next Question is ",i);
}
else
{
printf(" You have entered the wrong answer Better Luck Next Time You have earned Rs.%d00000",i-1);
i=11;
}
break;
case 2:
printf("Who is the Mother of RAMA in Ramayana 1.Kousalya 2.Kaikai 3.Sumitra 4.Mantra ");
scanf("%d",&n);
if(n==1)
{
printf("You have entered the correct answer Now you have won Rs.%d00000 Your Next Question is ",i);
}
else
{
printf(" You have entered the wrong answer Better Luck Next Time You have earned Rs.%d00000",i-1);
i=11;
}
break;
case 3:
printf("What is the Symbol of Nazis(Army of Great Hitler) 1.Cross 2.Skull and Bones 3.Owl 4.Swastika ");
scanf("%d",&n);
if(n==4)
{
printf("You have entered the correct answer Now you have won Rs.%d00000 Your Next Question is ",i);
}
else
{
printf(" You have entered the wrong answer Better Luck Next Time You have earned Rs.%d00000",i-1);
i=11;
}
break;
case 4:
printf("Who among these is not an Railway Minister 1.Mamtha Banerjee 2.Lal Bahadur Shastri 3.Geetha Mukerjee 4.George Fernandis ");
scanf("%d",&n);
if(n==3)
{
printf("You have entered the correct answer Now you have won Rs.%d00000 Your Next Question is ",i);
}
else
{
printf(" You have entered the wrong answer Better Luck Next Time You have earned Rs.%d00000",i-1);
i=11;
}
break;
case 5:
printf("Who Correctly Answered to Yaksha's Questions 1.Drona 2.Abimanyu 3.Yudishtira 4.Arjuna");
scanf("%d",&n);
if(n==3)
{
printf("You have entered the correct answerNow you have wonRs.%d00000Your Next Question is",i);
}
else
{
printf("You have entered the wrong answerBetter Luck NextTimeYou have earned Rs.%d00000",i-1);
i=11;
}
break;
case 6:
printf("Who Heads Reserve Bank of India1.FinanceMinister2.Commissioner3.Chief Bank Manager4.Governor");
scanf("%d",&n);
if(n==4)
{
printf("You have entered the correct answerNow you have wonRs.%d00000Your Next Question is",i);
}
else
{
printf("You have entered the wrong answerBetter Luck NextTimeYou have earned Rs.%d00000",i-1);
i=11;
}
break;
case 7:
printf("Which of these AnimalsLaughs1.Monkey2.Tiger3.Giraffe4.Hyna");
scanf("%d",&n);
if(n==4)
{
printf("You have entered the correct answerNow you have wonRs.%d00000Your Next Question is",i);
}
else
{
printf("You have entered the wrong answerBetter Luck NextTimeYou have earned Rs.%d00000",i-1);
i=11;
}
break;
case 8:
printf("Which is the system of Governance inChina1.communism2.communalism3.Monarchy4.Democratic");
scanf("%d",&n);
if(n==1)
{
printf("You have entered the correct answerNow you have wonRs.%d00000Your Next Question is",i);
}
else
{
printf("You have entered the wrong answerBetter Luck NextTimeYou have earned Rs.%d00000",i-1);
i=11;
}
break;
case 9:
printf("How many Rings does Olympic Symbolhave1.32.23.64.5");
scanf("%d",&n);
if(n==4)
{
printf("You have entered the correct answerNow you have wonRs.%d00000Your Next Question is",i);
}
else
{
printf("You have entered the wrong answerBetter Luck NextTimeYou have earned Rs.%d00000",i-1);
i=11;
}
break;
case 10:
printf("Who patronised Kalidas1.Akbar2.Chandra Guptha3.VikramaAditya4.Krishna Devaraya");
scanf("%d",&n);
if(n==3)
{
printf("You have entered the correct answerNow you have wonRs.%d00000*YOU HAVE BECOME CROREPATHI OF THIS WEEK*",i);
}
else
{
printf("You have entered the wrong answerBetter Luck NextTimeYou have earned Rs.%d00000",i-1);
i=11;
}
break;
default:
break;
}
}
getch();
}
OUTPUT:-

Quiz Game using C

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
void show_record();
void reset_score();
void help();
void edit_score(float , char []);
int main()
     {
     int countr,r,r1,count,i,n;
     float score;
     char choice;
     char playername[20];
     mainhome:
     system("cls");
     printf("\t\t\tC PROGRAM QUIZ GAME\n");
     printf("\n\t\t________________________________________");

     printf("\n\t\t\t   WELCOME ");
     printf("\n\t\t\t      to ");
     printf("\n\t\t\t   THE GAME ");
     printf("\n\t\t________________________________________");
     printf("\n\t\t________________________________________");
     printf("\n\t\t   BECOME A MILLIONAIRE!!!!!!!!!!!    ") ;
     printf("\n\t\t________________________________________");
     printf("\n\t\t________________________________________");
     printf("\n\t\t > Press S to start the game");
     printf("\n\t\t > Press V to view the highest score  ");
     printf("\n\t\t > Press R to reset score");
     printf("\n\t\t > press H for help            ");
     printf("\n\t\t > press Q to quit             ");
     printf("\n\t\t________________________________________\n\n");
     choice=toupper(getch());
     if (choice=='V')
{
show_record();
goto mainhome;
}
     else if (choice=='H')
{
help();getch();
goto mainhome;
}
else if (choice=='R')
{reset_score();
getch();
goto mainhome;}
else if (choice=='Q')
exit(1);
    else if(choice=='S')
    {
     system("cls");

    printf("\n\n\n\n\n\n\n\n\n\n\t\t\tResister your name:");
     gets(playername);

    system("cls");
    printf("\n ------------------  Welcome %s to C Program Quiz Game --------------------------",playername);
    printf("\n\n Here are some tips you might wanna know before playing:");
    printf("\n -------------------------------------------------------------------------");
    printf("\n >> There are 2 rounds in this Quiz Game,WARMUP ROUND & CHALLANGE ROUND");
    printf("\n >> In warmup round you will be asked a total of 3 questions to test your");
    printf("\n    general knowledge. You are eligible to play the game if you give atleast 2");
    printf("\n    right answers, otherwise you can't proceed further to the Challenge Round.");
    printf("\n >> Your game starts with CHALLANGE ROUND. In this round you will be asked a");
    printf("\n    total of 10 questions. Each right answer will be awarded $100,000!");
    printf("\n    By this way you can win upto ONE MILLION cash prize!!!!!..........");
    printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the");
    printf("\n    right option.");
    printf("\n >> You will be asked questions continuously, till right answers are given");
    printf("\n >> No negative marking for wrong answers!");
    printf("\n\n\t!!!!!!!!!!!!! ALL THE BEST !!!!!!!!!!!!!");
    printf("\n\n\n Press Y  to start the game!\n");
    printf("\n Press any other key to return to the main menu!");
    if (toupper(getch())=='Y')
{
    goto home;
        }
else
{
        goto mainhome;

       }

     home:

     count=0;
     for(i=1;i<=3;i++)
     {

     r1=i;


     switch(r1)
{
case 1:
printf("\n\nWhich of the following is a Palindrome number?");
printf("\n\nA.42042\t\tB.101010\n\nC.23232\t\tD.01234");
if (toupper(getch())=='C')
{
    printf("\n\nCorrect!!!");count++;
    getch();
    break;
}
else
       {
           printf("\n\nWrong!!! The correct answer is C.23232");
           getch();
       break;
       }

        case 2:
printf("\n\n\nThe country with the highest environmental performance index is...");
printf("\n\nA.France\t\tB.Denmark\n\nC.Switzerland\t\tD.Finland");
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");count++;
getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is C.Switzerland");
       getch();
       break;}

        case 3:
printf("\n\n\nWhich animal laughs like human being?");
printf("\n\nA.Polar Bear\t\tB.Hyena\n\nC.Donkey\t\tD.Chimpanzee");
if (toupper(getch())=='B')
{printf("\n\nCorrect!!!");count++;
getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is B.Hyena");
       getch();
       break;}

        case 4:
printf("\n\n\nWho was awarded the youngest player award in Fifa World Cup 2006?");
printf("\n\nA.Wayne Rooney\t\tB.Lucas Podolski\n\nC.Lionel Messi\t\tD.Christiano Ronaldo");
if (toupper(getch())=='B')
{printf("\n\nCorrect!!!");count++;
getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is B.Lucas Podolski");
       getch();
       break;}

        case 5:
        printf("\n\n\nWhich is the third highest mountain in the world?");
        printf("\n\nA.Mt. K2\t\tB.Mt. Kanchanjungha\n\nC.Mt. Makalu\t\tD.Mt. Kilimanjaro");
        if (toupper(getch())=='B')
               {printf("\n\nCorrect!!!");count++;
               getch();
                break;}
        else
       {printf("\n\nWrong!!! The correct answer is B.Mt. Kanchanjungha");
       getch();
       break;}

        case 6:
printf("\n\n\nWhat is the group of frogs known as?");
printf("\n\nA.A traffic\t\tB.A toddler\n\nC.A police\t\tD.An Army");
if (toupper(getch())=='D' )
{printf("\n\nCorrect!!!");count++;
getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is D.An Army");
       getch();
       break;}}
       }

if(count>=2)
{goto test;}
else
{
system("cls");
printf("\n\nSORRY YOU ARE NOT ELIGIBLE TO PLAY THIS GAME, BETTER LUCK NEXT TIME");
getch();
goto mainhome;
}
     test:
     system("cls");
     printf("\n\n\t*** CONGRATULATION %s you are eligible to play the Game ***",playername);
     printf("\n\n\n\n\t!Press any key to Start the Game!");
     if(toupper(getch())=='p')
{goto game;}
game:
     countr=0;
     for(i=1;i<=10;i++)
     {system("cls");
     r=i;

     switch(r)
{
case 1:
printf("\n\nWhat is the National Game of England?");
printf("\n\nA.Football\t\tB.Basketball\n\nC.Cricket\t\tD.Baseball");
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is C.Cricket");getch();
       goto score;
       }

case 2:
printf("\n\n\nStudy of Earthquake is called............,");
printf("\n\nA.Seismology\t\tB.Cosmology\n\nC.Orology\t\tD.Etimology");
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is A.Seismology");getch();
      goto score;

       }

        case 3:
printf("\n\n\nAmong the top 10 highest peaks in the world, how many lie in Nepal? ");
printf("\n\nA.6\t\tB.7\n\nC.8\t\tD.9");
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is C.8");getch();
       goto score;
       }

        case 4:
printf("\n\n\nThe Laws of Electromagnetic Induction were given by?");
printf("\n\nA.Faraday\t\tB.Tesla\n\nC.Maxwell\t\tD.Coulomb");
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
       {
                printf("\n\nWrong!!! The correct answer is A.Faraday");getch();
       goto score;

       }

        case 5:
printf("\n\n\nIn what unit is electric power measured?");
printf("\n\nA.Coulomb\t\tB.Watt\n\nC.Power\t\tD.Units");
if (toupper(getch())=='B')
{printf("\n\nCorrect!!!");countr++;getch(); break;}
else
       {
           printf("\n\nWrong!!! The correct answer is B.Power");
       getch();
       goto score;

       }

case 6:
printf("\n\n\nWhich element is found in Vitamin B12?");
printf("\n\nA.Zinc\t\tB.Cobalt\n\nC.Calcium\t\tD.Iron");
if (toupper(getch())=='B' )
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is B.Cobalt");goto score;

       }

        case 7:
printf("\n\n\nWhat is the National Name of Japan?");
printf("\n\nA.Polska\t\tB.Hellas\n\nC.Drukyul\t\tD.Nippon");
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is D.Nippon");getch();
       goto score;
       }

        case 8:
printf("\n\n\nHow many times a piece of paper can be folded at the most?");
printf("\n\nA.6\t\tB.7\n\nC.8\t\tD.Depends on the size of paper");
if (toupper(getch())=='B')
{printf("\n\nCorrect!!!");countr++;getch(); break;}
else
       {printf("\n\nWrong!!! The correct answer is B.7");getch();
       goto score;
       }

        case 9:
printf("\n\n\nWhat is the capital of Denmark?");
printf("\n\nA.Copenhagen\t\tB.Helsinki\n\nC.Ajax\t\tD.Galatasaray");
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is A.Copenhagen");getch();
       goto score;
       }

        case 10:
printf("\n\n\nWhich is the longest River in the world?");
printf("\n\nA.Nile\t\tB.Koshi\n\nC.Ganga\t\tD.Amazon");
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++;getch(); break;}
else
       {printf("\n\nWrong!!! The correct answer is A.Nile");getch();break;}

        case 11:
printf("\n\n\nWhat is the color of the Black Box in aeroplanes?");
printf("\n\nA.White\t\tB.Black\n\nC.Orange\t\tD.Red");
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
              {printf("\n\nWrong!!! The correct answer is C.Orange");getch();
      break;}

        case 12:
printf("\n\n\nWhich city is known at 'The City of Seven Hills'?");
printf("\n\nA.Rome\t\tB.Vactican City\n\nC.Madrid\t\tD.Berlin");
if (toupper(getch())=='A')
  {printf("\n\nCorrect!!!");countr++;getch();
   break;}
else
              {printf("\n\nWrong!!! The correct answer is A.Rome");getch();
      break;}

case 13:
printf("\n\n\nName the country where there no mosquitoes are found?");
printf("\n\nA.Japan\t\tB.Italy\n\nC.Argentina\t\tD.France");
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is D.France");getch();
       break;}

        case 14:
printf("\n\n\nWho is the author of 'Pulpasa Cafe'?");
printf("\n\nA.Narayan Wagle\t\tB.Lal Gopal Subedi\n\nC.B.P. Koirala\t\tD.Khagendra Sangraula");
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is A.Narayan Wagle");getch();
       break;}

case 15:
printf("\n\n\nWhich Blood Group is known as the Universal Recipient?");
printf("\n\nA.A\t\tB.AB\n\nC.B\t\tD.O");
if (toupper(getch())=='B')
{printf("\n\nCorrect!!!");countr++;getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is B.AB");getch();
       goto score;
       }

case 16:
printf("\n\n\nWhat is the unit of measurement of distance between Stars?");
printf("\n\nA.Light Year\t\tB.Coulomb\n\nC.Nautical Mile\t\tD.Kilometer");
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; getch();
break;
}
else
       {printf("\n\nWrong!!! The correct answer is A.Light Year");getch();
       goto score;
       }


case 17:
printf("\n\n\nThe country famous for Samba Dance is........");
printf("\n\nA.Brazil\t\tB.Venezuela\n\nC.Nigeria\t\tD.Bolivia");
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is A.Brazil");getch();goto score;
}

case 18:
printf("\n\n\nWind speed is measure by__________?");
printf("\n\nA.Lysimeter\t\tB.Air vane\n\nC.Hydrometer\t\tD.Anemometer\n\n");
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is D.Anemometer");getch();goto score;
       }

case 19:
printf("\n\n\nWhich city in the world is popularly known as The City of Temple?");
printf("\n\nA.Delhi\tB.Bhaktapur\n\nC.Kathmandu\tD.Agra\n\n");
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is C.Kathmandu");getch();goto score;
       }

case 20:
printf("\n\n\nWhich hardware was used in the First Generation Computer?");
printf("\n\nA.Transistor\t\tB.Valves\n\nC.I.C\t\tD.S.S.I");
if (toupper(getch())=='B')
{printf("\n\nCorrect!!!");countr++; getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is B.Valves");getch();goto score;
       }

case 21:
printf("\n\n\nOzone plate is being destroyed regularly because of____ ?");
printf("\n\nA.L.P.G\t\tB.Nitrogen\n\nC.Methane\t\tD. C.F.C");
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is D. C.F.C");getch();goto score;
       }

case 22:
printf("\n\n\nWho won the Women's Australian Open Tennis in 2007?");
printf("\n\nA.Martina Hingis\t\tB.Maria Sarapova\n\nC.Kim Clijster\t\tD.Serena Williams");
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is D.Serena Williams");getch();goto score;
       }

case 23:
printf("\n\n\nWhich film was awarded the Best Motion Picture at Oscar in 2010?");
printf("\n\nA.The Secret in their Eyes\t\tB.Shutter Island\n\nC.The King's Speech\t\tD.The Reader");
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; getch();
break;}
else
       {printf("\n\nWrong!!! The correct answer is C.The King's Speech");getch();goto score;
       }}}
score:
    system("cls");
score=(float)countr*100000;
if(score>0.00 && score<1000000)
{
   printf("\n\n\t\t**************** CONGRATULATION *****************");
     printf("\n\t You won $%.2f",score);goto go;}

else if(score==1000000.00)
{
    printf("\n\n\n \t\t**************** CONGRATULATION ****************");
    printf("\n\t\t\t\t YOU ARE A MILLIONAIRE!!!!!!!!!");
    printf("\n\t\t You won $%.2f",score);
    printf("\t\t Thank You!!");
}
else
{
printf("\n\n\t******** SORRY YOU DIDN'T WIN ANY CASH ********");
    printf("\n\t\t Thanks for your participation");
    printf("\n\t\t TRY AGAIN");goto go;}

go:
puts("\n\n Press Y if you want to play next game");
puts(" Press any key if you want to go main menu");
if (toupper(getch())=='Y')
goto home;
else
{
edit_score(score,playername);
goto mainhome;}}return 0;}

void show_record()
    {
char name[20];
float scr;
FILE *f;
f=fopen("score.txt","r");
fscanf(f,"%s%f",&name,&scr);
printf("\n\n\t\t*************************************************************");
printf("\n\n\t\t %s has secured the Highest Score %0.2f",name,scr);
printf("\n\n\t\t*************************************************************");
fclose(f);
getch();}

void reset_score()
    {
float sc;
char nm[20];
FILE *f;
f=fopen("score.txt","r+");
fscanf(f,"%s%f",&nm,&sc);
sc=0;
fprintf(f,"%s,%.2f",nm,sc);
    fclose(f);}

void help()
{system("cls");
    printf("\n\n                              HELP");
    printf("\n -------------------------------------------------------------------------");
    printf("\n ......................... C program Quiz Game...........");
    printf("\n >> There are two rounds in the game, WARMUP ROUND & CHALLANGE ROUND");
    printf("\n >> In warmup round you will be asked a total of 3 questions to test your general");
    printf("\n    knowledge. You will be eligible to play the game if you can give atleast 2");
    printf("\n    right answers otherwise you can't play the Game...........");
    printf("\n >> Your game starts with the CHALLANGE ROUND. In this round you will be asked");
    printf("\n    total 10 questions each right answer will be awarded $100,000.");
    printf("\n    By this way you can win upto ONE MILLION cash prize in USD...............");
    printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the");
    printf("\n    right option");
    printf("\n >> You will be asked questions continuously if you keep giving the right answers.");
    printf("\n >> No negative marking for wrong answers");

printf("\n\n\t*********************BEST OF LUCK*********************************");
printf("\n\n\t*****C PROGRAM QUIZ GAME is developed by CODE WITH C TEAM********");}

void edit_score(float score, char plnm[20])
{
float sc;
char nm[20];
FILE *f;
f=fopen("score.txt","r");
fscanf(f,"%s%f",&nm,&sc);
if (score>=sc)
  { sc=score;
    fclose(f);
    f=fopen("score.txt","w");
    fprintf(f,"%s\n%.2f",plnm,sc);
    fclose(f);}}

OUTPUT:-