You are on page 1of 5

Example Code

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

int x=12, y=1;

void main()
{
clrscr();

printf("\n Initial Value of X: %d",x);


printf("\n Initial Value of Y: %d",y);

y=++x;

printf("\n\n After Incrementing by 1 \n X = %d",x);


printf("\n Y = %d",y);

y=--x;

printf("\n\n After Decrementing by 1 \n X = %d",x);


printf("\n Y = %d",y);

getch();
}
1) Write a C program to demonstrate the usage of postfix increment/decrement operator
#include<stdio.h>
#include<conio.h>

int x=12, y=1;

void main()
{
clrscr();

printf("\n Initial Value of X: %d",x);


printf("\n Initial Value of Y: %d",y);

y=x++;

printf("\n\n After Incrementing by 1 \n X = %d",x);


printf("\n Y = %d",y);

y=x--;
printf("\n\n After Decrementing by 1 \n X = %d",x);
printf("\n Y = %d",y);

getch();
}

2) Write a C program to print whether a given number is even or odd.


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

int num;

void main()
{
clrscr();

printf("\n Enter the Number to be Checked: ");


scanf("%d",num);

if(num%2 == 0)
{
printf("\n\n Entered Number is an Even Number!");
}
else if(num%2 != 0)
{
printf("\n\n Entered Number is an Odd Number!");
}

getch();
}

3) Write a C Program to read the values of x and y and print the results of the following
expression (x+y)/(x-y)
#include<stdio.h>
#include<conio.h>

int x,y,res;

void main()
{
clrscr();

printf("\n Enter the Value of X: ");


scanf("%d",x);
printf("\n Enter the Value of Y: ");
scanf("%d",y);

res = (x+y)/(x-y);

printf("\n\n The Result: %d",res);

getch();
}

You might also like