0% found this document useful (0 votes)
165 views

PPS - Practicallist - Lab Manual

The document provides the practical list for the subject "Programming for Problem Solving" for the first year of the Computer Engineering program. It includes 12 programming problems to practice various programming concepts like data types, operators, input/output, decision making, loops, functions, and arrays. For each problem, it provides the aim, headers/libraries required, and a brief pseudo code to solve the problem.

Uploaded by

ONLY FOR KIDS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views

PPS - Practicallist - Lab Manual

The document provides the practical list for the subject "Programming for Problem Solving" for the first year of the Computer Engineering program. It includes 12 programming problems to practice various programming concepts like data types, operators, input/output, decision making, loops, functions, and arrays. For each problem, it provides the aim, headers/libraries required, and a brief pseudo code to solve the problem.

Uploaded by

ONLY FOR KIDS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Government Engineering College, Bhavnagar

Computer Engineering Department


F.Y. B.E (CE)

Subject Name: PROGRAMMING FOR PROBLEM SOLVING


Semester : I
Subject Code: 3110003 Academic year: 2021-22

Practical List
Sr.
Aim of the Practical H CO PO PEO
No.

Knowledge Required: Constants, Variable & Data Types, Operators

Write a C program that will output this passage by Michael Singer. Make sure 02 2 1 1,7
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.

The ASCII Value for Diamond is is 4.

The ASCII Value for Heart is is 3.


In a town, the percentage of men is 52. The percentage of total literacy is 48. 02 2 1 1,7
If total percentage of literate men is 35 of the total population, write a
2.
program to find the total number of illiterate men and women if the
population of the town is 80,000.
Write a program to do following: 02 2 1 1,7
(a) Input an amount and convert it into rupees and paisa. (For Ex. 25.67
Rs = 25 Rs and 67 Paisa).(Implicit type Conversion)
3. (b) Input No of female and No of male and calculate the ratio of females
to males in a town. No of female and No of male are in int and ratio is
in float. (For Ex. No_of_Female = 10 & No_of_Male = 7 then ratio =
1.43).(Explicit type Conversion)

Knowledge Required: I/O Operations , Decision Making and Branching, Decision Making and Looping
Sr.
Aim of the Practical H CO PO PEO
No.

While purchasing certain items, a discount of 10% is offered if the quantity 00 1,2 1,3 1,7
purchased is more than 1000.If quantity and price per item are input through
4.
the keyboard, write a program to calculate the total expenses. Use Simple If
statement.
Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if 02 1,2 1 1,7
5. all the three points fall on one straight line. Use fabs() function of <
maths.h> header file. Use if…else statement.
Write a program using Conditional Operators to determine whether Year02 1,2 1 1,7
entered through the keyboard is a leap year or not. An year occurring once
6. every four years, which has 366 days including 29 February is called a leap
year. (Hint: The year is Leap if it is fully divisible by 100 & 400 else the year
is leap if it is fully divisible by 4).
Write a program to input a character using getchar() and print the character 00 1,2,3 1,3,4 1,7
using putchar() and check the character category. Also convert uppercase
7. 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.
If the ages of Ram, Shyam and Ajay are input through the keyboard, write a 02 1,2,3 1,3,4 1,7
8. program to determine the youngest of the three. Use Nested Switch
Statement.
Write a program to calculate following series using if and goto statement. 02 1,2,3 1,3, 1,7
9. 2 2
1 +2 +…….n 2
4
An “Armstrong number” is an n-digit number that is equal to the sum of the 00 1,2 1,2,4 1,7
nth powers of its individual digits. For example, 153 is an Armstrong number
10. 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.
11. Write a menu driven program which has following options: 02 1,2 1,2,4 1,7
1. Prime or not
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.
Pseudo Code for Prime Number:
 Declare variables number, counter, flag as 0
 Input value of number at runtime.
 Repeat loop from counter=2 to n-1
 Set flag as 1 value of number is divisible by counter.
 Break loop flag set to 1.
 Print wheatear number is pime or not.
Perfect number, a positive integer that is equal to the sum of its proper
divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3.
Other perfect numbers are 28, 496, and 8,128. The discovery of such
numbers is lost in prehistory
Pseudo Code for Perfect number:
 Declare variable number, reminder, counter and sum
 Input number
Sr.
Aim of the Practical H CO PO PEO
No.

 Repeat loop from counter=1 to number-1


o Do check in loop weather number is divisible by counter
o If yes then add it to sum
 Print perfect If number is equal to sum else not perfect.
Factorial of a number.
 Declare variable counter,number and fact as 0.
 Input number
 Repeat loop from 1 to number
