Skip to main content

Create an equivalent code segment using switch for the following else ... if ladder: if(marks>79) grade=”A”; else if(marks>69) grade=”B”; else if(marks>59) grade=”C”; else if(marks>49) grade=”D”; else if(marks>39) grade=”E”; else grade=”F”;


Answer:
#include<stdio.h>
#include<conio.h>
void main(){
clrscr();



int mark,index;
printf("Enter the mark: ");
scanf("%d",&mark);
index=mark/10;
switch(index){
            case 9:
            printf("Grade: A");
            break;
            case 8:
            printf("Grade: A");
            break;
            case 7:
            printf("\nGrade: B");
            break;
            case 6:
            printf("Grade: C");
            break;
            case 5:
            printf("Grade: D");
            break;
            case 4:
            printf("Grade: E");
            break;
            default:
            if(mark==100)
            {
            printf("Grade: A");
            }
            else if(mark<=39)
            {
            printf("Grade: F");
            }
            else if(mark>100)
            {
            printf("This is wrong number");
            }
            break;
            }
 getch();
}                                
Sample output:
            Enter the mark: 84

            Grade: A

Popular posts from this blog

Draw the basic organization of computer

Answer:                 The basic organization of computer__ Input Unit: ·          It accepts (or reads) instructions and data from outside. ·          It converts these instructions and data in computer acceptable form ·          It supplies the converted instructions and data to the computer system for further processing. Central Processing Unit (CPU): Control Unit: Control unit of a computer system manages and coordinates the operations of all other components of the computer system. Arithmetic Logic Unit(ALU): Arithmetic logic unit of a computer system is the place, where the actual executions of instruction, takes place during processing operation. Storage Unit: Primary Memory: It is volatile ( loses data on power ...

Describe the four basic data types. How could we extend the range of values they represent?

Answer: The basic four data types are: Data Type Integer Type Character Type Floating Point Type Void Type signed int short int long int unsigned unsigned int unsigned short int unsigned long int char signed char unsigned char float double long double