0% found this document useful (0 votes)
8 views5 pages

PPS Assingment

The document discusses various C programming concepts, including identifying errors in C statements, evaluating expressions, and understanding operator hierarchy. It also includes sample programs and their expected outputs, as well as true/false statements regarding arithmetic operations in C. Additionally, it covers type declarations, arithmetic rules, and control instructions.

Uploaded by

a4er4at
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)
8 views5 pages

PPS Assingment

The document discusses various C programming concepts, including identifying errors in C statements, evaluating expressions, and understanding operator hierarchy. It also includes sample programs and their expected outputs, as well as true/false statements regarding arithmetic operations in C. Additionally, it covers type declarations, arithmetic rules, and control instructions.

Uploaded by

a4er4at
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/ 5

34 Let Us C

Output

Enter the amount: 570


Smallest number of notes = 8
____________________________________________________________________

[A] Point out the errors, if any, in the following C statements:

(a) x = ( y + 3 ) ;
(b) cir = 2 * 3.141593 * r ;
(c) char = ‘3’ ;
(d) 4 / 3 * 3.14 * r * r * r = vol_of_sphere ;
(e) volume = a3 ;
(f) area = 1 / 2 * base * height ;
(g) si = p * r * n / 100 ;
(h) area of circle = 3.14 * r * r ;
(i) peri_of_tri = a + b + c ;
(j) slope = ( y2 - y1 ) ÷ ( x2 - x1 ) ;
(k) 3 = b = 4 = a ;
(l) count = count + 1 ;
(m) char ch = '25 Apr 12' ;
[B] Evaluate the following expressions and show their hierarchy.
(a) ans = 5 * b * b * x - 3 * a * y * y - 8 * b * b * x + 10 * a * y ;
(a = 3, b = 2, x = 5, y = 4 assume ans to be an int)
(b) res = 4 * a * y / c - a * y / c ;
(a = 4, y = 1, c = 3, assume res to be an int)
(c) s = c + a * y * y / b ;
(a = 2.2, b = 0.0, c = 4.1, y = 3.0, assume s to be a float)
(d) R = x * x + 2 * x + 1 / 2 * x * x + x + 1 ;
(x = 3.5, assume R to be a float)
[C] Indicate the order in which the following expressions would be
evaluated:
Chapter 2: C Instructions 35

(a) g = 10 / 5 /2 / 1 ;
(b) b = 3 / 2 + 5 * 4 / 3 ;
(c) a = b = c = 3 + 4 ;
(d) x = 2 - 3 + 5 * 2 / 8 % 3 ;
(e) z = 5 % 3 / 8 * 3 + 4
(f) y = z = -3 % -8 / 2 + 7 ;

[D] What will be the output of the following programs?

(a) # include <stdio.h>


int main( )
{
int i = 2, j = 3, k, l ;
float a, b ;
k=i/j*j;
l=j/i*i;
a=i/j*j;
b=j/i*i;
printf ( "%d %d %f %f\n", k, l, a, b ) ;
return 0 ;
}

(b) # include <stdio.h>


int main( )
{
int a, b, c, d ;
a=2%5;
b = -2 % 5 ;
c = 2 % -5 ;
d = -2 % -5 ;
printf ( "a = %d b = %d c = %d d = %d\n", a, b, c, d ) ;
return 0 ;
}

(c) # include <stdio.h>


int main( )
{
float a = 5, b = 2 ;
int c, d ;
c=a%b;
36 Let Us C

d=a/2;
printf ( "%d\n", d ) ;
return 0 ;
}

(d) # include <stdio.h>


int main( )
{
printf ( "nn \n\n nn\n" ) ;
printf ( "nn /n/n nn/n" ) ;
return 0 ;
}

(e) # include <stdio.h>


int main( )
{
int a, b ;
printf ( "Enter values of a and b" ) ;
scanf ( " %d %d ", &a, &b ) ;
printf ( "a = %d b = %d", a, b ) ;
return 0 ;
}

[E] State whether the following statements are True or False:

(a) * or /, + or - represents the correct hierarchy of arithmetic


operators in C.
(b) [ ] and { } can be used in Arithmetic instructions.
(c) Hierarchy decides which operator is used first.
(d) In C, Arithmetic instruction cannot contain constants on left side of
=.
(e) In C ** operator is used for exponentiation operation.
(f) % operator cannot be used with floats.

[F] Fill in the blanks:

(a) In y = 10 * x / 2 + z ; operation will be performed first.


(b) If a is an integer variable, a = 11 / 2 would store in a.
(c) The expression, a = 22 / 7 * 5 / 3 would evaluate to .
(d) The expression x = -7 % 2 - 8 would evaluate to .
38 Let Us C

1) Type declaration 2) Arithmetic 3) Control


x Declaration and assignment can be combined. Ex. : int a = 5 ;
x 3 types of Arithmetic instructions:
1) Integer mode 2) Real mode 3) Mixed mode
x Rules for arithmetic instructions :
- If one operand is float, result is a float
- Result is int only if both operands are ints
x a = pow ( 2, 5 ) ; would store 25 in a. Remember to #include
<math.h>

x Every operator has 1) Priority 2) Associativity


x Priority is * / %, + -, =. Priority can be changed using ( )

x Associativity comes into play when priority cannot decide which


operation to perform first. Associativity is either L to R or R to L.
+, -, *, /, % has L to R, = has R to L associativity

x Format string of printf( ) can contain :


1) Format specifiers - %c, %d, %f
2) Escape sequences : \n, \t, many others
3) Any other character
x Format string of scanf( ) can contain only format specifiers
x Control instructions control the sequence of execution of
instructions in a program

x 4 types of control instructions :


1) Sequence 2) Decision 3) Repetition 4) Case

You might also like