0% found this document useful (0 votes)
13 views12 pages

Lab 3

Uploaded by

tanishqrajpatel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views12 pages

Lab 3

Uploaded by

tanishqrajpatel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

#include <stdio.

h>

int main()

int num1, num2;

/* Input two numbers from user */

printf("Enter two numbers: ");

scanf("%d%d", &num1, &num2);

/* If num1 is maximum */

if(num1 > num2)

printf("%d is maximum", num1);

/* If num2 is maximum */

if(num2 > num1)

printf("%d is maximum", num2);

/* Additional condition check for equality */

if(num1 == num2)

printf("Both are equal");

return 0;

}
#include <stdio.h>

int main()

int num1, num2;

/* Input two numbers from user */

printf("Enter two numbers: ");

scanf("%d%d", &num1, &num2);

/* Compare num1 with num2 */

if(num1 > num2)

/* True part means num1 > num2 */

printf("%d is maximum", num1);

else

/* False part means num1 < num2 */

printf("%d is maximum", num2);

return 0;

}
#include <stdio.h>

int main()

int num1, num2, max;

/* Input two numbers from user */

printf("Enter two numbers: ");

scanf("%d%d", &num1, &num2);

/* Compare num1 with num2 */

if(num1 > num2)

max = num1;

else

max = num2;

printf("%d is maximum.", max);

return 0;

}
/**

* C program to find maximum between three numbers using nested if

*/

#include <stdio.h>

int main()

int num1, num2, num3, max;

/* Input three numbers from user */

printf("Enter three numbers: ");

scanf("%d%d%d", &num1, &num2, &num3);

if(num1 > num2)

if(num1 > num3)

/* If num1 > num2 and num1 > num3 */

max = num1;

else

/* If num1 > num2 but num1 > num3 is not true */

max = num3;

else

if(num2 > num3)


{

/* If num1 is not > num2 and num2 > num3 */

max = num2;

else

/* If num1 is not > num2 and num2 > num3 */

max = num3;

/* Print maximum value */

printf("Maximum among all three numbers = %d", max);

return 0;

}
/**

* C program to find maximum between three numbers using ladder if else

*/

#include <stdio.h>

int main()

int num1, num2, num3, max;

/* Input three numbers from user */

printf("Enter three numbers: ");

scanf("%d%d%d", &num1, &num2, &num3);

if((num1 > num2) && (num1 > num3))

/* If num1 is greater than both */

max = num1;

else if((num2 > num1) && (num2 > num3))

/* If num2 is greater than both */

max = num2;

else if((num3 > num1) && (num3 > num2))

/* If num3 is greater than both */

max = num3;

/* Print maximum number */

printf("Maximum among all three numbers = %d", max);

return 0;

}
/**

* C program to find maximum between three numbers using ladder if else if

*/

#include <stdio.h>

int main()

int num1, num2, num3, max;

/* Input three numbers from user */

printf("Enter three numbers: ");

scanf("%d%d%d", &num1, &num2, &num3);

if((num1 > num2) && (num1 > num3))

/* If num1 > num2 and num1 > num3 */

max = num1;

else if(num2 > num3)

/* If num1 is not > num2 and num2 > num3 */

max = num2;

else

/* If num1 is not > num2 and num2 is also not > num3 */

max = num3;

/* Print maximum number */

printf("Maximum among all three numbers = %d", max);

return 0;

}
/**

* C program to calculate total electricity bill

*/

#include <stdio.h>

int main()

int unit;

float amt, total_amt, sur_charge;

/* Input unit consumed from user */

printf("Enter total units consumed: ");

scanf("%d", &unit);

/* Calculate electricity bill according to given conditions */

if(unit <= 50)

amt = unit * 0.50;

else if(unit <= 150)

amt = 25 + ((unit-50) * 0.75);

else if(unit <= 250)

amt = 100 + ((unit-150) * 1.20);

else

{
amt = 220 + ((unit-250) * 1.50);

/*

* Calculate total electricity bill

* after adding surcharge

*/

sur_charge = amt * 0.20;

total_amt = amt + sur_charge;

printf("Electricity Bill = Rs. %.2f", total_amt);

return 0;

}
find the areas of rectangle, square, triangle, circle by using the switch case statement −

#include <stdio.h>

int main() {

char op;

double first, second;

printf("Enter an operator (+, -, *, /): ");

scanf("%c", &op);

printf("Enter two operands: ");

scanf("%lf %lf", &first, &second);

switch (op) {

case '+':

printf("%.1lf + %.1lf = %.1lf", first, second, first + second);

break;

case '-':

printf("%.1lf - %.1lf = %.1lf", first, second, first - second);

break;

case '*':

printf("%.1lf * %.1lf = %.1lf", first, second, first * second);

break;

case '/':

printf("%.1lf / %.1lf = %.1lf", first, second, first / second);

break;

// operator doesn't match any case constant

default:

printf("Error! operator is not correct");

return 0;
}

#include <stdio.h>

void main(){

int fig_code;

float side, base, length, breadth, height, area, radius;

printf("-------------------------
");

printf(" 1 --> Circle


");

printf(" 2 --> Rectangle


");

printf(" 3 --> Triangle


");

printf(" 4 --> Square


");

printf("-------------------------
");

printf("Enter the Figure code


");

scanf("%d", &fig_code);

switch(fig_code){

case 1:

printf(" Enter the radius


");

scanf("%f",&radius);

area=3.142*radius*radius;

printf("Area of a circle=%f
", area);

break;

case 2:

printf(" Enter the breadth and length


");

scanf("%f %f",&breadth, &length);

area=breadth *length;
printf("Area of a Rectangle=%f
", area);

break;

case 3:

printf(" Enter the base and height


");

scanf("%f %f", &base, &height);

area=0.5 *base*height;

printf("Area of a Triangle=%f
", area);

break;

case 4:

printf(" Enter the side


");

scanf("%f", &side);

area=side * side;

printf("Area of a Square=%f
", area);

break;

default:

printf(" Error in figure code


");

break;

You might also like