Computer Science, asked by Dk4842, 6 months ago

Solve the given expressions : (8 Marks)

int a=20, b=15, c=30 ;

i. a -= ++a - --a + a%b

ii. int r = ( ++a + --b) / c

iii. c -= a-- + ++b + c%b

iv. int s = ( a+b+c ) / (a++ + ++c)​

Answers

Answered by anjumalik4128
1

Answer:

Introduction

Let's start

I am data

Operators

Decide if/else

Loop and loop

Decide and loop

My functions

Point me

Array

String

Pre-processor

Structure

Enjoy with files

Dynamic memory

enum

Union

typedef

Storage classes

Operators in C

Operators are symbol which tells the compiler to perform certain operations on variables. For example, (*) is an operator which is used for multiplying two numbers.

There are different types of operators in C. Let's take a look at each type of them with few examples of each.

Arithmetic Operators

Relational Operators

Increment and Decrement Operators

Logical Operators

Assignment Operators

Arithmetic Operations

Arithmetic Operators are the type of operators which take numerical values (either literals or variables) as their operands and return a single numerical value.

Let's assume, 'a' is 8 and 'b' is 4.

Operator Description Example

+ Adds operands a+b=12

- Subtracts second operand from the first a-b=4

* Multiplies both operands a*b=32

/ Divides numerator by denominator. a/b=2

% Modulus Operator returns the remainder after an integer division. a%b=0

#include <stdio.h>

int main()

{

int a = 25;

int b = 8;

printf("sum = %d", (a+b));

printf("\ndifference = %d", (a-b));

printf("\nproduct = %d", (a*b));

printf("\nremainder = %d\n", (a%b));

return 0;

}

Output

Now let's talk about '/'.

If we divide two integers, the result will be an integer.

5/2=2 (Not 2.5)

To get 2.5, at least one of the numerator or denominator must have a decimal(float) value.

5.0/2=2.5 or 5/2.0=2.5 or 5.0/2.0=2.5 but 5/2 = 2.

#include <stdio.h>

int main()

{

int a ;

int b ;

a = 2 ;

b = 9 ;

printf ( "Value of b/a is : %d\n" , b/a ) ;

return 0;

}

Output

#include <stdio.h>

int main()

{

float a ;

int b ;

a = 2.0 ;

b = 9 ;

printf ( "Value of b/a is : %f\n" , b/a ) ;

return 0;

}

Output

As we saw, if 'b' and 'a' are both integers, then the result is 4 (not 4.5) but when one of them is float then the result is 4.500000 (a float).

Similar questions