0% found this document useful (0 votes)
6 views11 pages

LAB 05 by Golam Saroar Nice

The document outlines a course on Structured Programming with a focus on the switch statement in C programming. It includes multiple tasks with example code for printing gender, grading systems, days of the week, total days in a month, and checking if a letter is a vowel or consonant. Each task provides input prompts and corresponding C code implementations.
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)
6 views11 pages

LAB 05 by Golam Saroar Nice

The document outlines a course on Structured Programming with a focus on the switch statement in C programming. It includes multiple tasks with example code for printing gender, grading systems, days of the week, total days in a month, and checking if a letter is a vowel or consonant. Each task provides input prompts and corresponding C code implementations.
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/ 11

Course Title: Structured Programming

Language Lab
Course Code: CSE0613102
Topic: Switch statement

Submitted By:
Name: Golam Saroar Nice
ID: 2241081210
Batch: 61F (Day)

Submitted To:
Name: Shahanaz Islam Shaown
Lecturer, CSE, UU
Task 1: Write a C program using switch statement to print
gender (male, female).
Input:

#include<stdio.h>
int main()
{
char gender;
printf("enter gender(M/m or F/f):");
scanf("%c",&gender);
switch(gender)
{
case 'M':
case'm':
printf("Male.");
break;
case'F':
case'f':
printf("Female.");
break;
default:
printf("Unspecified gender");
}
printf("\n");
return 0;
}
Output:
Task 2: Write a C program using switch statement for the
grading system.
Input:
#include <stdio.h>
int main()
{
int mark;
printf("enter mark(0-100):");
scanf("%d",&mark);
switch(mark/10)
{
case 9:
printf("Grade:A+");
break;
case 8:
printf("Grade:A");
break;
case 7:
printf("Grade:A-");
break;
default:
printf("Fail");

}
return 0;
}
Output:

Task 3: Write a C program to print day of week name


using switch case.

Input:
#include <stdio.h>

int main()

int choice;

printf("enter your choice:");

scanf("%d",&choice);

switch(choice)

case 1:

printf("Saturday");

break;

case 2:

printf("Sunday");

break;
case 3:

printf("Monday");

break;

default:

printf("Invalid");

return 0;

}
Output:
Task 4: Write a C program print total number of days in a
month using switch case.

Input:

#include <stdio.h>
int main()
{
int month;
printf("enter your month:");
scanf("%d",& month);
switch(month)
{
case 1:
printf("January 31 days");
break;
case 2:
printf("February 28 days");
break;
default:
printf("Invalid");

}
return 0;
}
Output:
Task 5: Write a C program to check whether an alphabet
is vowel or consonant using switch case.

Input:

#include <stdio.h>
int main()
{
char ch;
printf("enter a letter:");
scanf("%c",& ch);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("This is vowel/n");
break;
default:
printf("This is consonant\n");

}
return 0;
}
Output:

You might also like