You are on page 1of 5

EX.N0.2.

A FIND THE NUMBER IS ODD OR EVEN


DATE:

PROBLEM STATEMENT:

To write a C program to find whether a given number is odd or even.

ALGORITHM:

STEP 1: Start.
STEP 2: Get a number.
STEP 3: If number is multiple of 2 it’s even else odd.
STEP 4: Print the type of the number.
STEP 5: Stop.

PROGRAM:

#include <stdio.h>
#include<conioh>
int main()
{
int number;
clrscr();
printf("\nEnter the number: \n");
scanf("%d", &number);
if(number % 2 == 0)
printf("\n%d is even\n.", number);
else
printf("\n %d is odd \n", number);
getch();
return 0;
}

OUTPUT:

Enter the number:


3

3 is odd
Enter the number:
34

34 is even

Result:
Thus a C program is written to check whether the given number is odd or even.
EX.N0.2.b FIND WHETHER A GIVEN NUMBER IS POSITIVE OR
NEGATIVE OR ZERO
DATE:
PROBLEM STATEMENT:
To write a C program to find whether a given number is positive or negative or zero.

ALGORITHM:

STEP 1: Start.
STEP 2: Get the required number.
STEP 3: Using if conditions check for the sign of the number.
STEP 4: Print whether the number is positive or negative or zero.
STEP 5: Stop.

PROGRAM:
#include<stdio.h>
#include<stdio.h>
int main()
{
int n;
clrscr();
printf("\nEnter a number:\n");
scanf("%d",&n);
if(n<0)
printf("\nNumber is negative");
else if(n>0)
printf("\nNumber is positive");
else
printf("\nNumber is equal to zero");
getch();
return 0;
}

OUTPUT:
Enter a number:
45

Number is positive

Enter a number:
-56
Number is negative

Result:
Thus a C program is written to find whether a given number is positive or negative or zero,
executed and results verified.
EX.2.C PRINTS THE RESULTS OF ALL THE OPERATORS AVAILABLE IN C
Date :

Problem statement:
Write a simple C program that prints the results of all the operators available in C (including pre/
post increment, bitwise and/or/not, etc.). Read required operand values from standard input.

ALGORITHM:

STEP 1: START
STEP 2: Get the two values required numbers.
STEP 3: Check arithmetic operators result.
STEP 4: apply relational, logical, increment, decrement, Bitwise operators
and find the result.
STEP 5 : STOP

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b;
clrscr();
printf("enter the values of a and b\n");
scanf("%d%d",&a,&b);
printf("the arithmetic operators result is %d %d %d %d\n", a+b,a-b,a*b,a/b);
printf("the relational operators result is %d %d %d %d\n", a>b,a<b,a>=b,a<=b);
printf("the logical operators result is %d %d %d %d\n", a&&b,a||b,!a, !b);
printf("the increment operator result is %d %d %d %d\n",a++,++a,b++,++b);
printf("the decrement operator result is %d %d %d %d\n",a--,--a,b--,--b);
printf("the bitwise AND operator result is %d\n",a&b);
printf("the bitwise OR operator result is %d\n",a|b);
printf("the bitwise NOT operator result is %d\n",a^b);
getch();
}
Sample Output:

Result:
Thus a simple C program that prints the results of all the operators available in C
(including pre/ post increment, bitwise and/or/not, etc.) was written, executed and
results verified.

You might also like