Thank you all for being with us.
Learn, Create and Implement.

  • Build Concept

    You can build your concept in programming on programsway.com.

  • Examples

    There are many C Programming examples on programsway.com.

  • Ask Questions

    Ask questions and get quick answers. Request any program and we will publish that program.

  • Showing posts with label Datatypes and Variables. Show all posts
    Showing posts with label Datatypes and Variables. Show all posts

    Thursday, 9 January 2014

    Written by Kousik :
    C provides some fundamental DATA types. They are int, float, char, double. They are very useful and important in C language. But they have a limiting fact. The fact is that a variable of these types can store only one value at a time. With variables of those types we cannot handle a large volume of data of same type at a time. So we need a powerful data type with which we can solve this problem. C supports such a data type called ARRAYS.
    Definition: An array is a well defined collection of elements of same data type. In others words One can say that an array is grouping of some elements that are of same data type. Some applications of arrays in C are given below:
    §  To store age of some boys.
    §  To store marks of subjects.
    §  To store daily rainfall data.
    And so on.
    Declaration of ARRAYS:  ARRAY in C can be declared by following format
    int array[50]; , float temperature[7];
    See carefully that an array is declared by defining the data type first then the name and then the  size of array.
    Now a question should be come to reader’s mind and that is how can we take input of many elements at a time by using array? Answer of this question is very easy. This problem can be solved by using for loop for taking input by using following syntax.
    For (i=0; i<n; i++)
    Scanf (“%d”, &arr[i]);
    Where n is the size of the array and arr is the name of array.
    Now here a example is given to understand ARRAYS and the way of using an ARRAY in C.


    #include<stdio.h>
    int main()
    {
    int a[25],i,n,sum=0,mean;
    printf("Enter the number of array elements\n");
    scanf("%d",&n);
    printf("Enter the value of array elements\n");
    for(i=0;i<n;i++)
    {
    scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
    Printf(“%d ”, a[i]);
    }
    return 0;
    }
    There are two kinds of array those can be used in C language. One is ONE DIMENSIONAL and the other one is TWO DIMENSIONAL.
    In this section we will discuss about only one dimensional array.
    INITIALIZATION OF ONE DIMENSIONAL ARRAY: After declaring an array its elements can be initialized. Otherwise elements of array are of ‘garbage’. The following syntax can be used to initialize an array.
    Data type  variablename[size]={values};
    Example : int student[3]={1,2,3};
    Above example is called compile time initialization. Another type of initialization can be used for initialize an array. That is Run time initialization. For example take the following segment.

      for(j=0;j<50;j++)
      {
        If(j<20)
       A[i]=0.0;
       Else
       A[i]=1.0;
      }
     We can also use a scanf function to initialize an array as we discuss earlier with the answer of the question how to take input value of elements of an array.
    The following example illustrates a sorting program in ascending order as an important application of arrays in C science.


    /* a program to sort an array */
    # include<stdio.h>
    int main()
    {
    int a[25],i,j,n,temp,item;
    char c;
    printf("Enter the number of array elements\n");
    scanf("%d",&n);
    printf("Enter the value of array elements\n");
    for(i=0;i<n;i++)
    {
    scanf("%d",&a[i]);
    }
    /* sorting of array */
    for(i=0;i<n;i++)
    {
    for(j=i+1;j<n;j++)
    {
    if(a[i]>a[j])
    {
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
    }
    }
    }
    printf("After sorting \n");
    for(i=0;i<n;i++)
    {
    printf("%d ",a[i]);
    }
    }









     


    Monday, 12 August 2013

    Written by Kousik : 
    Every programming language has a grammar. Different programming language has different grammar. So to learn C programming language we have to be familiar with that grammar which is related to C program. The grammar is nothing but CONSTANTS, VARIABLES, & their DATA TYPES.
    CONSTANTS:
    There are two types of C constants. One is PRIMARY and other is SECONDARY.
    Primary constants are of three types.
    1)      Integer Constant
    2)      Real Constant
    3)      Character Constant
    Secondary constants are of several types.
    1)      Array
    2)      Pointer
    3)      Structure
    4)      Union
    5)      Enum etc…
    Now we have to primary constants first…
    Integer Constants:
    Characteristics: a) An integer constants must have at least one digit. It must not have a decimal point.
                                    b) It can either positive or negative. If no sign proceeds then the integer assumed to be positive.
                                    c) The range for integer constants is -2147483648 to +2147483647. The range of integer constants is depend upon the compiler (visual studio, gcc  , turbo c etc).
    Example : 400, -421,+755 etc
    Real Constants (Floating Point Constants) :
    Real constants can be shown in two forms. One is fractional form and other is exponential form.
    Characteristics   of Fractional form  :
    a)      A real constants must have at least one digit . It must have a decimal point.
    b)      It can be either positive or negative. If no sign proceeds then the integer assumed to be positive.
    c)       No blanks are allowed within a real constant.
    Example  : -69.35 , 12.00 , +39.355 etc
    In exponential form the real is represented in two major parts  . The part coming before ‘e’ is called ‘mantissa’ and the part coming after ‘e’ called ‘exponent’ .
    Characteristics of exponential form:
    a)      The word ‘e’ separate the exponential part and the mantissa part of real constants.
    b)      The mantissa part may have +ve or –ve sign. . If no sign proceeds then the integer assumed to be positive.
    c)       The exponent must have at least one digit.
    d)      Range = -3.4e38 to +3.4e38
    Example: 3.2e-23, -0.45e+33 etc
    Character Constants:
    Characteristics
    a)      A character constant can be a single alphabet, single digit or a single special symbol enclosed with single inverted commas.
    b)      The maximum length of a character constant is 1 character.
    Example: ‘A’, ‘c’, ‘5’, ‘/’ etc
    *Secondary constants will be discussed later.
    VARIABLE:
    To store the data value in computer memory we have to know about VARIABLES.  Variables names are names given to location in memory. These locations can contain Integer, real, character constants .Type of variables are depending upon the type of constants. For example an integer type of variable can holds only the integer constants. The variable name is chosen by the programmer in such a way that shows its nature in the program.
    Example:  class, roll, count etc
    Characteristics of variables:
    a)      They must begin with a letter.
    b)      A variable name is any combination of 1 to 31 alphabets, digits or underscores. The length of variables is depending upon the compiler.
    c)       No special symbol other than an underscore can be used in a variable name.
    d)      Uppercase and lowercase are very significant.

    C KEYWORDS:
    C compiler has some words whose meaning has already been explained. There are 32 keywords available in C. Different keywords have different meaning.
     auto                       double                     int                                        struct
     Break                     else                        long                                      switch
     case                       enum                      register                                typedef
     char                       extern                     return                                  union
     const                     float                        short                                 unsigned
     continue                 for                            signed                                  void
     default                  goto                         sizeof                                   volatile
     do                          if                           static                                    while
    To know more about c keywords you can follow LET UC C(by yashvant kanetkar) & ANSI C (by Balaguruswamy) .










                    `              




    Wednesday, 20 February 2013

    Introduction to Data Types:

    For learning C programming we have to familiar with several types of data.
    There are five fundamental datatypes,which are all supported in any c compilers.
    They are 
    1) Integer (int) - for integer type data.
    2) Float (float) - for floating point number.
    3) Character (char) - for a single character. (included spacial character)
    4) Double (double) - for a huge floating point number.
    5) Void (void) - for a void type variable.

    We can derive some other data type from these five fundamental datatypes.
    these derived datatypes are short integer,signed integer, unsigned integer etc.

    Integer:
    1. signed int               1. unsigned int 
    2. signed short int     2. unsigned short int
         3. signed long int      3. unsigned long int

    Character:                            Float:   
        1. char                             1. float
          2. signed char               2. double
          3. unsigned char           3. long double

    Now one thing is to be remembered. The range of several data type depends upon compiler.

    i.e: For a 16 bit compiler the range of an integer constant   is -32768 to +32767.
    for a 32 bit compiler this range is -2147483648 to +2147483647.

    Size of data types is also depend upon compiler.

    Compiler short Int long
    16 bit 2 2 4
    32 bit 2 4 4