DO NOT MISS

Ads

Wednesday, 13 July 2016

C-Programs Using Inc/Dec Operators


* Write a Program to implements increment operator.

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

void main()

     {

           int a,b,c;
           clrscr();

           
printf(“enter a value:\n”);
           scanf(“%d”,&a);

           b=++a;
           c=a++;

           printf(“a,b,c values are=%d,%d,%d”,a,b,c);

           getch();

    }

Output:-

enter a value: 
5
a,b,c values are=7,6,6

* Write a Program to implements post decrements operator.

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

void main()

     {

        b=23;
        a=b--;

       
printf(“a value=%d\n”,a);
        printf(“b value=%d”,b);

        getch();

     }

Output:-

a value=23
b value=
22

* Write a Program to implements post & pre decrements operator.

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

void main()

      {

         
 int x=10,y,z;
           clrscr();

           y=x--;
           z=--x;

           printf(“x,y,z values=%d%d%d”,x,y,z);

           getch();

      }
Output:-

x,y,z values=8,10,8

* Write a Program to implements post & pre increments operator.

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

void main()

     {

           
int a=21;
           clrscr();

           c=a++;

           printf(“After post increment ‘c’ value=%d\n”,c);
           printf(“After post increment ‘a’ value=%d\n”,a);

           c=++a;

           printf(“After pre increment ‘c’ value=%d”,c);

           getch();

}
Output:-

after post increment ‘c’ value=21
after post increment ‘a’ value=
22
after pre increment ‘c’ value =
23

* Another Program of increment operator.

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

void main()

      {

           
int a=10;
           int k=(a++, ++a);
           clrscr();


           printf(“k,a values=%d%d”, k,a);

           getch();

      }
Output:-

k,a values=12,12
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________

Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims