Friday, January 25, 2019

C Characters Sets and C Tokens

Characters Set In C     

 

C Character Set:-

A C program is a collections of number of instructions written in meaningful order.
Further instructions are made up of Keyword, Variables and Functions etc which
uses the C character set defined by C. It is collections of various characters, digits, and symbols which can be used in a C program. It comprises followings below:-
 
Symbols In C

‘C’ Tokens:

Smallest individual unit in a C program is called C token. Our C program are
building by using these tokens. They are use in C program in different-different
ways. In C there are five types of tokens as followings below:-

Token In C    

1.Keywords:-

Keywords are those words whose meaning has already been known to the system or compiler. That is meaning of each keywords is fixed. You can only use the keyword for its predefined meaning. You cannot change the meaning of
keywords. Also you cannot use keywords as names for Variables, Functions. Arrays etc. All the keywords are written in small case letters. In C 32 keywords are available as followings below:- 

Keywords In C   

2.Identifiers:-

Identifiers are names given to various program elements like Variables, Structures,Union, Constants -names, Macros etc.
Rules for writing identifiers as followings below:-
1. First letter must be an alphabet or underscore (   _   ).
2. From second character onwords any combinations of digits, alphabets, or underscore is allowed.
3. Only digits, alphabets, underscore, are allowed. No other symbols is allowed.
4. Keywords cannot be used as identifiers.
5. For ANSI (American National Standard Institute) C maximum length of identifiers is 32,but  many compiler support more than 32.
Examples of Valid and Invalid Identifiers (On the basis of above rules):-

Valid and Invalid Identifiers  

3.Constants:-

Constants in C programming language refer to fixed values that do not change during the execution of a program. There are various types of constants in C. They are classified into followings categories as below:-


Constant In C  

1. Numeric Constants:- There are two types of numeric constants as followings below:-
A. Integer Constants:- Integer constants also have further types as followings below:-
       a. Decimal Constants:- They are sequence of digits from 0 to 9 without fractional
             part. It may be negative, positive or zero.
             Example: 22, 817, -8137, 0.
       b. Octal Constants:- They have sequence of numbers from 0 to 7 and first digit
             must be 0.                           
             Example: 045, 0, 0671, 028.
      c. Hex Decimal Constants:- They have sequence of digits from 0 to 9 and
           (Represents 10 to 15). They start with 0x or 0X.
            Example: 0x37, 0xab17, 0X81AB.

B. Real Constants:-They are the number with fractional part. They also known as floating
      point constants.
      Example: 45.67, 0.78, 5.278.
      Real constants can be also be represented in exponential or scientific notation which
      consists of two part. For example the number 212.345 can be represented as
      where e+2 means 10 to the power 2. Here the portion before the e that 2.12345 
      is is known mantissa and +2 is the exponent.

2. Non Numeric Constants:- They are two type as followings below:-
A. Single Character Constants:-They are enclosed in single quotes.They consists of 
      single character or digit. Character constants have integer values known as ASCII
      (American Standard Institute Code for Information Interchange)values
      Example:ASCII value Of A is 65.
                        
B. String Constants:- They are sequence of characters, digits, or any symbols enclosed 
      in double quotes.
      Example: “Hello World”, “15 August 1947”, “Hello C 1978”, “145.18891B”.

Backslash Constants:- C defines several backslash character constants which are used 
for special purpose. They are called so because each constants start with backslash (\).
They are represented with 2 characters whose general form is \char but treated as a single character. They are also called escape sequences. You will see their usage in others post.
Backslash constants are as followings below:-


Backslash Constant In C


4.Operators:- 
The operators are the symbols, they performs operation with operands
Example: 12+14
Here 12 and 14 are operands and + is Arithmetic operator that will generate results 26. We will learn more about Operators and Operands in Next Post. Operators are as followings below:-


Operators In C


5.Special Symbols:- 

They are also known as separators. They are use in our  program like Arrays, Functions and Function, Structure, Union and Others Blocks of  Codes.
They are three type followings below:-

Special Symbols In C



Wednesday, January 23, 2019

C Program To Swap Two Numbers Using Third Variable


Swap Two Numbers Using Third Variable:-
In this c program we swap two numbers by using a third variable. Here we take three int type of variable, name as num1, num2, num3. num1 and num2 variable for store first number and second number likewise and third used for interchanging the value when swapping. 
   /*
      Program : Swap Two Numbers Using Third Variable
      Filename : swapThirdVariable.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
      int num1, num2,num3;
       printf("Enter the first number :");
       scanf("%d",&num1); 
       printf("Enter the second number :");
       scanf("%d",&num2); 
       printf("\nBefore swapping first no :%d\n",num1); 
       printf("Before swapping second no :%d\n\n",num2);
          num3=num1;
          num1=num2;
          num2=num3;
       printf("After Swapping First No :%d\n",num1); 
       printf("After Swapping Second No :%d\n",num2); 
      return 0;
    }
 

Output :

  Enter the first number : 11
  Enter the first number : 27
  
  Before swapping first no. : 11
  Before swapping second no. : 27
  
  Before swapping first no. : 27
  Before swapping second no. : 11

C Program To Print N Natural Numbers By User Input


Print N Natural Numbers:-
In this c program we will print N natural numbers by input values from user. Here we take two int type of variables name as num, i. num for store user input as last number and i variable for counter, i initialize with value 1 and iterate until the given condition become false i<=num.

   /*
      Program : N Natural Numbers
      Filename : nNaturalNumber.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
      int num,i;
       printf("Enter the last number :");
       scanf("%d",&num); 
       for(i=1;i<=num;i++)
         {
             printf("%d \n",i);
         }
       return 0;
    }
 

Output :

  Enter the last number :15
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15

Sunday, January 20, 2019

C Program To Print First 10 Natural Numbers In Reverse Order


Print 10 Natural Numbers In reverse order:-
In this c program we will print first 10 natural numbers in reverse order by using for loop. Here we take a int type variable, name as num for counter. We initialize with 10 and decrement the value of num, break loop when reached 1 by giving condition num>=1.

   /*
      Program : 10 Natural Numbers In Reverse Order
      Filename : naturalNumberReverse.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
      int num;
       for(num=10;num>=1;num--)
         {
             printf("%d \n",num);
         }
       return 0;
    }
 

Output :

  10
  9
  8
  7
  6
  5
  4
  3
  2
  1

C Program To Print First 10 Natural Numbers


Print 10 Natural Numbers:-
In this c program we will print first 10 natural numbers by using for loop. Here we take a int type variable, name as num for counter. We initialize with 1 and increment the value of num,  break loop when reached 10 by giving condition num<=10.

   /*
      Program : 10 Natural Numbers
      Filename : naturalNumber.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
      int num;
       for(num=1;num<=10;num++)
         {
             printf("%d \n",num);
         }
       return 0;
    }
 

Output :

  1
  2
  3
  4
  5
  6
  7
  8
  9
  10