Wednesday, 19 August 2015

Codes for a record entry project

/******************************************
  Application: Record Entry System
  Compiled on: Borland Turbo C++ 3.0
 
******************************************/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <ctype.h>
void dataentry(void);
void selectAdminOption(void);
void getData(int option);
int showAdminMenu;
void main()
{
 int cancelOption,timeOption,entryOption,exitOption;
 char choice[1];
 char selectOption[1];
 textcolor(YELLOW);
 cancelOption=0;

 /* Shows the main menu for the application*/
        while (cancelOption==0)
 {
  clrscr();
  gotoxy(30,7);
  printf("Please Select an Action-->");
  gotoxy(30,10);
  printf("Daily Time Record [1] ");
  gotoxy(30,11);
  printf("Data Entry        [2] ");
  gotoxy(30,12);
  printf("Close             [3] ");
  gotoxy(30,15);
  printf("Please Enter Your Choice (1/2/3): ");
  scanf("%s",&choice);
  timeOption=strcmp(choice,"1");
  entryOption=strcmp(choice,"2");
  exitOption=strcmp(choice,"3");

  if (timeOption==0)
  {
  clrscr();
  gotoxy(23,6);
  printf("DAILY EMPLOYEE TIME RECORDING SYSTEM");
  gotoxy(16,24);
  printf("Input Any Other key to Return to Previous Screen.");
  gotoxy(31,9);
  printf("[1] Employee Log In ");
  gotoxy(31,10);
  printf("[2] Employee Log Out");
  gotoxy(28,12);
  printf("Please Enter Your Option: ");
  scanf("%s",&selectOption);
  if (strcmp(selectOption,"1")==0)
  {
     getData(5);
  }
  if (strcmp(selectOption,"2")==0)
  {
     getData(6);
  }
  cancelOption=0;
  }
  if (entryOption==0)
  {
  dataentry();
  cancelOption=0;
  }
  if (exitOption==0)
  {
  cancelOption=1;
  }
  if (!(timeOption==0 || entryOption==0 || exitOption==0))
  {
                   gotoxy(10,17);
     printf("You Have Entered an Invalid Option. Please Choose Either 1, 2 or 3. ");
     getch();
     cancelOption=0;
  }
 }
 clrscr();
 gotoxy(23,13);
 printf("The Application will Close Now. Thanks!");
 getch();
}
/* This function provides logic for data entry to be done for the system.
Access to Data Entry screens will be only allowed to administrator user.*/
void dataentry(void)
{
char adminName[10], passwd[5],buffer[1];
char tempo[6],sel[1];
int validUserNameOption,validUserPwdOption,returnOption,UserName,inc,tmp;
char plus;
 clrscr();
 validUserNameOption=0;
 validUserPwdOption=0;
 while (validUserPwdOption==0)
 {
  clrscr();
  while (validUserNameOption==0)
  {
   clrscr();
   gotoxy(20,5);
   printf("IT SOFTWARE DATA ENTRY SYSTEM-ADMIN INTERFACE");
   gotoxy(20,24);
   printf("Info: Type return to go back to the main screen.");
   gotoxy(28,10);
   printf("Enter Administrator Name: ");
   scanf("%s",&adminName);
   returnOption=strcmp(adminName,"return");
   UserName=strcmp(adminName,"admin");
   if (returnOption==0)
   {
   goto stream;
   }
   if (!(UserName==0 || returnOption==0))
   {
   gotoxy(32,11);
   printf("Administrator Name is Invalid.");
   getch();
   validUserNameOption=0;
   }
   else
   validUserNameOption=1;
  }
 gotoxy(30,11);
 printf("Enter Password: ");
 inc=0;
 while (inc<5)
 {
  passwd[inc]=getch();
  inc=inc+1;
  printf("* ");
 }
 inc=0;
 while (inc<5)
 {
  tempo[inc]=passwd[inc];
  inc=inc+1;
 }
 while(getch()!=13);
 if (!strcmp(tempo, "admin12"))
  {
                        gotoxy(28,13);
   printf("You have Entered a Wrong Password. Please Try Again. ");
   getch();
   validUserPwdOption=0;
   validUserNameOption=0;
  }
  else
  {
   clrscr();
   gotoxy(24,11);
   textcolor(YELLOW+BLINK);
   cprintf("You Have Successfully Logged In.");
   gotoxy(24,17);
   textcolor(YELLOW);
   printf("Press Any Key to Continue.");
   validUserPwdOption=1;
   validUserNameOption=1;
   getch();
   showAdminMenu=0;
       while (showAdminMenu==0)
       {
   clrscr();
   gotoxy(24,4);
   printf("ADMIN OPTIONS");
   gotoxy(26,9);
   printf("Add New Employee       [1]");
   gotoxy(26,11);
   printf("Show Daily Entries     [2]");
   gotoxy(26,13);
   printf("Search Employee Record [3]");
   gotoxy(26,15);
   printf("Remove Employee        [4]");
   gotoxy(26,17);
   printf("Close                  [5]");
   gotoxy(24,21);
   printf("Please enter your choice: ");
   selectAdminOption();
     }
  }
 }
stream:{}
}
/* This function provides the administrator level functionalities, such as Adding or deleting an employee.*/
void selectAdminOption(void)
{
  char chc[1];
  int chooseNew,chooseShow,chooseSearch,chooseRemove,chooseClose;
  gets(chc);
  chooseNew=strcmp(chc,"1");
  chooseShow=strcmp(chc,"2");
  chooseSearch=strcmp(chc,"3");
  chooseRemove=strcmp(chc,"4");
  chooseClose=strcmp(chc,"5");
  if (!(chooseNew==0 || chooseShow==0 || chooseSearch==0 || chooseRemove==0 || chooseClose==0))
  {
     gotoxy(19,21);
     textcolor(RED+BLINK);
     cprintf("Invalid Input!");
     gotoxy(34,21);
     textcolor(YELLOW);
     cprintf("Press any key to continue.");
  }
  if (chooseNew==0)
  {
     clrscr();
     gotoxy(25,5);
     getData(1);
  }
  else if(chooseShow==0)
  {
     getData(2);
  }
  else if(chooseSearch==0)
  {
     clrscr();
     getData(3);
  }
  else if(chooseRemove==0)
  {
     getData(4);
  }
  else if (chooseClose==0)
  {
     showAdminMenu=1;
  }
}
/* This function retreives data from the database as well as do data processing according to user requests.
   The function provides functionality for menu options provided to both employee as well as administrator user*/
