C PRGM Lab (R13)
C PRGM Lab (R13)
0 3 2
C PROGRAMMING LAB
Exercise l
a) Write a C Program to calculate the area of triangle using the formula
1/2
area = ( s (s-a) (s-b)(s-c)) where s= (a+b+c)/2
b) Write a C program to find the largest of three numbers using ternary operator.
c) Write a C Program to swap two numbers without using a temporary variable.
Exercise 2
a) 2’s complement of a number is obtained by scanning it from right to left and complementing all the bits
after the first appearance of a 1. Thus 2’s complement of 11100 is 00100. Write a C program to find the 2’s
complement of a binary number.
b) Write a C program to find the roots of a quadratic equation.
c) Write a C program, which takes two integer operands and one ope ator fo m the use , performs the
operation and then prints the result. (Consider the operators +,-,*, /, % and use Switch Statement)
Exercise 3
a) Write a C program to find the sum of individual digits f a p sitive integer and find the everse of the given
number.
b) A Fibonacci sequence is defined as follows: the first and sec nd te ms in the sequence are 0 and 1.
c) Write a C program to generate all the prime numbers between 1 and n, where n is a value supplied by the
user.
Exercise 4
a) Write a C Program to print the multiplication table of a given number n up to a given value, where n is
entered by the user.
b) Write a C Program to enter a decimal number, and calculate and display the binary equivalent of that
number.
c) Write a C Program to check whether the given number is Armstrong number not.
Exercise 5
a) Write a C program to interchange the largest and smallest numbers in the array.
b) Write a C program to implement a liner search.
c) Write a C program to implement binary search
Exercise 6
a) Write a C program to implement sorting of an array of elements .
b) Write a C program to input two m x n matrices, check the compatibility and perform addition and
multiplication of them
Exercise 7
Write a C program that uses functions to perform the following operations:
i. To insert a sub-string in to given main string from a given position.
ii. To delete n Characters from a given position in a given string.
iii. To replace a character of string either from beginning or ending or at a specified location
Exercise 8
Write a C program that uses functions to perform the following operations using Structure:
i) Reading a complex number ii) Writing a complex number
iii) Addition of two complex numbers iv) Multiplication of two complex numbers
Exercise 9
Write C Programs for the following string operations without using the built in functions
- to concatenate two strings
- to append a string to another string
- to compare two strings
Exercise 10
Write C Programs for the following string operations without using the built in
functions - to find t he length of a string
Exercise 11
a) Write a C functions to find both the largest and smallest number of an array of integers.
b) Write C programs illustrating call by value and call by reference cncepts.
Exercise 12
Write C programs that use both recursive and non-recursive functions for the following
i) To find the factorial of a given integer.
ii) To find the GCD (greatest common divisor) of two given integers.
iii) To find Fibonacci sequence
Exercise 13
a) Write C Program to reverse a string using pointers
b) Write a C Program to compare two arrays using pointers
Exercise 14
a) Write a C program consisting of Pointer based function to exchange value of two integers using passing
by address.
b) Write a C program to swap two numbers using pointers
Exercise 15
Examples which explores the use of structures, union and other user defined va iab es
Exercise 16
a) Write a C program which copies one file to another.
b) Write a C program to count the number of characters and number f lines in a file.
c) Write a C Program to merge two files into a third file. The names f the files must be entered using
command line arguments.
------- o -------