Computer Science, asked by kundratania7, 3 days ago

Describe the structure of a conditional statement. Write a program using conditional statements to find out discounted price for an item depending upon its category such as I. seasonal-food-items with expiry date in a month at 10% and otherwise 5% II. seasonal clothes with sizes extra-small, or extra-extra-large at 20% and otherwise 5%
in python language​

Answers

Answered by mreema2002
0

Conditional statements help you to make a decision based on certain conditions. These conditions are specified by a set of conditional statements having boolean expressions which are evaluated to a boolean value true or false. There are following types of conditional statements in C.

If statement

#include<stdio.h>

#include<conio.h>

void main()

{

int num=0;

printf("enter the number");

scanf("%d",&num);

if(n%2==0)

{

printf("%d number in even",num);

}

getch();

}

If-Else statement

#include<stdio.h>

#include<conio.h>

void main()

{

int num=0;

printf("enter the number");

scanf("%d",&num);

if(n%2==0)

{

printf("%d number in even", num);

}

else

{

printf("%d number in odd",num);

}

getch();

}

Nested If-else statement

#include<stdio.h>

#include<conio.h>

void main( )

{

int a,b,c;

clrscr();

printf("Please Enter 3 number");

scanf("%d%d%d",&a,&b,&c);

if(a>b)

{

if(a>c)

{

printf("a is greatest");

}

else

{

printf("c is greatest");

}

}

else

{

if(b>c)

{

printf("b is greatest");

}

else

{

printf("c is greatest");

}

}

getch();

}

If-Else If ladder

#include<stdio.h>

#include<conio.h>

void main( )

{

int a;

printf("enter a number");

scanf("%d",&a);

if( a%5==0 && a%8==0)

{

printf("divisible by both 5 and 8");

}

else if( a%8==0 )

{

printf("divisible by 8");

}

else if(a%5==0)

{

printf("divisible by 5");

}

else

{

printf("divisible by none");

}

getch();

}

Switch statement

#include<stdio.h>

#include<conio.h>

void main( )

{

char grade = 'B';

if (grade == 'A')

{

printf("Excellent!");

}

else if (grade == 'B')

{

printf("Well done");

}

else if (grade == 'D')

{

printf("You passed");

}

else if (grade == 'F')

{

printf("Better try again");

}

else

{

printf("You Failed!");

}

}

getch();

}

Similar questions