LTC-04 C Program
LTC-04 C Program
assignment operators
1. Addition assignment
- It is expressed by +=
- The expression a+=b have same meaning as a=a+b
2. Subtraction assignment
- It is expressed by -=
- The expression a-=b have same meaning as a=a-b
3. Multiplication assignment
- It is expressed by *=
- The expression a*=b have same meaning as a=a*b
4. Division assignment
- It is expressed by /=
- The expression a/=b have same meaning as a=a/b
5. Module division assignment
- It is expressed by %=
- The expression a%=b have same meaning as a=a%b
// Find the output of this program // // Find the output of this program //
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main() { void main() {
int a=10, b=3; int a=10, b=3;
clrscr(); clrscr();
a*=2; a/=2;
b+=5; b%=2;
printf("a=%d \t b=%d ", a, b); printf("a=%d \t b=%d ", a, b);
getch(); getch();
} }
OUTPUT: a=20 b=8 OUTPUT: a=5 b=0
Size of operator
- It is used to display required amount of memory for store data.
- syntax:
sizeof(name of the variable)
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
b=sizeof(a);
printf("size of a is =%d", b);
getch();
}
--------------------------------------x-------------------------------------
Syntax: if(conditon)
{
do this ----
do this ----
}
NB: The region between curly brackets is referred as block of is statement
Program Program
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main() void main()
{ {
int x=10, y=20; int x=10, y=10;
clrscr(); clrscr();
if(x!=y) if(x!=y)
printf("condition is match"); printf("condition is match");
getch(); getch();
} }
OUTPUT: condition is match OUTPUT:
2. if else statement
- If the condition is true, then block of ` if ‘ statement/statements will be
executed otherwise else part will be executed.
Syntax: if(condition) {
----
----
}
else {
----
----
}
// Find the output of the following program //
#include<stdio.h>
#include<conio.h>
void main()
{
int x=10, y=20;
clrscr();
if(x>=y)
printf("condition is true ");
else
printf("condition is false");
getch();
}
OUTPUT: condition is false
_______________________________________________________