Header Ads

Header ADS

Program for Displaying numbers from 0 to 9 using Do-While Loop

Introduction

Hello friends, In this post, we will learn how to write a simple program in C for Bubble displaying numbers from 0 to 9 using do-while loop.
This tutorial is for those people who want to learn programming in C and do not necessarily have any previous knowledge of other programming languages. Of course any knowledge of other programming languages or any general computer skill can be useful to better understand this tutorial, although it is not essential.
Here we are calling two standard library functions. Whenever we call the library functions we must write their prototype before making the call.This helps the compiler in checking whether the values being passed and returned are as per the prototype declaration.But since we don’t define the library functions (we merely call them) we may not know the prototypes of library functions. Hence when the library of functions is provided a set of ‘.h’ files is also provided.These files contain the prototypes of library functions. But why multiple files? Because the library functions are divided into different groups and one file is provided for each group. For example, prototypes of all input/output functions are provided in the file ‘stdio.h’, prototypes of all mathematical functions are provided in the file ‘math.h’, etc.
On compilation of the above code the compiler reports all errors due to the mismatch between parameters in function call and their corresponding prototypes declared in the file ‘conio.h’. You can even open this file and look at the prototypes.

Program Briefing

First, we call the standard library function 'stdio.h' because prototypes of all input/output functions are provided in the file ‘stdio.h’. Then we call the standard library function 'conio.h' because On compilation of the above code the compiler reports all errors due to the mismatch between parameters in function call and their corresponding prototypes declared in the file ‘conio.h’. Then comes the program's main body. We declare an integer variable 'i' and set its value to '0'. then we print the number and increase the value by '1'. We do this operation while the value of 'i' is less than '10'.

Program

//Program for displaying Nos. from 0 to 9 using "do-while" loop :

 #include<stdio.h>
 #include<conio.h>

 void main()
 {
   int i;
   i=0;
   clrscr();

   do
   {
     printf("%d\n\n",i);
     i++;
   }

   while(i<10);

   getch();
 }



No comments

Powered by Blogger.