0% found this document useful (0 votes)
409 views6 pages

Lab Report 1 PDF

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

Lab Report-1

Objective:
 To swapping value of m and n.
 To find a number is even or odd.
 To find out which numbers are even or odd.

Description:
Program-1
Daclared three variables are named m, n & temp. Then take a value of m & n. Now m is assigned to temporary
Variable & n is assigned to m. Then temporary variable is assigned to n. After swapping finally we got the
result.
Program-2
Initialized a variable y. Then take a integer value of y. Now create a decision making using if-else statement. If
this integer value of y modulus 2 equal to 0 then the number are Even. Else this number modulus 2 is not
equal to 0 then the number are Odd.
Program-3
Declared three variables a[50], i & c. Then take a array size & array elements. Now use a for loop to execute a
sequence of statements multiple times. Then print Even number if array[i] modulus 2 eqaul to 0. Else array[i]
modulus 2 is not equal to 0 then it’s print Odd number.
Source Code: (Program-1)
/*Write a program to exchange the values of m and n*/
#include<stdio.h>
int main()
{
int m,n,temp;
printf("Enter the value of m: ");
scanf("%d",&m);

printf("\nEnter the value of n: ");


scanf("%d",&n);

temp=m;
m=n;
n=temp;
printf("\nThe value of m: %d\n", m);
printf("\nThe value of n: %d\n", n);

return 0;
}

Input & Output:


Program-1
Source Code: (Program-2)
/*Write a program to find even and odd number*/
#include<stdio.h>
int main()
{
int y;
printf("Enter a number ");
scanf("%d", &y);

if (y%2==0)
printf("%d is even", y);

else
printf("%d is odd", y);

return 0;
}

Input & Output:


Program-2
Source Code: (Program-3)
/* write a program to find even and odd using array*/
#include<conio.h>

int main()
{

int a[30],i,c;

printf("Enter the array size: ");


scanf("%d",&c);

printf("Enter the array element: \n");


for(i=0;i<c;i++)
{
scanf("%d",&a[i]);
}

printf("The Even Number are: ");


for(i=0;i<c;i++)
{
if(a[i]%2==0)
{
printf("%d \t",a[i]);
}
}

printf("\nThe Odd Number are: ");


for(i=0;i<c;i++)
{
if(a[i]%2!=0)
{
printf("%d \t",a[i]);
}
}

return 0;
}

Input/Output:
Program-3

Discussion:
In first program we learn how to swapping value of two variables. This program swap the
value of x & y using swapping process.
In second program we learn how to find out even and odd number. This program help us to
find out any single even and odd number.
In third program we learn how to find out multiple even and odd number. Using this program
we can find out any multiple even-odd number & separates the even & odd number.

You might also like