0% found this document useful (0 votes)
5 views16 pages

PPA Assignment

Uploaded by

Manish
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)
5 views16 pages

PPA Assignment

Uploaded by

Manish
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/ 16

Programming Principles and Algorithm

Assignments

Page 1 of 25
Programming Principles and Algorithm
Assignments

Table of Contents
S# Session Page No.
1. Basics of C 3
2. Variables and Data Types 4
3. Variables and Data Types (Lab) 5
4. Operators and Expressions 6
5. Operators and Expressions (Lab) 7
6. Input and Output in C 8
7. Condition 10
8. Condition (Lab) 12
9. Loop 13
10. Loop (Lab) 14

Page 2 of 25
Programming Principles and Algorithm
Assignments

Basics of C
Sr. No. Assignment Question
1
What is programming Language. Explain types of Programming language.

2 Explain history of C Programming.

Page 3 of 25
Programming Principles and Algorithm
Assignments

Variables and Data


Sr. No. Assignment Question
1
Match the following:

Column A Column B

8 Invalid Identifier Names

10.34 Integer Constants

ABC Character Constants

abc Double

23 Floating Point Numbers

12112134.868686868 Valid Identifier Names


86
_A1
$abc
‘A’

Table 2.1: Books Master Table

Hint: Multiple items in Column A can map to a single element in


Column B
2
What will be the value of the variables at the end in each of the following
code statements:

1. int a=4^4
2. int a=23.34
3. a = 10
b = a + a++
4. a=-5
b=-a

Page 4 of 25
Programming Principles and Algorithm
Assignments

Variables and Data Types (Lab)


Sr. No. Assignment Question
1
Write a C program to find the area and perimeter of a circle.

2
Write a C program that accepts the salary and age from the user and
displays the
same on the screen as output.

Page 5 of 25
Programming Principles and Algorithm
Assignments

Operators and Expressions


Sr. No. Assignment Question
1
Write a program to accept and add, subtract, multiplication, division and
modulus
numbers.
2
For the following values, write a program to evaluate the expression
z = a*b+(c/d)-e*f;
a=10
b=7
c=15.75
d=4
e=2
f=5.6
3
Write a program to evaluate the area and perimeter of the rectangle.
4
Write a program to evaluate the volume of a cylinder.
5
Write a program to evaluate the net salary of an employee given the
following constraints:

Basic salary : $

12000 DA : 12% of

Basic salary HRA :

$150

TA : $120

Others : $450

Tax cuts – a) PF :14% of Basic salary and b) IT: 15% of Basic

salary Net Salary = Basic Salary + DA + HRA + TA + Others

Page 6 of 25
Programming Principles and Algorithm
Assignments

– (PF + IT)

Page 7 of 25
Programming Principles and Algorithm
Assignments

Operators and Expressions (Lab)


Sr. No. Assignment Question
1
What is the assigned (left-hand side) value in each case?

int s, m=3, n=5, r, t;


float x=3.0, y;
t = n/m;
r = n%m;
y = n/m;
t = x*y-m/2;
x = x*2.0;
s = (m+n)/r;
y = --n;

2
Write a program which will take the input as a floating (real) number.
This number represents the centimeters. Print out the equivalent
number of feet (floating, 1 decimal) and inches (floating, 1 decimal),
with feet and the inches given to an accuracy of one decimal place.

Assume 2.54 centimeters per inch, and 12 inches


per foot. If the input value is 333.3, the output
format should be:
333.3 centimeters is 10.9 feet
333.33 centimeters is 131.2 inches
3
Find the value of iResult for the following assignment
statements: int iResult, a = 10, b = 8, c = 6, d = 5,
e =2; iResult = a - b - c - d;
iResult = a - b + c - d;
iResult = a + b / c / d;
iResult = a + b / c * d;
iResult = a / b * c * d;
iResult = a % b / c * d;
iResult = a % b % c % d;
iResult = a - (b - c) - d;
iResult = (a - (b - c)) - d;
iResult = a - ((b - c) - d);
iResult = a % (b % c) * d * e;
iResult = a + (b - c) * d - e;
iResult = (a + b) * c + d * e;
iResult = (a + b) * (c / d) % e;

Page 8 of 25
Programming Principles and Algorithm
Assignments

Input and Output in ‘C’


