C program that print the number in word - using else if - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Wednesday, June 26, 2019

C program that print the number in word - using else if - My CS Tutorial


In this tutorial, we will learn how write a C program that print number in word from 1 to 7. If you want to increase the range of numbers so you can increase the else if statement.

Solution:


  • In this program we will use one variable for store the value of a number.
  • We declared this variables in int data type.
  • Then we will enter the value of number.
  • After it we will use else if statement to print the number into word.
  • We will use some condition for every number.
  • Which condition is true that's statement will be execute.
  • In the end we will use else statement for another number. Which are not use by else if statement. It is wrong entry.
  • Compiler will check every condition,which condition are matched by entering number that's statement or body will be execut.


C program code


#include<stdio.h>

#include<conio.h>

void main()

{

 int num;

 printf("\n enter the number between 1 to 7=");

 scanf("%d",&num);

 if(num==1)

 printf("one");

 else if(num==2)

 printf("two");

 else if(num==3)

 printf("three");

 else if(num==4)

 printf("four");

 else if(num==5)

 printf("five");

 else if(num==6)

 printf("six");

 else if(num==7)

 printf("seven");

 else

 printf("wrong entery");

 getch();

}



Output 1:





Output 2:





Compiler will check every condition,which condition are matched by entering number that's statement or body will be execut.we will use else if statement to print the number into word in this C program.


If you want to increase the range of numbers so you can increase the else if statement.


I hope that you understand everything easily.If you have any problem or question so you write a comment and follow me on this blog and my Facebook page and on Instagram.Share the post.



Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem comment in comment box, subscribe for notifications of new post on your email and follow this blog.



Created by-- HARSH CHAUHAN

No comments:

Post a Comment