Wednesday, 9 March 2016

WAP TO ACCEPT A SINGLE DIGIT AND DISPLAY IT IN WORDS

/"enter 9 then output will be nine"/

#include<stdio.h>
main()
{
int n;
printf("Enter a digit");
scanf("%d",&n);
switch(n)
{
 case 0:printf("Zero");
       break;
 case 1:printf("One");
       break;
 case 2:printf("Two");
       break;
 case 3:printf("Three");
       break;
 case 4:printf("Four");
       break;
 case 5:printf("Five");
       break;
 case 6:printf("Six");
       break;
 case 7:printf("Seven");
       break;
 case 8:printf("Eight");
       break;
 case 9:printf("Nine");
       break;
 default:printf("Invalid input");
}
}


ASSIGNMENT 3)

TO DEMONSTRATE DECISION MAKING STATEMENTS (SWITCH CASE)

You should read following topics before starting this exercise

1. Different types of decision-making statements available in C.
2. Syntax for switch case statements.

The control statements that allows us to make a decision from the number of choices is called a switch-case statement. It is a multi-way decision making statement.

i) Usage of switch statement
   
    Syntax:  switch(expression)
                    {
                   case value1: block1;
                      break;
                   case value2: block2;
                      break;
                         . 
                         . 
                    default: default block;
                      break;
                   }
ii) The switch statement is used in writing menu driven programs here a menu displays several options and the user gives the choice by typing a character or number . 

No comments:

Post a Comment