Professional Documents
Culture Documents
CSE-102
Computer Programming Laboratory
Student ID 221010005
1
Name : Sahiduzzaman
ID :221010020
Experiment No: 04
Name of the Experiment: Understanding the decision statements in C
Objective(s):
To understand the programming knowledge using Decision Statements (if, if-else, if-else if ladder,
switch and GOTO)
Learning outcome(s):
Students will be able to perform conditional and logical operations in C. They will be able to write
programme using conditional expressions.
Problem
Problem 1
/*Write a program to find the largest and smallest among three entered numbers and also display
whether
the identified largest/smallest number is even or odd.*/
#include<stdio.h>
#include<stdlib.h>
int main(){
int a,b,c,min,max;
scanf("%d%d%d",&a,&b,&c);
if(min%2 == 0){
printf("\n The smallest number is even");
2
Name : Sahiduzzaman
ID :221010020
else{
printf("\n The smallest number is odd");
}
printf("\nThe largest number is : %d",max);
if(max%2 == 0){
printf("\n The largest number is even");
}
else{
}
return 0;
}
Output :
Problem 2
/*
Write a program to check whether input alphabet is vowel or not using if-else and switch
statement.
*/
#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
3
Name : Sahiduzzaman
ID :221010020
scanf("%c", &c);
Output :
Problem 3
/*Write a program to get input of two or higher digit integer number and display in reverse order.*/
#include <stdio.h>
int main()
{
int n, r = 0;
while (n != 0)
{
r = r * 10;
r = r + n%10;
n = n/10;
}
Output :
Problem 4
/*
Write a program that asks a number and test the number whether it is multiple of 5 or not, divisible by
7 but not by eleven.
*/
#include<stdio.h>
int main(){
int num;
if ((num % 5) == 0)
{
printf(" Number %d is multiple of 5\n", num);
}
else
{
printf(" Number %d is not multiple of 5\n", num);
}
if ((num % 7 == 0) && (num % 11 != 0)){
printf("%d is divisible by 7 but not by 11.\n", num);
}
else{
5
Name : Sahiduzzaman
ID :221010020
printf("%d is not divisible by 7 but not by 11.\n", num);
}
return 0;
}
Output :
Problem 5
/*
Write a program to check whether the entered year is leap year or not (a year is leap if it is divisible
by 4 and divisible by 100 or 400.)
*/
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
return 0;
}
Output :
Problem 6
#include <stdio.h>
#include <math.h>
int main()
{
int a, b, c, d;
double root1, root2;
d = b*b - 4*a*c;
7
Name : Sahiduzzaman
ID :221010020
if (d < 0) { // complex roots, i is for iota (√-1, square root of -1)
printf("First root = %.2lf + i%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
printf("Second root = %.2lf - i%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
}
else { // real roots
root1 = (-b + sqrt(d))/(2*a);
root2 = (-b - sqrt(d))/(2*a);
return 0;
}
Output :
8
Name : Sahiduzzaman
ID :221010020
9
Name : Sahiduzzaman
ID :221010020