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

Program_08[1]

The document contains C programs that demonstrate the use of switch statements and conditional statements to determine grades, check if a number is even or odd, and calculate a salesboy's weekly salary based on the number of products sold. Each program includes input prompts and outputs the results along with the author's name and roll number. The programs utilize basic control structures to perform their respective calculations.

Uploaded by

Arnab
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)
3 views

Program_08[1]

The document contains C programs that demonstrate the use of switch statements and conditional statements to determine grades, check if a number is even or odd, and calculate a salesboy's weekly salary based on the number of products sold. Each program includes input prompts and outputs the results along with the author's name and roll number. The programs utilize basic control structures to perform their respective calculations.

Uploaded by

Arnab
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/ 4

1.

Develop a C program to determine grade using


switch statement.
Input:
#include<stdio.h> #include<stdlib.h>
int main()
{
int score, grade;
printf("OUTPUT:\n"); printf("Enter
score:\n"); scanf("%d",&score);
grade=score/10;
switch(grade)
{ case
10:
case 9:
case 8: printf("\nGrade is A+");
break;
case 7: printf("\nGrade is B");
break;
case 6: printf("\nGrade is C");
break;
case 5: printf("\nGrade is D");
break;
case 4: printf("\nGrade is E");
break;
default: printf("\nGrade is F");
}
printf("\nName: Md Al Jaber\nRoll: 2101002\nSection:
A");
return 0;
}
Output:

2. Develop a C program to check even or odd number


using switch case.
Input:
#include<stdio.h> #include<stdlib.h>
int main()
{ int number, check;
printf("OUTPUT:\n");
printf("Enter a number:\n");
scanf("%d",&number);
check=number%2;
switch(check)
{ case
1:
case -1: printf("\nThe number is odd");
break;
case 0:printf("The number is even");
}
printf("\nName: Md Al Jaber\nRoll:
2101002\nSection: A");
return 0;
}

Output:
3. Develop a C program using conditional statement
Input:
#include<stdio.h> #include<stdlib.h>
int main() { float x,y;
printf("OUTPUT:\n");
printf("Enter a number:\n");
scanf("%f",&x); y=(x>2?
2*x+5:1.5*x+3); printf("y=
%.2f",y); printf("\nName: Md Al
Jaber\nRoll:
2101002\nSection: A");
return 0;
}
Output:

4. HW: Consider the weekly salary of a salesboy who is


selling some products. If x is the number of products
sold in a week, his weekly salary is given by:
4x + 100 for x <40
300 for x=40
4.5x + 150 for x >40 Input:
#include<stdio.h> #include<stdlib.h>
int main()
{
float x,salary; printf("OUTPUT:\
n");
printf("Enter the number of products sold:\n");
scanf("%f",&x);
salary=(x!=40?(x<40?4*x+100:4.5*x+150):300);
printf("\nSalary is %.2f",salary); printf("\
nName: Md Al Jaber\nRoll:
2101002\nSection: A");
return 0;
}
Output:

You might also like