void getData(int option)
{
 FILE *db,*tempdb;
 char anotherEmp;
 int choice;
 int showMenu,posx,posy;
 char checkSave,checkAddNew;
 int i;
 struct employee
 {
        char firstname[30];
 char lastname[30];
 char password[30];
 int  empid;
 char loginhour;
 char loginmin;
 char loginsec;
 char logouthour;
 char logoutmin;
 char logoutsec;
 int yr;
 char mon;
 char day;
 };
 struct employee empData;
 char confirmPassword[30];
 long int size;
 char lastNameTemp[30],firstNameTemp[30],password[30];
 int searchId;
 char pass[30];
 char findEmployee;
 char confirmDelete;
 struct date today;
 struct time now;
 clrscr();
 /* Opens the Employee Database*/
 db=fopen("d:/empbase.dat","rb+");
 if(db==NULL)
 {
  db=fopen("d:/empbase.DAT","wb+");
  if(db==NULL)
  {
   printf("The File could not be opened.\n");
   exit();
  }
 }
  printf("Application Database \n");
  size=sizeof(empData);
  showMenu=0;
  while(showMenu==0)
  {
   fflush(stdin);
   choice=option;
   /* Based on the choice selected by admin/employee, this switch statement processes the request*/
   switch(choice)
   {
   /* To add a new employee to the database*/
   case 1:
    fseek(db,0,SEEK_END);
    anotherEmp='y';
    while(anotherEmp=='y')
    {
                   checkAddNew=0;
     while(checkAddNew==0)
     {
     clrscr();
     gotoxy(25,3);
     printf("ADD A NEW EMPLOYEE");
     gotoxy(13,22);
     printf("Warning: Password Must Contain Six(6) AlphaNumeric Digits.");
     gotoxy(5,8);
     printf("Enter First Name: ");
     scanf("%s",&firstNameTemp);
     gotoxy(5,10);
     printf("Enter Last Name: ");
     scanf("%s",&lastNameTemp);
     gotoxy(43,8);
     printf("Enter Password: ");
     for (i=0;i<6;i++)
     {
      password[i]=getch();
      printf("* ");
     }
     password[6]='\0';
     while(getch()!=13);
     gotoxy(43,10);
     printf("Confirm Password: ");
     for (i=0;i<6;i++)
     {
      confirmPassword[i]=getch();
      printf("* ");
     }
     confirmPassword[6]='\0';
     while(getch()!=13);
     if (strcmp(password,confirmPassword))
     {
        gotoxy(24,12);
               printf("Passwords do not match.");
        gotoxy(23,13);
        printf("Press any key to continue.");
        getch();
     }
     else
     {
     checkAddNew=1;
     rewind(db);
     empData.empid=0;
     while(fread(&empData,size,1,db)==1);
     if (empData.empid<2000)
     empData.empid=20400;
     empData.empid=empData.empid+1;
     gotoxy(29,16);
     printf("Save Employee Information? (y/n): ");
     checkSave=getche();
     if (checkSave=='y')
     {
     strcpy(empData.firstname,firstNameTemp);
     strcpy(empData.lastname,lastNameTemp);
     strcpy(empData.password,password);
     empData.loginhour='t';
     empData.logouthour='t';
     empData.day='j';
     fwrite(&empData,size,1,db);
     }
     gotoxy(28,16);
     printf("                        ");
     gotoxy(28,16);
     printf("Would like to add another employee? (y/n):");
     fflush(stdin);
     anotherEmp=getche();
     printf("\n");
     }
     }
    }
    break;
   /* To view time records for all employees*/
   case 2:
    clrscr();
    gotoxy(21,2);
    printf("VIEW EMPLOYEE INFORMATION");
    gotoxy(1,5);
    printf("Employee ID  Employee Name     Time Logged In     Time Logged Out     Date\n\n");
    rewind(db);
    posx=3;
    posy=7;
    while(fread(&empData,size,1,db)==1)
    {
     empData.firstname[0]=toupper(empData.firstname[0]);
     empData.lastname[0]=toupper(empData.lastname[0]);
     gotoxy(posx,posy);
     printf("%d",empData.empid);
     gotoxy(posx+10,posy);
     printf("| %s, %s",empData.lastname,empData.firstname);
     gotoxy(posx+30,posy);
     if (empData.loginhour=='t')
     {
      printf("| Not Logged In");
     }
     else
     printf("| %d:%d:%d",empData.loginhour,empData.loginmin,empData.loginsec);
     gotoxy(posx+49,posy);
     if (empData.logouthour=='t')
     {
     printf("| Not Logged Out");
     }
     else
     printf("| %d:%d:%d",empData.logouthour,empData.logoutmin,empData.logoutsec);
     if (empData.day=='j')
     {
     gotoxy(posx+69,posy);
     printf("| No Date");
     }
     else
     {
     gotoxy(posx+73,posy);
     printf("| %d/%d/%d",empData.mon,empData.day,empData.yr);
     }
     posy=posy+1;
    }
           getch();
    printf("\n");
    break;
  /* To search a particular employee and view their time records*/
  case 3:
    clrscr();
    gotoxy(27,5);
    printf("SEARCH EMPLOYEE INFORMATION");
    gotoxy(25,9);
    printf("Enter Employee Id to Search: ");
    scanf("%d", &searchId);
    findEmployee='f';
    rewind(db);
           while(fread(&empData,size,1,db)==1)
    {
        if (empData.empid==searchId)
        {
  gotoxy(33,11);
  textcolor(YELLOW+BLINK);
  cprintf("Employee Information is Available.");
  textcolor(YELLOW);
  gotoxy(25,13);
  printf("Employee name is: %s %s",empData.lastname,empData.firstname);
  if(empData.loginhour=='t')
  {
  gotoxy(25,14);
  printf("Log In Time: Not Logged In");
  }
  else
  {
  gotoxy(25,14);
  printf("Log In Time is: %d:%d:%d",empData.loginhour,empData.loginmin,empData.loginsec);
  }
  if(empData.logouthour=='t')
  {
  gotoxy(25,15);
  printf("Log Out Time: Not Logged Out");
  }
  else
  {
  gotoxy(25,15);
  printf("Log Out Time is: %d:%d:%d",empData.logouthour,empData.logoutmin,empData.logoutsec);
  }
  findEmployee='t';
        getch();
        }
    }
    if (findEmployee!='t')
    {
    gotoxy(30,11);
    textcolor(YELLOW+BLINK);
    cprintf("Employee Information not available. Please modify the search.");
    textcolor(YELLOW);
    getch();
    }
    break;
  /* To remove entry of an employee from the database*/
  case 4:
    clrscr();
    gotoxy(25,5);
    printf("REMOVE AN EMPLOYEE");
    gotoxy(25,9);
    printf("Enter Employee Id to Delete: ");
    scanf("%d", &searchId);
    findEmployee='f';
    rewind(db);
           while(fread(&empData,size,1,db)==1)
    {
        if (empData.empid==searchId)
        {
  gotoxy(33,11);
  textcolor(YELLOW+BLINK);
  cprintf("Employee Information is Available.");
  textcolor(YELLOW);
  gotoxy(25,13);
  printf("Employee name is: %s %s",empData.lastname,empData.firstname);
  findEmployee='t';
        }
    }
    if (findEmployee!='t')
    {
    gotoxy(30,11);
    textcolor(YELLOW+BLINK);
    cprintf("Employee Information not available. Please modify the search.");
    textcolor(YELLOW);
    getch();
    }
    if (findEmployee=='t')
    {
    gotoxy(29,15);
    printf("Do you want to Delete the Employee? (y/n)");
    confirmDelete=getche();
  if (confirmDelete=='y' || confirmDelete=='Y')
  {
  tempdb=fopen("d:/tempo.dat","wb+");
  rewind(db);
  while(fread(&empData,size,1,db)==1)
   {
    if (empData.empid!=searchId)
    {
    fseek(tempdb,0,SEEK_END);
    fwrite(&empData,size,1,tempdb);
    }
   }
  fclose(tempdb);
  fclose(db);
  remove("d:/empbase.dat");
  rename("d:/tempo.dat","d:/empbase.dat");
  db=fopen("d:/empbase.dat","rb+");
  }
    }
    break;
  /* To login an employee into the system and record the login date and time*/
  case 5:
    clrscr();
    gotoxy(20,4);
    printf("DAILY EMPLOYEE TIME RECORDING SYSTEM");
    gotoxy(20,23);
    printf("Warning: Please Enter Numeric Values Only.");
    gotoxy(23,7);
    printf("Enter Your Id to Login: ");
    scanf("%d", &searchId);
    gotoxy(20,23);
    printf("                                            ");
    findEmployee='f';
    rewind(db);
           while(fread(&empData,size,1,db)==1)
    {
        if (empData.empid==searchId)
        {
  gotoxy(23,8);
  printf("Enter Your Password: ");
                 for (i=0;i<6;i++)
     {
      pass[i]=getch();
      printf("* ");
     }
     pass[6]='\0';
   while(getch()!=13);
  if (strcmp(empData.password,pass))
  {
   gotoxy(23,11);
   textcolor(YELLOW+BLINK);
   cprintf("You Have Supplied a Wrong Password.");
   textcolor(YELLOW);
   findEmployee='t';
   getch();
   break;
  }
  gotoxy(23,11);
  textcolor(YELLOW+BLINK);
  cprintf("You have successfully Logged In the System.");
  textcolor(YELLOW);
  gotoxy(23,13);
  printf("Employee name: %s %s",empData.lastname,empData.firstname);
  gettime(&now);
  getdate(&today);
  gotoxy(23,14);
  printf("Your LogIn Time: %2d:%2d:%2d",now.ti_min,now.ti_hour,now.ti_sec);
  gotoxy(23,15);
  printf("Your Log In Date: %d/%d/%d",today.da_mon,today.da_day,today.da_year);
  empData.day=today.da_day;
  empData.mon=today.da_mon;
  empData.yr=today.da_year;
  fseek(db,-size,SEEK_CUR);
  empData.loginhour=now.ti_min;
  empData.loginmin=now.ti_hour;
  empData.loginsec=now.ti_sec;
  fwrite(&empData,size,1,db);
  findEmployee='t';
  getch();
        }
    }
    if (findEmployee!='t')
    {
    gotoxy(30,11);
    textcolor(YELLOW+BLINK);
    cprintf("Employee Information is not available.");
    textcolor(YELLOW);
    getch();
    }
    break;
  /* To logout an employee and record the logout date and time*/
  case 6:
           clrscr();
    gotoxy(20,4);
    printf("DAILY EMPLOYEE TIME RECORDING SYSTEM");
    gotoxy(20,23);
    printf("Warning: Please Enter Numeric Values Only.");
    gotoxy(23,7);
    printf("Enter Your Id to Logout: ");
    scanf("%d", &searchId);
    gotoxy(20,23);
    printf("                                            ");
    findEmployee='f';
    rewind(db);
           while(fread(&empData,size,1,db)==1)
    {
        if (empData.empid==searchId)
        {
  gotoxy(23,8);
  printf("Enter Password: ");
                 for (i=0;i<6;i++)
     {
      pass[i]=getch();
      printf("* ");
     }
     pass[6]='\0';
   while(getch()!=13);
  if (strcmp(empData.password,pass))
  {
   gotoxy(30,11);
   textcolor(YELLOW+BLINK);
   cprintf("You Have Supplied a Wrong Password.");
   textcolor(YELLOW);
   findEmployee='t';
   getch();
   break;
  }
  gotoxy(23,11);
  textcolor(YELLOW+BLINK);
  cprintf("You have successfully Logged Out of the System.");
  textcolor(YELLOW);
  gotoxy(23,13);
  printf("Employee name is: %s %s",empData.lastname,empData.firstname);
  gettime(&now);
  getdate(&today);
  gotoxy(23,14);
  printf("Your Log Out Time: %2d:%2d:%2d",now.ti_min,now.ti_hour,now.ti_sec);
  gotoxy(23,15);
  printf("Your Log Out Date: %d/%d/%d",today.da_mon,today.da_day,today.da_year);
  fseek(db,-size,SEEK_CUR);
  empData.logouthour=now.ti_min;
  empData.logoutmin=now.ti_hour;
  empData.logoutsec=now.ti_sec;
  fwrite(&empData,size,1,db);
  findEmployee='t';
  getch();
        }
    }
    if (findEmployee!='t')
    {
    gotoxy(23,11);
    textcolor(YELLOW+BLINK);
    cprintf("Employee Information is not available.");
    textcolor(YELLOW);
    getch();
    }
    break;
  /* Show previous menu*/
  case 9:
    printf("\n");
    exit();
    }
   fclose(db);
   showMenu=1;
   }
 }

Why we learn C language today?

  •  There are some other language like as C++,C# and Java, its languages are more advanced then c,then why we learn C today? There are some reason behind this question that's are following:
    1. C is the basic(mother) of all other languages.When you had learned c, you are easily deal with classes,object,template,structure,polymorphic and with familiar terminology.
    2. C++,C# and Java are OOP(Object Oriented Programming) languages.So when u creating object u must still a good command on C language.
    3. Major parts of OS(Operating System) like as Windows,UNIX,Linux are still written in C.
    4. C language is known for owns speed and execution.
    5. Today daily routine apparatus like as microwave,washing,digital camera's,microprocessor,and operating system,smart phones are worked in C programs.
    6. Maximum 3-d games are built in C.
  • So now let's start to learn C.

    C Basic

    #. What is language? 
    • A language is medium in which two or more object/person communicate their thought,information,data etc. C is computer language. Computer languages are generally two types:
      1. High Level Language-Translator required must example: FORTRAN
      2. Low Level Language-Not requirement translator example: machine language(0 , 1)
    •  C is a high level language with low level programming features so it is also called procedure object oriented language i.e. we can write program either in machine language(0,1) or general English keyword(HLL).
    •  C is a structured programming language,that is developed by Dennis Ritchie in 1972 at AT & Bell Laboratories in USA. 
    • Some basic tips for C Programs and C language:
      1. Each instruction in a C program is written as a separate statement. Therefore, a complete C program would comprise a series of statements.
      2. The statement in a program must appear in the same order in which we wish them to be executed, unless the result will be differ as we want wish.
      3. All statement are entered in Small case letters.
      4. Every C statement must be end with a semicolon (;). This is act that statement has been terminated
      5. C is "free form language" i.e. there are no specific rule for where the statement write.

    Programming in C to test that the given number is prime or not

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int n,x=2;
    clrscr();
    printf("\n Enter the number for testing (Prime or not) :");
    scanf("%d",&n);
    while (x<n)
    {
    if (n%x==0)
    {
    printf("\n The number %d is not Prime.",n);
    getch();
    exit(0);
    }
    x++;
    }
    printf("\n The number %d is Prime.",n);
    getch();
    }

    Programming in C to find the cube of any number

    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    void main()
    {
    int y,x;
    clrscr();
    printf("\nEnter a number for its cube");
    scanf("%d",&x);
    y=pow(x,3);
    printf("\nCube of the given number is %d ",y);
    getch();
    }

    Programming in C to find the square of the given number

    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    void main()
    {
    int y,x;
    clrscr();
    printf("\nEnter a number for their square");
    scanf("%d",&x);
    y=pow(x,2);
    printf("\nSquare of the given number is %d ",y);
    getch();
    }

    Programming in C to reverse a number

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,r=0,s;
    clrscr();
    printf("\nEnter the number which is to be reversed (upto 4 numbers only):");
    scanf("%d",&a);
    while(a>0)
    {
    s=a%10;
    a=a-s;
    r=(r*10)+s;
    a=a/10;
    }
    printf("\n Reversed number: %d",r);
    getch();
    }

    Programming in C to convert a letter from upper to lower case and vice versa

    #include<stdio.h>
    #include<conio.h>
    #include<ctype.h>
    void main()
    {
    char c;
    clrscr();
    printf("\n * Enter 'E' to exit");
    printf("\n * Enter only one character at a time");
    while (c!='1')
    {
    printf("\nEnter a character;");
    c=getche();
    if (c==toupper(c))
    printf("\t   It's Lower case : %c",c+32);
    else
    printf("\t   It's Upper case : %c",c-32);
    }
    getch();
    }

    Programming in C to find the sum of the given number

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int n,k=1,sum=0;
    clrscr();
    printf("Enter a number:");
    scanf("%d",&n);
    while(n!=0)
    {
    k=n%10;
    sum=sum+k;
    k=n/10;
    n=k;
    }
    printf("Sum of the digits: %d",sum);
    getch();
    }

    Programming in C to convert the Decimal number to Binary digits

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int x,y=40;
    clrscr();
    printf("Enter a number:");
    scanf("%d",&x);
    printf("\n Binary number:");
    while(x!=0)
    {
    gotoxy(y--,3);
    printf("%d",x%2);
    x=x/2;
    }
    getch();
    }

    Programming in C to find the factorial of given number

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,fact=1;
    clrscr();
    printf("\nEnter a number :");
    scanf("%d",&a);
    while (a>=1)
    {
    printf(" %d *",a);
    fact=fact*a;
    a--;
    }
    printf(" = %d",fact);
    printf("\n Factorial of given number is %d",fact);
    getch();
    }

    Structure Of A C Program

    Every C Program contains a number of building blocks known as functions. Each function of it perform a specific task independently.

    (i) Include Header File Section – C Program depends upon some header files for function definition that are used in the program. Each header file has extension ‘.h’.
    The header files are included at the beginning of the program in the C language. These files should be included using #include directive as given below.

    Example:
    #include<stdio.h> or
    #include “stdio.h”

    In this example, <stdio.h> file is included, i.e. all the definitions and prototypes of functions and prototypes of function defined in this file are available in the current program.

    (ii) Global Declaration – This section declares some variables that are used in more than one function. These variables are known as global variables. This section must be declared outside of all functions.

    (iii) Function main() – Every program written in C must contain main() and its execution starts at the beginning of this function. In ASCII C standard, first line of C program from where program execution begins is written as follows.

    int main(void)
    This is the function definition for main(). Parenthesis followed to main is to tell the user again that main() is a function. The int main(void) is a function that takes no arguments and returns a value of type int. Here in this line int and void are keywords and they have special meanings assigned by the compiler. In case int is not mentioned in the above statement, by default the function returns an integer.

    Alternately, one can also write the first line of C program from where program execution begins as follows,

    void main(void)

    Here, this function takes no arguments and returns nothing. Alternately, one can also write as follows.

    void main() : This function returns nothing and takes no arguments.

    In maximum programming examples the main function is written as void main(). This procedure is followed only to avoid writing return statement at the end of each program. This step helps to minimize source code lines. The programmer can either write the function main with int main(void) or void main().

    (iv) Declaration Part – The declaration part declares the entire local variables that are used in executable part. Local variable scope is limited to that function where the local variables are declared. The initializations of variables can also be done in this section. The initialization means providing initial value to the variables.

    (v) Executable Part – This part contains the statements following the declaration of the variables. This part contains a set of statements or a single statement.

    (vi) User-defined Function – The functions defined by the user are called user-defined functions. These functions are defined outside the main() function.

    (vii) Body of the Function – The statements enclosed within the body of the function (between opening and closing brace) are called body of the function.

    (viii) Comments – Comments are not necessary in a program. However, to understand the flow the program a programmer can insert comments in the program. Comments are to be inserted by the programmer is useful for documentation. The clarity of the program can be followed if it is properly documented.

    Comments are statement that give us information about the program which are to be placed between the delimiters /* and */. The programmers uses in the program for enhancing the lucidity frequently use comments. The compiler does not execute comments. Thus, we can say that comments are not a part of executable program.

    Example:
    /* This is single comment */
    /* This is an example of  /* nested comments */.

    Programming in C to find the name of the day of the week particularly

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int x;
    printf("\nEnter any no. between 1 to 7\n");
    scanf("%d",&x);
    switch(x)
    {
    case 1:
    printf("\n1st day is Sunday");
    break;
    case 2:
    printf("\n2nd day is Monday");
    break;
    case 3:
    printf("\n3rd day is Tuesday");
    break;
    case 4:
    printf("\n4th day is Wednesday");
    break;
    case 5:
    printf("\n5th day is Thursday");
    break;
    case 6:
    printf("\n6th day is Friday");
    break;
    case 7:
    printf("\n7th day is Saturday");
    break;
    default:
    printf("\nInvalid choice");
    }
    getch();
    }

    Programming in C to find the value of any variable using Quadratic Equation.

    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    void main()
    {
    int a,b,c,d,e,f,g,x,x1,x2;
    clrscr();
    printf("Enter the value of a,b,c respectively\n");
    scanf("%d %d %d",&a,&b,&c);
    if (b<a,b<c)
    {
    printf("Please input right value of a,b and c\n Please try again\n\n Value should be positive under root\n Value of b is always greater than others");
    }
    else
    {
    d=(b*b)-(4*a*c);
    e=sqrt(d);
    f=-b+e;
    g=-b-e;
    x1=f/(2*a);
    x2=g/(2*a);
    printf("Two values of x are:\n");
    printf("%d and %d",x1,x2);
    }
    getch();
    }

    History of C

    History of C (programming language)



     The origin of C is closely tied to the development of the Unix operating system, originally implemented in assembly
    language on a PDP-7by Ritchie and Thompson, incorporating several ideas from colleagues. Eventually they decided to port the operating system to a PDP-11. The original PDP-11 version of Unix was developed in assembly language. The developers were considering to rewrite the system using the B language, Thompson's simplified version of BCPL. However B's inability to take advantage of some of the PDP-11's features, notably byte address-ability, led to C.

    The development of C started in 1972 on the PDP-11 Unix system, and first appeared in Version 2 Unix. The language was not initially designed with portability in mind, but soon ran on different platforms as well: a compiler for the Honeywell 6000 was written within the first year of C's history, while an IBM System/370 port followed soon.
    Also in 1972, a large part of Unix was rewritten in C. By 1973, with the addition of struct types, the C language had become powerful enough that most of the Unix's kernel was now in C.

    Unix was one of the first operating system kernels implemented in a language other than assembly. (Earlier instances include the Multics system (written in PL/I), and MCP (Master Control Program) for the Burroughs B5000 written in ALGOL in 1961.) Circa 1977, further changes to the language were made by Ritchie and Stephen C. Johnson to facilitate portability of the Unix operating system. Johnson's Portable C Compiler served as the basis for several implementations of C on new platforms.