o Calculate fact by counter*factorial.
Write a program for a match-stick game between the computer and a user. 00 1,2 1,2,4 1,7
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.
 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
12.
Pseudo code

 Declare variable match_stick as 21 , usercount and


computercount
 Repeat loop till match_stick is greater than or equal to one.
o Ask the user to pickup match stick
o Computer will pick up match stick as 5-usercount
o Update match_stick count.
 Set match-stick as 0.
 Print message computer win.

Knowledge Required: Arrays & Strings

13. Write a program to sort elements of an array in ascending order using 02 1,2,3 1,2 1,7
Bubble Sort.
Sr.
Aim of the Practical H CO PO PEO
No.

Pseudo Code

 Declare array named list and counter1 and counter2,swamp_flag


as 0.
 For all elements of list from counter as 0 to list count -1
o Repeat loop to compare adjacent element.
 Check if current element of list is higher than next
element
 If yes then swap list[i] and list[i+1]
 Else leave it as it is.

14. Write a Program to print the table of Squares and Cubes of 1 to 10. 01 1,2,3 1,4.8 1,7
The Program uses the following four Function:
Functions Category
printline(): draws the Function with No Arguments, No return
line using ‘ - ’ character. type
printnum() : prints Function with Arguments ,No Return type
number, square and
cube.
square() : computes Function with Arguments, with Return
square of a number. Type
cube() : computes cube Function with Arguments, with Return
of a number. Type

The output should look like the below diagram:


Sr.
Aim of the Practical H CO PO PEO
No.

Pseudo code:
 Declare Function printline()
 Declare function printnum(number)
 Declare function square(number) that return square of number.
 Declare function cube(number) that return cube of number.
 Define main function.
o Call printline();
o Print Title
o Call printline()
o Repeat loop from 1 to 10.
 Print | , print number, print | , call square() print |
call cube print |
 Define function printnum(number)
 Define function square(number) that return square of number.
 Define function cube(number) that return cube of number.

Pseudo code square(number):


 Return number * number
Pseudo code cube(number):
 Return number * number * number.
15. Write a program to calculate nCr using Function with No arguments But 02 1,2,3 1,4.8 1,7
with Return type.
,4
(Hint: nCr = n! / ((r!) (n – r)!)).

Pseudo code:
 Declare function fact(n) that return factorial of given number.
 Define main function
o Declare variable n, r and result.
o Initialize n and r.
o Evaluate
 Call fact(n) divide it by multiplication of fact(r) and
fact(n-r). Assign it to result.
o Print result.

Pseudo code fact(var)


 Declare variables: iterator, result=1.
Sr.
Aim of the Practical H CO PO PEO
No.

 Check if var is 0 then return 1.


 Repeated loop for iterator is equal 1 to var
o Evaluate result=result * iterator;
 Return result.

Write a Program to reverse a string using Recursive Function and check 01 2 1,2 1,7
16.
whether it is palindrome or not.
Write four small programs to illustrate the use of 4 storage class specifier’s 00 2,4 1,4.8 1,7
17.
auto, static, register and extern.
Create a Structure called library to hold accession number, title of the book 02 2,4 1,4.8 1,7
,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 otherwise). Write a program to
18.
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 02 2,4 1,4.8 1,7
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:

19.

Write a program to read and display information of salary of an employee 00 2,4 1,4.8 1,7
using Structure within a Structure. Outer structure contains members like
20. 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 02
Year. Write a program that compares two given dates. If the dates are equal
then display message as “Equal” otherwise “Unequal”. Write a function
21. 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)

Knowledge Required: Pointers, File Management, Dynamic Memory Allocation

22. Write a program which performs the following tasks: 02


− initialize an integer array of 10 elements in main( )
Sr.
Aim of the Practical H CO PO PEO
No.

− 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)

23. Write output for the following programs: 00


1. (Pointers to Functions)

#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()
{
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++;
}
Sr.
Aim of the Practical H CO PO PEO
No.

*t='\0';
return(r);
}
An automobile company has serial number engine parts starting from AA0 to 02
FF9. The other characteristics of parts to be specified in structure are year of
manufacturing, material and quantity manufactured.
24. (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 02
25. and print it on the screen. 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 00
26. letters ABC…XYZ and 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 enter N numbers into array and sort the second half of the 02
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.
27.
For example if input is
5 13 24 67 45 34
Output should be
5 13 24 34 45 67
Write a program using to store a character string in a block of memory space 00
28. created by calloc () and then modify the same to store a larger string using
realloc () function. (Dynamic Array)

You might also like