B046 MD Rafiquer Rahman C Assignment 3
B046 MD Rafiquer Rahman C Assignment 3
B046 MD Rafiquer Rahman C Assignment 3
C Assignment 3
1. Write the syntax of nested if else.And write a program to demonstate
the same.
Solution:-
Syntax of nested if else :-
if(condition) {
//Nested if else inside the body of "if"
if(condition2) {
//Statements inside the body of nested "if"
}
else {
//Statements inside the body of nested "else"
}
}
else {
//Statements inside the body of "else"
}
Program to demonstrate nested if else:-
#include <stdio.h>
int main()
{
int var1, var2;
printf("Input the value of var1:");
scanf("%d", &var1);
printf("Input the value of var2:");
scanf("%d",&var2);
if (var1 != var2)
{
printf("var1 is not equal to var2\n");
//Nested if else
if (var1 > var2)
{
printf("var1 is greater than var2\n");
}
else
{
printf("var2 is greater than var1\n");
}
}
else
{
printf("var1 is equal to var2\n");
}
return 0;
}
If the condition is not true If the condition is not true Even if the condition is not
first time than control will first time than control will true for the first time the
never enter in a loop. never enter in a loop. control will enter in a loop.
There is no semicolon; after There is no semicolon; after There is semicolon; after
the condition in the syntax of the condition in the syntax of the condition in the syntax
the for loop. the while loop. of the do while loop.
Initialization and updating is Initialization and updating is Initialization and updating
the part of the syntax. not the part of the syntax. is not the part of the syntax
Solution:-
USE OF BREAK :-
If we want to jump out of a loop instantly, without waiting to get back to
the conditional test. The keyword break allows us to do this. When break
is encountered inside any loop, control automatically passes to the first
statement after the loop.
USE OF CONTINUE :-
If we want to take the control to the beginning of the loop, bypassing the
statements inside the loop, which have not yet been executed. The key-
word continue allows us to do this. When continue is encountered inside
any loop, control automatically passes to the beginning of the loop.
Solution:-
Syntax of goto statement :-
//any scope
{
//statement(s)
[condition]
goto label_name;
//statement(s)
label_name;
//statement(s)
}
Program to demonstrate goto statement :-
#include <stdio.h>
int main()
{
int num;
QUIT: //label
printf("BYE BYE!!!\n");
return 0;
}