Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

EX.

NO : 1A ADDITION AND SUBTRACTION


DATE :

AIM:
To write a C program to perform addition and subtract of two numbers.

ALGORITHM:
1. Start the program.
2. Read the values of a, b.
3. Sum = a + b.
4. Difference = a – b
5. Print the result.
6. Stop the program.

PROGRAM:
/* Perform addition and subtract of two numbers */
# include <stdio.h>
# include <conio.h>
int main ()
{
int a, b, sum, difference;
clrscr ();
printf (“\n Enter the value of a: ”);
scanf (“%d”, &a);
printf (“\n Enter the value of b: ”);
scanf (“%d”, &b);
sum = a + b;
difference = a – b;
printf (“\n Addition of two numbers is %d”, sum);
printf (“\n Subtraction of two numbers is %d”, difference);
getch ();
return 0;
}
OUTPUT:
Enter the value of a: 20
Enter the value of b: 10
Addition of two numbers is 30
Subtraction of two numbers is 10

RESULT:
Thus, the implementation of addition and subtraction of two numbers was
executed successfully.

1
EX. NO : 1B LARGEST OF THREE NUMBERS
DATE :

AIM:
To write a C program to find the largest of three numbers.

ALGORITHM:
1. Start the program.
2. Read the values of a, b, c.
3. Compare a with b and c
a. if a is greater than b and a is greater than c
b. print a is largest
c. else print c is largest
4. Compare b and c
a. if b is greater than c
b. print b is largest
c. else print c is largest
5. Stop the program.

PROGRAM
/* Find the largest of three numbers */
# include <stdio.h>
# include <conio.h>
int main ()
{
int a, b, c;
clrscr ();
printf (“Enter the value of a, b, c: ”);
scanf (“%d%d%d”, &a, &b, &c);
if (a > b)
{
if (a > c)
printf (“Largest number is %d”, a);
else
printf (“Largest number is %d”, c);
}
else if (b > c)
printf (“Largest number is %d”, b);
else
printf (“Largest number is %d”, c);
getch ();
return 0;
}
OUTPUT:
Enter the value of a, b, c: 10 20 30
Largest number is 30

2
RESULT:
Thus, the implementation of finding the largest of three numbers was
executed successfully.

3
EX. NO : 1C CALCULATOR OPERATIONS
DATE :

AIM:
To write a C program to perform all the calculator operations using switch
statement.

ALGORITHM:
1. Start the program.
2. Get the choice.
3. Perform the operations based on choice.
4. Print the result.
5. Stop the program.

PROGRAM:
/* Calculator operations using switch statement */
#include <stdio.h>
#include <conio.h>
int main ()
{
int a, b;
char o;
clrscr ();
printf (“Choose the operator (+, - , * , /): ”);
scanf (“%c”, &o);
printf (“Enter the value of a: ”);
scanf (“%d”, &a);
printf (“Enter the value of b: ”);
scanf (“%d”, &b);
switch (o)
{
case ‘+’ : printf (“Addition is %d”, a+b);
break;
case ‘-’ : printf (“Subtraction is %d”, a-b);
break;
case ‘*’ : printf (“Multiplication is %d”, a*b);
break;
case ‘/’ : printf (“Division is %f”, (float)a/b);
break;
default : printf (“Not valid”);
}
getch ();
return 0;
}
OUTPUT:
Choose the operator (+, -, *, /): +
Enter the value of a: 10

4
Enter the value of b: 20
Addition is 30

RESULT:
Thus, the implementation of calculator operations using switch statement
was executed successfully.

5
EX. NO : 1D FIBONACCI SERIES
DATE :

AIM:
To write a C program to generate Fibonacci series.

ALGORITHM:
1. Start the program.
2. Read the value of n.
3. Using for loop to calculate the Fibonacci series.
4. Print the result.
5. Stop the program.

PROGRAM:
/* Generate Fibonacci series */
#include <stdio.h>
#include <conio.h>
int main ()
{
int i, n, first = 0, second = 1, next;
clrscr ();
printf (“Enter the number of terms: ”);
scanf (“%d”, &n);
printf (“First %d terms of Fibonacci series are: ”, n);
for (i = 0; i < n; i++)
{
if (i <= 1)
next = i;
else
{
next = first + second;
first = second;
second = next;
}
printf (“\n%d”, next);
}
getch ();
return 0;
}
OUTPUT:
Enter the number of terms: 5
First 5 terms of Fibonacci series are: 0 1 1 2 3

RESULT:
Thus, the implementation of Fibonacci series was executed successfully.

6
EX. NO : 1E PALINDROME
DATE :

AIM:
To write a C program to check the given number is Palindrome or not.

ALGORITHM:
1. Start the program.
2. Read the value of n.
3. Using while loop to calculate the Fibonacci series.
4. Print the result.
5. Stop the program.

PROGRAM:
/* Check the given number is Palindrome or not */
#include <stdio.h>
#include <conio.h>
int main ()
{
int n, n1, rev = 0, rem;
clrscr ();
printf (“Enter the number: ”);
scanf (“%d”, &n);
n1 = n;
while (n > 0)
{
rem = n % 10;
rev = rev * 10 + rem;
n = n / 10;
}
if (n1 == rev)
printf (“Given number is a palindrome”);
else
printf (“Given number is not a palindrome”);
getch ();
return 0;
}
OUTPUT:
Enter the number: 121
Given number is a palindrome

RESULT:
Thus, the implementation of checking the given number is Palindrome or not
was executed successfully.

You might also like