Sunday, August 14, 2016

C program to perform mathematical operations on characters.



C program to perform mathematical operations on characters.

#include<stdio.h>
int main()
{
            char ch1, ch2;
            ch1 = 'A';
            ch2 = 'B';
           
            printf("Addition of two characters: %d", ch1 + ch2);
            //Ascii of A is 65, Ascii of B is 66, hence addition is 131.
            //"%d" in printf will print 131.
            //"%c" will print corresponding character of 131.
            return 0;
}


Output of program

Addition of two characters: 131

1 comment:

  1. C Arithmetic operators are used to perform mathematical operations. C language support a almost all arithmetic operators like addition, subtraction, division and modulus etc.

    ReplyDelete