Академический Документы
Профессиональный Документы
Культура Документы
Ex. p.p 48
Note that : z*=y+x = z*(y+x)=z*y+z*x and this
is not the same as :
Z*=y+x z=z*y+x
2. Unary Minus sign (related to the negative sign
operator):
It is the negative of a variable; if x = 12
-x = -12
In C- we can write z =x - - y , this is equivalent to z
= x (-y)
Unary Subtraction
minus operator
3. Increment and decrement operators:
Increment is the increase by "1" x=x+1
Decrement is the decrease by "1" x=x-1
x=x+1 is equivalent to ++x or x++
x=x-1 is equivalent to - -x or x- -
pre process
post process
Library Functions
// sqrt.c
// demonstrates sqrt() and pow(,) library function
#include <stdio.h>
#include <math.h> //for sqrt() and pow(,)
int main(){
double number, sqrt_root,power_to; //sqrt() and pow(,)require type double
printf( Enter a number: );
scanf(" %f ",number ); //get the number
sqrt_root= sqrt(number); //find square root
power_to= pow(number,5) // findnumber to the power 5
printf("Square root of number is : %f", sqrt_root);
printf("number to the power 5 is : %f", power_to);
return 0; }
Example of Relational Operators
// relat.c
// demonstrates relational operators This program performs three
#include <stdio.h> kinds of comparisons between
int main(){ 10 and a number entered by
int numb; the user.
printf( Enter a number: ); Heres the output when the
scanf("%d", numb); user enters 20:
printf(numb<10 is,(numb < 10));
printf(numb>10 is , (numb > 10)); Enter a number: 20
printf(numb==10 is , (numb == 10)); numb<10 is 0
return 0;} numb>10 is 1
numb==10 is 0
As you can see from the output, the C++ compiler considers that a true
expression has the value 1, while a false expression has the value 0.