Final CE141 CCP Practical List
Final CE141 CCP Practical List
Practical List
Sr.
No. Aim of the Practical
Write a C program that will output this passage by Michael Singer. Make sure your output looks
exactly as shown here (including spacing, line breaks, punctuation, and the title and author). Use
Required Escape Sequence and ASCII Value.
1.
There are three shapes in the output: Smiling Face, Diamond & Heart.
The ASCII Value for Smiling face is 1.
Write a program to calculate area of two circle. (r2). Use Preprocessor directive named macro
expansion for the symbol (Symbolic Constant) without argument and with argument. Use
typedef to rename the float datatype.
Programme:
/*programme to calculate area of circle*/
#include<stdio.h>
#include<conio.h>
#define PI 3.14
main()
{
3. int r1,r2;//it will
float area1,area2;//it will
printf("Enter the value of radius of first circle:");//it will give the message to enter value
of radius
scanf("%d",&r1);//it will accept value of radius
area1=PI*r1*r1;//it will calculate value of area
printf("Area of your first circle is:%f\n",area1);//it will print the message of area
printf("Enter the value of radius of second circle:");
scanf("%d",&r2);
area2=PI*r2*r2;
printf("Area of second circle is:%f",area2);
getch();
}
OUTPUT:
While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than
5. 1000.If quantity and price per item are input through the keyboard, write a program to calculate the
total expenses. Use Simple If statement.
6. Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points fall on
one straight line. Use fabs() function of < maths.h> header file. Use ifelse statement.
If the three sides of a triangle are entered through the keyboard, write a program to check whether the
triangle is valid or not. The
7. triangle is valid if the sum of two sides is greater than the largest of
the three sides. Use nested ifelse statement.
Write a program to input a character using getchar() and print the character using putchar() and check
10. the character category. Also convert uppercase alphabet to lower case and vice versa. (Use Character
Test Functions : isalnum(), isalpha(), isdigit(), islower(), isprint(), ispunct(), isspace(), isupper()) and
(toupper() & tolower()) of <ctype.h> header file.
Write a program to find the grace marks for a student using Switch Statement. The user should enter
the class obtained by the student and the number of subjects he has failed in.
1. If the student gets first class and the number of subjects he failed in is greater than 3, then he
does not get any grace. If the number of subjects he failed in is less than or equal to 3 then the
grace is of 5 marks per subject.
2. If the student gets second class and the number of subjects he failed in is greater than 2, then
he does not get any grace. If the number of subjects he failed in is less than or equal to 2 then
11. the grace is of 4 marks per subject.
3. If the student gets third class and the number of subjects he failed in is greater than 1, then he
does not get any grace. If the number of subjects he failed in is equal to 1 then the grace is of 5
marks per subject.
If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to
12. determine the youngest of the three. Use Nested Switch Statement. (This Program is a part of
Practical List but it is an Homework for students but explain the concept in Lab not the logic)
Write a program to calculate following series using if and goto statement.
13. 12+22+.n2
Write a program to find number of 1s in the binary representation of a number. For example, the
14. binary of 5 is 0000 0000 0000 0101 contains two 1s. Use for loop. Use Bitwise AND & and Shift
Right >> operator.
An Armstrong number is an n-digit number that is equal to the sum of the nth powers of its
15. individual digits. For example, 153 is an Armstrong number because it has 3 digits and 13+ 53+33
=153. Similarly 1634 is an Armstrong number because it has 4 digits and 14+ 64+34 + 44 = 1634.
Write a program to find whether the entered number is Armstrong or not using While Loop.
Write a menu driven program which has following options:
1. Prime or not
16. 2. Perfect number or not
3. Factorial of a number
4. Exit
Use do...while statement so that the menu is displayed at least once. Also use Switch statement.
Write a program to print the following pattern using Nested for loop.
(a)
A B C D E F G F E D C B A
17.
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
(b)
Write a program for a match-stick game between the computer and a user. Your Program should ensure
that the computer always wins. Rules for the games are as follows:
There are 21 match-sticks.
The computer asks the player to pick 1, 2, 3, or 4 match-sticks.
After the person picks, the computer does its picking.
18. Whoever is forced to pick up the last match-stick loses the game.
Use while loop, break and Continue Statements.
To understand the above game in a better way visit the following link:
http://atozmath.com/Games/21MatchStick.aspx
19. Write a program to sort elements of an array in ascending order using Bubble Sort.
Write a program that reads an M x N matrix A and prints its elements in spiral order. You should start
from the element in the 0th row and 0th column in the matrix and proceed in a spiral order as shown
below.
1 2 3 4
20. 567 8
9 1011 12
131415 16
Banana
22. Grapes
Mango
Orange
Pineapple
Write a program to calculate nCr using Function with No arguments But with Return type.
24. (Hint: nCr = n! / ((r!) (n r)!)). (This Program is a part of Practical List but it is an Homework
for students but explain the concept in Lab not the logic)
Write a program to pass a number entered through keyboard as an argument to user-defined functions
25. and find the factors of a number and check whether the factors are prime or not using Nested
Functions.
Write a program to generate Fibonacci series using Recursive Function. In a Fibonacci sequence the
26. sum of two successive terms gives the third term.
1 1 2 3 5 8 13 .
Write a Program to compute the standard Deviation of N Numbers using Arrays & Function.
1. First find out the simple average of the numbers which is also known as mean and is denoted by
.
There are 8 numbers so the average would be
= (9+2+5+4+12+7+8+9)/8 = 7
2. Then for each number: subtract the Mean and square the result
(9 7)2 = (2)2 = 4
(2 7)2 = (-5)2 = 25
(5 - 7)2 = (-2)2 = 4
(4 - 7)2 = (-3)2 = 9
(12 - 7)2 = (5)2 = 25
(7 - 7)2 = (0)2 = 0
(8 - 7)2 = (1)2 = 1
(9 - 7)2 = (2)2 = 4
3. Then calculate average of those squared differences.
= =
Write a Program to reverse a string using Recursive Function and check whether it is
28. palindrome or not. (This Program is a part of Practical List but it is an Homework for students
but explain the concept in Lab not the logic)
Write a Program to find the upper triangle in the given matrix. Consider the following 4 x 4 Matrix.
If all the elements denoted by X are non-zero then the matrix has upper
X X X X
triangle. For the upper triangle, all the elements of principle diagonal and
29. 0 X X X above must be non zero. Pass two dimensional arrays to the function.
0 0 X X
0 0 0 X
Write four small programs to illustrate the use of 4 storage class specifiers auto, static, register
30. and extern. (This Program is a part of Practical List but it is an Homework for students but
explain the concept in Lab not the logic)
Create a Structure called library to hold accession number, title of the book ,author name, price of the
book and flag indicating whether the book is issued or not.(flag = 1 if the book is issued , flag = 0
31. otherwise). Write a program to enter data of one book and display the data. Write this same program
with Union also.
Define a structure called Result for students. Structure will have members like Roll number, marks for
three subjects and total of three subjects. Write a program to enter data for 5 students and display the
merit list of students. Use Array of Structures. For example, if Roll No and marks of three subjects of
each student are entered through the keyboard , the output should look like the following:
32.
33. Write a program to read and display information of salary of an employee using Structure within a
Structure. Outer structure contains members like name of employee, designation, department name,
basic pay and inner structure contains dearness allowance, house_rent allowance and city_allowance.
Calculate the total salary of one employee.
Define a structure named Date that contains three members day, month and Year. Write a program
that compares two given dates. If the dates are equal then display message as Equal otherwise
34. Unequal. Write a function Check_Date to check whether the entered date is proper or not. The date
is proper if day is between 1 and 31, month is between 1 and 12 and year is between 1000 and 9999.
(Structures & Functions)
Write a program to read the marks of 10 students for the subject CE141 Computer concepts and
Programming and computes the number of students in categories FAIL, PASS, FIRST CLASS and
DISTINCTION using Pointers and Arrays.
Marks Categories
70 or Above DISTINCTION
35. 69 to 60 FIRST CLASS
59 to 40 PASS
Below 40 FAIL
For example if following marks of 10 students are entered:
34 56 78 98 12 31 67 75 91 23
Then the output should be
DISTINCTION 4 FIRST CLASS 1 PASS 1 FAIL 4
Write a program that extracts part of the given string from the specified position. For example, if the
string is Workshop on Cloud Computing, then if from position 5, 4 characters are to be extracted then
36. the program should return the string as shop. Moreover, if the position from where the string is to be
extracted is given and the number of characters to be extracted is 0 then the program should extract
entire string from the specified position. (Pointers and Strings)
Write a program that uses an array of pointers to strings str[ ]. Receive two strings str1 and str2 and
check if str1 is embedded in any of the strings in str[ ]. If str1 is found, then replace it with str2.
char *str[ ] = {
"We will teach you how to...",
"Move a mountain",
"Level a building",
37.
"Erase the past",
"Make a million",
"...all through C!"
};
For example if str1 contains "mountain" and str2 contains "car", then the second string in str
should get changed to "Move a car".
(Array of Pointers)
Write a program which performs the following tasks:
initialize an integer array of 10 elements in main( )
38. pass the entire array to a function modify( )
in modify( ) multiply each element of array by 3
return the control to main( ) and print the new array elements in
main( )
Above program should be done in two ways: call by value and call by address and illustrate the
difference between them. (Pointers as Function Arguments)
#include<stdio.h>
void display();
int main()
{
void (*func_ptr)();
func_ptr=display;
printf("Address of functions display is %u\n",func_ptr);
(*func_ptr)();
return 0;
}
void display()
{
puts("By helping others, we help overselves!!");
}
2. (Functions Returning Pointers)
char *copy (char*,char *);
int main()
39. {
char *str;
char source[] = "Kindness";
char target[10];
str=copy(target,source);
printf("%s\n",str);
return 0;
}
char *copy(char *t,char *s)
{
char * r;
r = t;
while(*s!='\0')
{
*t=*s;
t++;
s++;
}
*t='\0';
return(r);
}
An automobile company has serial number engine parts starting from AA0 to FF9. The other
characteristics of parts to be specified in structure are year of manufacturing, material and quantity
40. manufactured.
(a) Specify a structure to store information corresponding to part.
(b) Write a program using pointer to retrieve information on parts with serial numbers between
BB1 and CC6. (Pointers and Structures)
Write a program that takes contents of a file and copy them into another file and print it on the screen.
41. Use feof () functions to detect the end of file and ferror() function to detect if there is an error in
opening the file.
Write a program to create a file named ALPHABETS which consists of all 26 letters ABCXYZ and
42. prints the contents of the file in reverse order ZYX.CBA on the screen. Use the function ftell(),
fseek() and rewind().
Write a program to open a file name INVENTORY and store in it the following data. Use fprintf() and
fscanf() functions.
Item
Number Price Quantity
Name
43.
AAA1 111 17.5 100
BBB2 125 35 50
Two files Data1 and Data2 contains sorted list of integers. Write a program to produce file Data3
44. which holds a single sorted, merge list of these two list. Use command line argument to specify the
file name.
Write a program to enter N numbers into array and sort the second half of the array using function
sort(). Enter the size of the array through keyboard. (Dynamic Array). Use malloc () to allocate
memory and use free() to free the memory after the use.
45. For example if input is
5 13 24 67 45 34
Output should be
5 13 24 34 45 67
46. Write a program using to store a character string in a block of memory space created by calloc () and
then modify the same to store a larger string using realloc () function. (Dynamic Array).
TOTAL LAB HOURS