Assignment - 4

 

1: State use of branching statement in C program.

A1:

The main branching statements in C program are:

 

if statement: It is used to execute a block of code only if a specified condition is true.

if-else statement: It allows you to execute one block of code if a condition is true and another block if the condition is false.

switch statement: It is used to select one of many code blocks to be executed, based on the value of an expression.


2: Draw Flowchart and write syntax for if-else statement with example.



Syntax:

if (marks >= 35) {

                printf(“You are pass.”);

}

else {

                printf(“You are fail.”);

}

 

 

 

 

 

3: Draw Flowchart and write syntax for nested if-else statement with examples.



If (age >= 18) {

                If (gender == ‘m’) {

                                printf(“You are an adult Man.”);

                }

                Else {

                                printf(“You are an adult Woman.”);

                }

}

else {

                printf(“You are not adult.”);

}

 

 

  

Please follow me for more Assignment....


 

4: Explain syntax of switch statement or Demonstrate the use of switch statement with example or explain switch-case statement with syntax. Or explain switch-case statement with suitable example.*****

 

A4:

Syntax:

switch (expression)

​{

    case constant1:

      // statements

      break;

 

    case constant2:

      // statements

      break;

    .

    .

    default:

      // default statements

}

 

Example:

switch (gender)

​{

    case ‘m’:

      printf(“You are male”);

      break;

 

    case ‘f’:

      printf(“You are female”);

      break;

 

    default:

       printf(“Enter the correct gender.”);

}

 

 

5: Differentiate between break and continue statement or What is the use of break and continue? Explain with example. OR explain need of decision making and difference between break and continue statement **

 

Break Statement:

It is used to terminate a loop.

It is used when a certain condition is met.

The control is transferred to the first statement after the loop when break statement execute.

It is used in switch case statement to exit the switch block.

 

Continue Statement:

It is used to skip the rest of the code inside a loop.

It is often used with conditional statements to skip certain iterations.

When a continue statement is executed, the control goes back to the loop control expression.

 

6: Give the list of conditional branching statements in C language.

 

if statement: It is use to execute a block of code if a specified condition is true.

if-else statement: It provide an alternative block of code to be executed if the condition is false.

else-if ladder: The else-if ladder allows to test multiple conditions sequentially.

switch statement: It is used to select one of many code blocks to be executed based on the value of an expression.

 

 

Please follow me for more Assignment....



7: Explain if-else-if ladder statement with example or explain if-else-if ladder statement with suitable example OR write format for if-else-if ladder statement **


It allows to test multiple conditions sequentially and execute the block of code associated with the first condition that is true.

Example:

if (marks >= 90) {

        printf("Grade: A\n");

    } else if (marks >= 70) {

        printf("Grade: B\n");

    }

else {

        printf("Grade: C\n");

    }

 

8: Explain nested if else statement with example. **


A nested if-else statement is an if-else statement that is nested inside another if or else block.

if (age >= 18)

{

        if (gender == 'M')

{

                               printf("You are a male adult.");

                }

Else

{

                               printf("You are a female adult.");

               }

}

else

{

               printf("You are not an adult.");

}

 

 

9: Give difference between switch case statement and if else statement.

 

1. In the if-else statement, the condition is based on a relational or logical expression that evaluates to either true or false.

In the switch statement, the condition is based on the value of an expression, and the control flow jumps to the corresponding case label.

 

2. The if-else statement allows for more complex conditions using relational and logical operators. The switch statement is specifically designed for comparing the equality of the expression.

 

3. In an if-else statement, the control flow can be more flexible based on true condition.

In a switch statement, the control flow jumps directly to the matching case.

 

4. if-else statements allow for comparisons using a wide range of operators (>, <, >=, <=, ==, !=).

Switch statements are limited to equality comparisons (==).

 

 

Please follow me for more Assignment....



10: Explain use of break statement in C Program. OR Explain Break Statement And Continue Statement with Suitable Example. **

 

Break Statement:

It is used to terminate a loop.

It is used when a certain condition is met.

The control is transferred to the first statement after the loop when break statement execute.

It is used in switch case statement to exit the switch block.

 

 

11: State use of go to statement in c program OR Explain goto statement with syntax. ***

 

The goto statement allows you to unconditionally transfer control to a labelled statement within the same function.

Syntax:

goto label;

    // Statement(s) which are not to be executed.

label:

    // Statement(s) to be executed.

 

12: The break statement used to exit from:

A12: The break statement is used to exit from loops. It is associated with for, while, and do-while loops.


 

Please follow me for more Assignment....


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.