Sr. No. Assignment Question
1
A. Use the printf() statement and do the

following : Print out the value of the

integer variable sum

Print out the text string “Welcome”, followed by a new

line. Print out the character variable letter

Print out the float variable discount

Print out the float variable dump using two decimal

places Use the scanf() statement and do the following:

To read a decimal value from the keyboard, into the integer


variable sum

To read a float variable into the variable discount_rate


2
Write a program which prints the ASCII values of the characters
„A‟ and „b‟.
3
Consider the following program:

#include <stdio.h>
void main()
{
int breadth;
float length, height; scanf(“%d%f
%6.2f”,breadth,&length,height); printf(“%d %f
%e”,&breadth, length, height);
}

Correct the errors in the above program.

Page 9 of 25
Programming Principles and Algorithm
Assignments

4 Write a program which takes name, basic , daper ( ie, percentage of


D.A), bonper (ie, percentage bonus) and loandet ( loan amount to be
debited) for an employee. Calculate the salary using the following
relation:

salary = basic + basic * daper /100 +bonper * basic/100 - loandet


Data is:
name basic daper bonper loandet

MARK 2500 55 33.33 250.00

Table 6.1: Employee Table

Calculate salary and then print the result under the following
headings. (SalaryName
to be printed to the nearest dollar.)
Basic Salary

5
Write a program that asks for your first name and last name, and then
prints the
names in the format last name, first name

Page 10 of 25
Programming Principles and Algorithm
Assignments

Condition
Sr. No. Assignment Question
1
Write a program that accepts two numbers a and b and checks whether or
not a is divisible by b.

2
Write a program to accept 2 numbers and tell whether the product of
the two numbers is equal to or greater than 1000.
3
Write a program to accept 2 numbers. Calculate the difference between
the two values.

If the difference is equal to any of the values entered, then display the
following message:

Difference is equal to value <number of values entered>

If the difference is not equal to any of the values entered, display the
following message:

Difference is not equal to any of the values entered

4
Montek company gives allowances to its employees depending on their
grade as follows:
Grade Allowance

A 300

B 250

Others 100

Table 7.1: Grade Table

Calculate the salary at the end of the month. (Accept Salary and Grade
from the user)
5
Write a program to evaluate the Grade of a student for the following
constraints:

If marks > 75 – grade A

Page 11 of 25
Programming Principles and Algorithm
Assignments

If 60 < marks < 75 – grade B If 45 < marks<60 – grade C If 35 < marks<45 - grade D
If marks < 35 – grade E

Page 12 of 25
Programming Principles and Algorithm
Assignments

Condition (Lab)
Sr. No. Assignment Question
1 Declare two variables x and y. Assign values to these variables. Number x should
be printed only if it is less than 2000 or greater than 3000, and number y should
be printed only if it is between 100 and 500.
2 Write a program to show your computer’s capabilities. The user types in a letter of
the alphabet and your program should display the corresponding language or
package available. Some sample input and output are given below:

Input Output
A or a Ada
B or b Basic
C or c Cobol
D or d dBase III
f or F Fortran
p or P Pascal
V or V Visual C++

Table 8.1: Grade Table

Using the ‘switch’ statement to choose and display the appropriate message. Use
the default label to display a message if the input does not match any of the
above letters.

3 Accept values in three variables and print the highest value.

Page 13 of 25
Programming Principles and Algorithm
Assignments

Loop
Sr. No. Assignment Question
1 Write a program to print the series 100, 95, 90, 85,.............., 5.
2 Accept two numbers num1 and num2. Find the sum of all odd numbers between
the two numbers entered.
3 Write a program to generate the Fibonacci series. (1,1,2,3,5,8,13,).
4 Write a program to display the following patterns.

(a) 1 (b) 12345


12 1234
123 123
1234 12
12345 1

5 Write a program to generate the following pattern.

*******
******
*****
****
***
**
*

Page 14 of 25
Programming Principles and Algorithm
Assignments

Loop (Lab)
Sr. No. Assignment Question
1 Declare a variable which has the age of the person. Print the user’s name as many
times as his age.
2 Write a program to generate the following pattern:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 67
1 2 3 4 5 678
1 2 3 4 5 6789

3 Write a program to print a multiplication table for a given number.

Page 15 of 25
Programming Principles and Algorithm
Assignments

Page 16 of 25

You might also like