In this post, we will create a search program with the help of enum. This is a very simple and easy method for creating number search program and We will learn what is enumerator. What is its use in c language? how the enumerator is implemented in the program.
To understand this program, you must have this knowledge:
what is enumerator?
- It gives an opportunity to invent own data type and define what values the variable of this data type can take.
- each value on the list of permissible values corresponds to an integer, starting with 0. In the example sun is stored as 0, mon is stored as 1 ........, sat is stored as 6.
- you can manually assign value in enum
- we can initialize enumerators with different integer values.
- you can write any program in c language without the help of enumerations but enumerations helps in writing clear codes and simplify programming
enum month { sun, mon, tue, wed, thu, fri, sat }; main() { enum week we1,we2; }
enum month { sun=1, tue=4, fri=5 };
Now, let us go to the example enum program.
Source code: enum in c program
Output Screen
Enter range number: 12 99 Search your number: 55 Number is found: 55 Enter range number: 1 10 Search your number: 15 Number is not found: 15
Program Logic
First of all we are taking two inputs from the user. In the variable R and maxR
So that we know the range of numbers.
After that, those numbers will be input. Which to find in that range.
Then we will call the Ncheck
function. And pass n, R, maxR.
Inside the Ncheck
function we will place a loop
. Then we will assign R inside i and i<=maxR
.
Inside the loop, we will check through the if
condition. If the condition of n==i
is true, then return
. Found variable
If the condition is false. So the loop is complete. And then return
. not_found variable
Ncheck
will return the function value from here. Which will be assigned to a variable named Fnumber.
Then we will apply the if-else
condition. And will check. What condition is true if Fnumber==1
. So we have got the number. The othervice condition is false. Not received
Recomonded Post
c program for multiplication of two matrices c program fibonacci series using recursion coprime number program c program swap two numbers using pointers
😊
Now next you are, write your code in the comment below.😊
0 Comments:
Post a Comment
Please do not enter any spam link in the comment box.