Professional Documents
Culture Documents
UNIVERSITY
Algorithm: Just pass the string you want to print on the screen within
inverted commas (““).
Code:
PROGRAM 2
Aim: Write a C program to take input two integers and print their sum.
Algorithm: Adding two numbers and storing the value of their addition
in variable “sum” and using print function to finally display its value.
Code:
Code:
Output: Simple Interest is displayed on the screen for the value entered
by the user.
PROGRAM 4
Aim: Write a C program to take 5 integers as input and find the greatest
of them and print it.
Theory: The program takes the input one by one from the user and at
each turn compares the new input with the old input to see which is
greater. If the new input is found greater, the old input is discarded and
replaced with the new input and the program proceeds in a similar
fashion to accept another input. If the old input is found greater, it is
retained, and the new input is discarded away and the program proceeds
to accept the next input.
Algorithm: Declare integer variable ‘max’, ‘new’, and ‘i’. Input five
integer values from the user using for loop. After each entry by the user
check the greatest of available numbers. Then use the print function to
display the greatest of those 5 integer values.
Code:
Output:
PROGRAM 5
Theory:
Algorithm:
Code:
Output:
PROGRAM 6
Theory: The bitwise operators are the operators used to perform the
operations on the data at the bit-level. When we perform the bitwise
operations, then it is also known as bit-level programming. It consists of
two digits, either 0 or It is mainly used in numerical computations to
make the calculations faster.
Bitwise AND operator is denoted by the single ampersand sign (&).
Two integer operands are written on both sides of the (&) operator. If
the corresponding bits of both the operands are 1, then the output of the
bitwise AND operation is 1; otherwise, the output would be 0.
The bitwise OR operator is represented by a single vertical sign (|). Two
integer operands are written on both sides of the (|) symbol. If the bit
value of any of the operand is 1, then the output would be 1, otherwise 0.
Code:
Output:
PROGRAM 7
Code:
Theory: The program will read a value from the user and check for it
being a prime number or not. Starting from 2, the program will divide
the input number untill it is divided with each number till half of what
number was entered by the user. If the remainder in each case remains
not equal to zero, the program declares the input number as a prime
number. Otherwise, the number entered is a non-prime number.
Algorithm: Declare an integer variable n and by using scanf function
take input from the user. Divide n by each number till n/2 by using for
loop. If remainder is zero in any case print x is not a prime number.
Using else statement print n is a prime number
Code:
Output: Displaying if a number entered by the user is prime or not.
PROGRAM 9
Theory: The program accepts a value from the user and calculates the
sum of each digit of 5-digit number entered by the user. The program
stores the last digit of the number in integer type variable and then omits
that last digit from the original entered number.
Algorithm: The program accepts the value from the user and divides it
into 10 and stores the remainder and then the number in its integer form
is reduced by the factor of 10 and the process is repeated. This is carried
out as long as the number is reduced by the of 10 is greater than 0 after
reduction.
Code:
Theory: This program reverses the 5-digit number entered by the user
and then prints the reversed number on the screen. For example, if user
enters a number 12345 as input, then 54321 is printed as output. In our
program we use (%) operator to obtain the last digit of the number. In
this way we will be able to invert the number and display it from right to
left.
Code:
Output: Displaying the reverse of the 5-digit number input by the user.
PROGRAM 13
Aim: Write a C program to find the area and perimeter of a circle,
rectangle, square and triangle using functions.
perimeter of rectangle: 2 * (a + b)
perimeter of triangle: a + b + c
Output:
PROGRAM 14
N! = 1. 2. 3 ……...(N-2). (N-1). N
This function is defined for all the positive integers including 0. The
factorial of factional and negative numbers is not defined.
Algorithm: Declare a recursive function factorial ( ). Take input from
the user n. Using conditional statements If n = 0 or 1 then return 1. Else
return n*factorial(n-1). Print the value of factorial N.
Code:
Output:
PROGRAM 15
Output: