0% found this document useful (0 votes)
7 views3 pages

Assignment 1 (CP)

Bcd

Uploaded by

Vaibhav Khurdal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Assignment 1 (CP)

Bcd

Uploaded by

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

Course: Computer Programming CSL-101 (Y section, W-20)

Instructor: Abhinav Muley


Assignment-1: Variables, data types, Input/Output, Operators, and Expressions
precedence and associativity

1. Given that the ASCII codes for lowercase letters in the English alphabet ‘a’ to ‘z’ are 97 to 122 (in
decimal), what will be displayed when the following C program is executed?

main( )
{
int a;
a = ‘d’ * 2 + 4;
printf(“%d”, a);
}

2. What would be the output of the following program?

int x = 3, y = 5, z = 7, a, b;

a = x * 2 + y / 5 – z * y;
b = ++x * (y – 3) / 2 – z++ * y;

printf(“\n a = %d, b = %d”, a, b);

3. Solve the following expressions:

int a = 0, b = 1, c = -1;
float x = 2.5, y = 0.0;

i. a <= 10 && x >= 1 && b


ii. (x > y) + !a || c + +
iii. x * 5 && 5 || (b / c)
iv. !x || !c || b + c

4. From the expression (-2) * (x - 3) < x + (2 * z) && (z < 10), remove all the
unnecessary parenthesis so that the meaning of expression does not change.
5. Which of the following conditions is equivalent to the condition?
!((x >= y) && (y >= z))?

a. !( x >= z)
b. x <= z
c. (x < y) && (y < z)
d. (x < y) || ( y < z )

6. Write a program to read a character in upper case and then print it in lower case.

7. Write a main program which reads three values for a triangle, namely lengths of its two sides and
the angle in radian formed by them (say, z). Using the formula given below, print the length of
the other side (say c):

C = √𝑎2 + 𝑏 2 + 2. 𝑎. 𝑏. 𝑐𝑜𝑠𝑖𝑛𝑒(𝑧)

8. Describe in terms of the scanned integers m and n, what will be performed by the following
program.

main( )
{
int m, n;
printf ("Supply two integers: ");
scanf ("%d %d", &m, &n);
m = m - n;
n = m + n;
m = n - m;
printf ("%d %d\n", m, n);
}

9. Read five positive real numbers a, b, c, d and e from the user and compute their arithmetic mean,
geometric mean, harmonic mean and standard deviation.

Arithmetic mean AM = (a + b + c + d + e) / 5
Geometric mean GM = 5th root of abcde
Harmonic mean HM = 5 / [ (1/a) + (1/b) + (1/c) + (1/d) + (1/e) ]
Standard deviation SD = Square root of [(a2 + b2 + c2 + d2 + e2) / 5 - (AM)2]
10. The city of Wonderland is situated in the Argand plane of the Wonder-planet where each locations
can be characterized by a complex number, say z=(a+bi), when the real part a denotes the
latitude and the imaginary part b denotes the longitude. In the city of Wonderland, Alice Liddell
resides at the geographic location marked as, z1=(a1+b1i) and her elder sister Lorina Liddell
resides at the geographic location marked as, z2=(a2+b2i). Mathematically, a1, b1, a2, b2
all are real numbers (may be negative as well). God, before creating this Wonder-planet, had
experimented many geographical arithmetics over every location points. Your job is to write a C-
program to visualize these arithmetics over locations. Your program will do the following:
• Take from user two complex numbers (locations of Alice and Lorina), z1=(a1+b1i) and z2=
(a2+b2i), by asking user to enter the real (the latitude) and the imaginary (the longitude) part
(both in double format) separately.
• Print the two complex numbers (locations) in proper format, that is, like z=(a+bi).
• Compute the following operations over/with each of these two complex numbers and Print the
result:
1. Find MODULUS for both z1 and z2
2. Find MULTIPLICATION of z1 with z2
3. Find RECIPROCAL for both z1 and z2
4. Find EXPONENTIATION for both z1 and z2

Note: You can take help of Google for definitions, if you have lost your Geometry textbook.

You might also like