Assignment Operator:
Used to assign the result of an expression to a variable. '=' is the assignment operator. In addition C has a set of „short hand? assignment operators of the form.Eg:
x + = 1; == > x = x+1
x+ = y+1 == > x = x+y+1
1. WAP to print whether a given number is even or odd
main()
{
int a, b
printf(“ Enter a number “);
scanf(“ %d”, & a);
b = a%z;
((b = =o)? printf(“Even”): printf(“odd”);
}
2. WAP to print logic 1 if input character is capital otherwise o
main ( )
{
char x ; int y;
printf((“ \n nter a character” );
scanf(“ % C “, & x);
y = (x>=65 && x <=90? 1:0);
printf(“ y : %d”, y);
}
Output:
1) Enter a character : A
2) Enter a character : a
y : o
Shorthand operator Assignment operator
a + = 1 a = a+1
a - = 1 a = a-1
a * = n+1 a = a* (n + 1)
a / = n+1 a = a/(n+1)
a % = b a = a % b
0 comments:
Post a Comment