Computer Science, asked by henerybergh, 1 year ago

write a syntax of nested if statement.​

Answers

Answered by Lensten
3

Answer:

if(condition) {

// Statements inside body of if

}

else {

//Statements inside body of else

}

Explanation:

include <stdio.h>

int main()

{

int age;

printf("Enter your age:");

scanf("%d",&age);

if(age >=18)

{

/* This statement will only execute if the

* above condition (age>=18) returns true

*/

printf("You are eligible for voting");

}

else

{

/* This statement will only execute if the

* condition specified in the "if" returns false.

*/

printf("You are not eligible for voting");

}

return 0;

}

Output:

Enter your age:14

You are not eligible for voting

Note: If there is only one statement is present in the “if” or “else” body then you do not need to use the braces (parenthesis). For example the above program can be rewritten like this:

#include <stdio.h>

int main()

{

int age;

printf("Enter your age:");

scanf("%d",&age);

if(age >=18)

printf("You are eligible for voting");

else

printf("You are not eligible for voting");

return 0;

}

Answered by sneha413639
4

Answer:

YOUR ANSWER IS IN THE ATTACHMENT.

Attachments:
Similar questions