Password protected program | C-Program

 Protect with password:

Tips :

  1.  Use if else statement for password checking.
  2.  Use a separate function for finding lcm because the main program will be less dirty.
  3.  You can change the default password in the program.
                           

Code :

#include<stdio.h>

int lcm3(int x, int y, int z)
{ 
  int minval;
   minval=(x>y)?((x>z)?x:z):((y>z)?y:z);
   while(1)
   {
    if(minval%x==0&&minval%y==0&&minval%z==0)
    {
     printf("LCM of %d , %d and %d is %d\n\n",x,y,z,minval);
     break;
    }
     minval++;
   }
 }
int main()
{ int lcm3(int x, int y, int z);
   int pass=12345,chkpass=0,q=0,x,y,z;
   nab : printf("         Welcome\n\nEnter the password :- ");
   scanf("%i",&chkpass);
   if(chkpass==pass)
   { printf("\n Access granted.\n\n");
     chkpass==0;
     while(q!=99)
     {
     refresh : printf("1. use threee digit lcm module.\n2. change password.\n99. Exit.\n");
     scanf("%i",&q);
     switch(q)
     { case 1: printf("\nEnter three digits :- \n");
               scanf("%i %i %i",&x,&y,&z);
               lcm3(x,y,z);
               break;
       case 2: printf("Enter the current password :- ");
               scanf("%i",&chkpass);
               if(chkpass==pass)
               { printf("\nEnter new password :- ");
                 scanf("%i",&pass);
                 printf("\nPassword saved successfully;\n\n");
                 goto nab;
              }
               else
               {printf("\n\nWrong password entered !!!\n\n");
                goto refresh;
               }
               break;
               case 99: printf("Good bye. have a nice day.\n");
      }
   }
 }
  else
 { printf("\nYou have entered a wrong password!!!!\n"); }
}

Output :




Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :