PROGRAMMING IN C


LETS START A CODING IN C LANGUAGE :
------------------------------------------------------------------------
  #include<stdio.h>
  #include<conio.h>    //both are header file.

  void main( )
  { // starting coding part in c program
   
       // write code here.;
        getch( );

  }//ending of c program

------------------------------------------------------------------------

shal we discuss about above C programming .

LINE 1: #include<stdio.h>  (it is a standard input and output function defines in C header file).

LINE 2: #include<conio.h> (it is a console input and output function defines in C header file).

LINE 3 : The main( ) part is very important in C language ,if you want to start any coding in C programming you must start with main( ). its like a head part of the body if there is no head , the body part is useless.So, we are using main( ) for starting a C programming.

NOTE : there should be atleast one main( ) function in the programming.

LINE 4: OPENING CURLY BRACES { is indicating that coding part is started and we have to write code after curly braces.

LINE 5 : Here we are going to write code for different program for example take addition of two number.
              we have to take two variables.
           
               {
                      int a,b;
                      a=8;
                      b=6;
                      c=a+b;
                      printf("%d",c);
                      getch();
                 }

LINE 6: After completing the code we must end the code with closing curly braces }.

remember // indicates to write comment which c compiler cant read the code.
                 
yes, we learn how the C program looks like.

LETS START OF FIRST PROGRAM:

1) write a C Program to print your name ?

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


    void main( )
    {
      
        printf(" my name is training in technology. \n");
        getch( );
      }


           yeah its looks very simple right , yes C language is very simple to use and simple to develop programming language, here in above programming to print the statement in C compiler we use  printf function so we can print our any statement in side the printf function . The double quotation is very important in printf function.
--------------------------------------------------------------------------------
output :

    my name is training in technology.

---------------------------------------------------------------------------------

2) write a program to do arithmetic's function?

          #include<stdio.h>
          #incldue<conio.h>
         
          void  main( )
        {
              int a,b,c,d,e,f;

              a=5;
              b=2;
              c= a+b; // for addition.
              d=a-b; // for subtraction.
              e=a*b; // for multiplication.
              f=a%b; // for division.
               /* now we have to print all the code in the compiler so we    have to type printf function. */

                 printf("addition: %d",c);
                 printf("subtraction: %d",d);
                 printf("multiplication: %d",e);
                 printf("division:%d",f);

   //we can print value as printf("%d%d%d%d",c,d,e,f);

                   getch( );

               }

---------------------------------------------------------------------------------
  output:

      addition: 7
      subtraction: 3 
      multiplication: 10
      division: 2
---------------------------------------------------------------------------------

I think you struck in division ( 5/2 = 2.5) but in c compiler it shows 2. yeah because here we use the output variable 'f' as integer(int) data type ,it always give us a result of integer value not in decimal value.
       if you want to use decimal function than you have to use floating data type which prints decimal values at the output in C compiler.
example: 
                              float f;
                              printf( " division:%f",f );

   




1 comment: