0% found this document useful (0 votes)
12 views

If Else Assignment

Uploaded by

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

If Else Assignment

Uploaded by

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

2024

Assignment on If-Else Tasks


CSE115

Farhan Mahtab
CSE115.3
2422232642
Question 1: if a number is positive or not.

Code:
#include <stdio.h>

int main()

int x;

printf("Please Enter A Number: ");

scanf("%d", &x);

if (x>0)

printf("\n%d is a Positive Number\n", x);

else if (x<0)

printf("\n%d is a Negative Number\n", x);

else

printf("\n0 is an Integer\n");

return 0;

}
Result:
Question 2: BMI calculator.

Code:
#include <stdio.h>

int main()

float h, w, BMI;

printf("Please Enter Your Height in Inches: ");

scanf("%f", &h);

printf("Please Enter Your Weight in Pounds: ");

scanf("%f", &w);

BMI = (703*(w/(pow(h,2))));

printf("\nYour BMI is: %f\n", BMI);

if (BMI<=18.4)

printf("\nYou are Underweight\n");

else if (BMI>=18.5 && BMI<=24.9)

printf("\nYou are Normal\n");

else if (BMI>=25 && BMI<= 39.9)

printf("\nYou are Overweight\n");


}

else if (BMI >= 40)

printf("\nYou are Obese\n");

return 0;

Result:
Question 3: Odd / Even number.

Code:
#include <stdio.h>

int main()

int x;

printf("Please Enter an Integer: ");

scanf("%d", &x);

if (x%2==0)

printf("\n%d is an Even Number\n", x);

else if (x%2!=0)

printf("\n%d is an Odd Number\n", x);

return 0;

Result:
Question 4: Leap year

Code:
#include <stdio.h>

int main()

int year;

printf("Please Enter a Year: ");

scanf("%d", &year);

if (year%4==0 && year%100!= 0)

printf("\nThe %d is a Leap Year\n", year);

else if (year%400==0)

printf("\nThe %d is a Leap Year\n", year);

else

printf("\nThe %d is not Leap Year\n", year);

return 0;

}
Result:
Question 5: Regular or Not.

Solve:
#include <stdio.h>

int main()

float td, pd, per;

printf("Please Enter Total days: ");

scanf("%f", &td);

printf("Please Enter Present days: ");

scanf("%f", &pd);

per = ((pd / td)*100);

printf("\nThe Percentage of Attendance is: %.2f%%\n",per);

if (per>=75)

printf("\nThe Student is Regular\n");

else if (per<75)

printf("\nThe Student is Irregular\n");

return 0;

}
Result:
Question 6: Slow or not to come to class.

Code:
#include <stdio.h>

int main()

float time;

printf("Please Punch Your Card: ");

scanf("%f", &time);

if (time>9 && time<=9.25)

printf("\nAttended the Class Timely\n");

else if (time>9.25 && time<=9.35)

printf("\nAttended the Class Lately\n");

else if (time>9.35)

printf("\nCan

not Attend the Class\n");

return 0;

}
Result:
Question 7: Progotishil or Not.

Code:
#include <stdio.h>

int main()

float tm, om, per;

printf("Please Enter Total Marks: ");

scanf("%f", &tm);

printf("Please Obtained Marks: ");

scanf("%f", &om);

per = ((om / tm)*100);

printf("\nThe Percentage is: %.2f%%\n",per);

if (per>=80)

printf("\nThe Student is Progotishil\n");

else if (per<80)

printf("\nThe Student is not Progotishil\n");

return 0;

}
Result:
Question 8: Pass or Fail in grade.

Code:
#include <stdio.h>

int main()

float tm, om, per;

printf("Please Enter Total Marks: ");

scanf("%f", &tm);

printf("Please Obtained Marks: ");

scanf("%f", &om);

per = ((om / tm)*100);

printf("\nThe Percentage is: %.2f%%\n",per);

if (per>=60)

printf("\nThe Student is Passed\n");

else if (per<60)

printf("\nThe Student Failed\n");

return 0;
}

Result:
Question 9: Got A or not

Code:
#include <stdio.h>

int main()

float tm, om, per;

printf("Please Enter Total Marks: ");

scanf("%f", &tm);

printf("Please Obtained Marks: ");

scanf("%f", &om);

per = ((om / tm)*100);

printf("\nThe Percentage is: %.2f%%\n",per);

if (per>=93)

printf("\nObtained Grade 'A'\n");

else if (per<93)

printf("\nThe Student Failed\n");

return 0;

}
Result:
Question 10: If temperature is too hot or not

Code:
#include<stdio.h>

int main()

float T;

printf("Please enter The Temperature In Celcius: ");

scanf("%f", &T);

if (T>=33)

printf("\nThe Temperature is too Hot.\n");

else if (T<33 && T>=22)

printf("\nThe Temperature is Normal.\n");

if (T<22 && T>=15)

printf("\nThe Temperature is Cold.\n");

if (T<15)

printf("\nThe Temperature is too Cold.\n");

}
return 0;

Result:

You might also like