Wednesday 7 March 2018

Arrays in C programming

 Array:-

Array:-  Array is a collection of homogeneous data type element.
               When ever we want to represent a collection of same data type elements with a single                   name then we go for array concept.

                Each element of array is represented with one index index value.
                 1st element index value will be[0]
                 2nd element index value will be[1]
                 3rd element index value will be[2]
                 Last element index value will be(Size-1) or (n-1).



    Declare an Array in C:-

                     data_type  variable_name [sire_of_array];

   Initializing array while declaration

              int age[5] = {1, 13, 8, 16, 12}; or


               int age[] = {1, 13, 8, 16, 12};

Initializing array after declaration

  int weight[6];

  weight[0]=10;
  weight[1]=11;
  weight[2]=13;
  weight[3]=14;

  weight[4]=16;
  weight[5]=17;
   
Example:-

        #include <stdio.h>

int main()
{
    int weight [6] = {1,2,3,4,5,6};
    /* To print all the elements of the array
    for (int i=0; i < 6; i++){
       printf("%d", height[i]);
    }
    return 0;
}

        => C programming language supports multidimensional arrays.

Declare of  Two dimensional Array in C:

             
   int a[3][4] = {  
   {0, 1, 2, 3} ,  
   {4, 5, 6, 7} ,   
   {8, 9, 10, 11}
};

Note:- a[3][4] 

a[3] resepents rows and a[4] columns.


Example:-




#include <stdio.h>

int main () {

   /* an array with 6 rows and 2 columns*/
   int a[6][2] = { {0,0}, {1,2}, {2,4}, {3,6},{4,8} {5,9}};
   int i, j;

   for ( i = 0; i < 6; i++ ) {

      for ( j = 0; j < 2; j++ ) {
         printf("a[%d][%d] = %d\n", i,j, a[i][j] );
      }
   }
   
   return 0;


}



For more info click here

Input and output in C programming

Input and output in C:-

 In C programming you can use Scanf() and Printf () function to read and print data. 

Example:


 #include<stdio.h>
void main() { int a,b,c; printf("enter any two numbers: \n"); scanf("%d %d", &a, &b); c = a + b; printf("addition of two number is: %d", c); }

Output:-

enter any two numbers:
15
5

addition of two number is:  20
Note:
Scanf() : is used to take input from the user.
Printf (): is used to display  result on the screen.


For more info click here

Begain with simple programming in C

Begain with simple programming in C:-


     /* Writes the words "Hello, World!" on the screen */
#include<stdio.h> int main() { printf("Hello, World!\n"); return 0; }


Display output:- Hello, World!

Note:-

#include<stdio.h> :-  stdio is standard for input /output, this allows us to use some 
commands which includes a file called stdio.h.


int  :-                      int is a return value.

main()  :-   The main() is the main function where program execution begins. Every C                                          program must contain only one main function.

printf() :-   It is a function in C, which display text on the screen.
return 0:-  At the end of the main function returns value 0.

Introduction about C programming

Introduction about C programming:-


Introduction:-
C is a high-level structured oriented programming language, used in general purpose programming, developed by Dennis Ritchie in the USA between 1969 and 1973 to develop the UNIX operating system. C is the most widely used computer language.

C has  become a widely used professional language for various reasons :−


  1. Easy to learn
  2. Structured language
  3. It produces efficient programs
  4. It can handle low-level activities
  5. It can be compiled on a variety of computer platforms

Facts about C

  • C was invented to write an operating system called UNIX.
  • The language was formalized in 1988 by the American National Standard Institute (ANSI).
  • The UNIX OS was totally written in C.
  •  C is the most widely used and popular System Programming Language.
  • C ismost popular Linux OS and RDBMS MySQL have been written in C.

Advantages of C

  • C is the building block for many other programming languages.
  • Programs written in C are  portable.
  • Several standard functions are there (like in-built) that can be used to develop programs.
  • C programs are basically collections of C library functions, and it's also easy to add own functions to the C library.
  • The modular structure makes code debugging, maintenance and testing easier.

Disadvantages of C

  • C does not support Object Oriented Programming (OOP) concepts.
  • There are no concepts of Namespace in C.
  • C does not support binding or wrapping up of data in a single unit.
  • C does not support Constructor and Destructor.

    For more info click here