Read any digit from 1-10 and display in word

 Read any digit from 1-10 and display in word


C Program
1.Using if else Statement
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a;
    printf("Enter any digit from 1-10:");
    scanf("%d",&a);
    if(a==1)
        printf("the number is One");
    else if(a==2)
        printf("the number is two");
    else if(a==3)
        printf("the number is three");
    else if(a==4)
        printf("the number is four");
    else if(a==5)
        printf("the number is five");
    else if(a==6)
        printf("the number is six");
    else if(a==7)
        printf("the number is seven");
    else if(a==8)
        printf("the number is eight");
    else if(a==9)
        printf("the number is nine");
    else if(a==10)
        printf("the number is ten");
    else
        printf("Error enter number between 1-10 ");
}

1.Using Switch Statement
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a;
    printf("Enter any digit from 1-10:");
    scanf("%d",&a);
    switch(a)
    {
        case 1: printf("the number is One");
                break;
        case 2: printf("the number is Two");
                break;
        case 3: printf("the number is Three");
                break;
        case 4: printf("the number is Four");
                break;
        case 5: printf("the number is Five");
                break;
        case 6: printf("the number is Six");
                break;
        case 7: printf("the number is Seven");
                break;
        case 8: printf("the number is Eight");
                break;
        case 9: printf("the number is Nine");
                break;
        case 10: printf("the number is Ten");
                break;
        default: printf("Error enter number between 1-10 ");
    }
}


Java Program
1.Using if else Statement
import java.util.Scanner;

public class digitToLetter {

	public static void main(String[] args)
	{
		Scanner  s = new Scanner(System.in);
		System.out.print("Enter any Digit:");
		int a = s.nextInt();
		   if(a==1)
		       System.out.print("the number is One");
		    else if(a==2)
		    	 System.out.print("the number is Two");
		    else if(a==3)
		    	 System.out.print("the number is Three");
		    else if(a==4)
		    	 System.out.print("the number is Four");
		    else if(a==5)
		    	 System.out.print("the number is Five");
		    else if(a==6)
		    	 System.out.print("the number is Six");
		    else if(a==7)
		    	 System.out.print("the number is Seven");
		    else if(a==8)
		    	 System.out.print("the number is Eight");
		    else if(a==9)
		    	 System.out.print("the number is Nine");
		    else if(a==10)
		    	 System.out.print("the number is Ten");
		    else
		       System.out.print("Error enter number between 1-10 ");
	}
		   
}

1.Using Switch Statement
import java.util.Scanner;

public class  digitToLetter {

	public static void main(String[] args) 
	{
		 Scanner  s = new Scanner(System.in);
	     System.out.print("Enter Any Digit:");
	     int a = s.nextInt();
	     
	     switch(a)
	     {
	         case 1: System.out.print("the number is One");
	                 break;
	         case 2:  System.out.print("the number is Two");
	                 break;
	         case 3:  System.out.print("the number is Three");
	                 break;
	         case 4:  System.out.print("the number is Four");
	                 break;
	         case 5: System.out.print("the number is Five");
	                 break;
	         case 6:  System.out.print("the number is Six");
	                 break;
	         case 7:  System.out.print("the number is Seven");
	                 break;
	         case 8:  System.out.print("the number is Eight");
	                 break;
	         case 9:  System.out.print("the number is Nine");
	                 break;
	         case 10:  System.out.print("the number is Ten");
	                 break;
	         default: System.out.print("Error enter number between 1-10 ");
	     }
	}

}

0 Comments:

Post a Comment