Now you can Subscribe using RSS

Submit your Email

Number searching program through enum in c

A LIFE ABK

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?

  1. It gives an opportunity to invent own data type and define what values the variable of this data type can take.
  2.             enum month 
                {
                    sun, mon, tue, wed, thu, fri, sat
                };
                
                
                main()
                {
                    enum week we1,we2;
                }  
            
  3. 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.
  4. you can manually assign value in enum
  5.             enum month 
                {
                 sun=1, tue=4, fri=5
                };
            
  6. we can initialize enumerators with different integer values.
  7. you can write any program in c language without the help of enumerations but enumerations helps in writing clear codes and simplify programming

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.๐Ÿ˜Š

coprime number program

A LIFE ABK
coprime number program

In this program, we will discuss the program of co-prime numbers. What are co-prime numbers? How to make co-prime number program.

To understand this program, you must have this knowledge:

what is coprime number?

A set of numbers which do not any other common factor other than 1 are called co-prime numbers.

This means those numbers whose HCF is 1.

For example, 7 and 11 no other common factor other than 1 so they are coprime numbers.

if more information


Now, let us go to the program.


Source code: coprime number program



Output Screen

 
            Enter two number: 8
            6
            8,6 are not coprimes
            Enter two number:7
            11
            7,11 are coprimes
        

Program logic

First of all, we will take two inputs from the user. Then we will assign it to the variables namedaand b.

After that, we will apply the if-else condition. And will put the expression in the if condition or if the condition of a==b is true. So both these numbers are not coprime. If false. Then you will move on the else block.

In the body of else, we will use the conditional operator. Will check both of these. Which is the bigger number? Which is bigger. It will be assigned to a variable named big.

Then we will apply a loop. In which i will start the value from 2. And from i<big.

Inside the loop, we will apply the if condition. If that condition is true. So the break keyword goes. And move out of the cursor loop. And move to the next line. If the condition is not true. So the loop is complete. And then the next line has come.

Once again we will apply the if-else condition. And will check i==big. If there is. So a and b are coprime numbers.

If the value of i is not equal to big. So both numbers are not coprime.

Recomonded Post






๐Ÿ˜Š

Now next you are, write your code in the comment below.๐Ÿ˜Š

The Ultimate Secret Of function overloading in c++

A LIFE ABK





c/c++ program solver,c++ program, new program, program code ,programing question

function overloading c++, compile-time polymorphism, function overloading flow


How to write function overloading program in c++


Explain function overloading in c++ with an example so that we can understand the function overloading program.


It is a function overloading program. In this, we have told this. how to get lcm, If inputs are received from the user two or three. In this program, you will understand How to program function overloading.



To understand this program, you must have this knowledge:

What is function overloading?

In c++ is a feature of function overloading. function overloading is an example of compile-time polymorphism.

where two or more functions can have the same name but parameters are different.

the polymorphism implements three categories:

compile-time polymorphism

  • function overloading
  • operator overloading
  • runtime polymorphism

  • virtual function
  • How can I resolve function overloading?

    these simple ways,

    1. first, c++ tries to find an exact match. this is the case where the actual argument exactly matches the parameter type of one of the overloaded functions.

    2. if no exact match is found, c++ tries to find a match through the promotion

      • char, unsigned char, and short is promoted to an int.

      • float is promoted to double

    3. if no promotion is found, c++ tries to find a match through standard conversion.

    Now, let us go to the program.


    First of all, you can imagine the output screen then build your logic.

            Enter two number:6
            16
            LCM is 48
    
            Enter three number:12
            6
            7
            LCM is 84
            
    Recommended Post

    function overloading sphere and cuboid

    Example: function overloading in c++




    Output Screen



    function overloading c++, compile-time polymorphism, function overloading flowfunction overloading c++, compile-time polymorphism, function overloading flow


    Program Logic


    This is a program of lcm. We have made a program to check lcm of numbers two and three.

    First, we put a while loop inside the main function. Which will run the infinite. Then inside it took input from the user and stored it in a variable named ch.

    Within this while loop, we created a switch-case and passed the ch variable to the parentheses of the switch.

    Now the number will be input by the user. The same case will work.

    Inside the first case, we took input in num1 and num2. Then passed to the lowestM function.

    Similarly, we did the same in the second case. But taking three inputs.

    case three, we created the exit function. To end the program. And for the default simple message.

    After that, we created two functions with the same name but there is a difference in argument. Which is an example of function overloading.

    In both functions, we used the conditional operator. Which shows which number is bigger.

    We will store that big number in L variable.

    Here we will take a new variable named Y and assign the value of L to it.

    Then we will apply a loop. In which L is less than or equal of num1 * num2 And add to L the value of Y. Then assign L

    Put an if condition in the body of the loop. In which num1 and num2 will divide to L.

    If the condition is true. Then the break keyword in the body of it will run. And the value of L will be the return.

    Our result is the return value. And we will get lcm of two number.

    Similarly, we will also get lcm of number three.



    Recently Post





    ๐Ÿ˜Š

    Now next you are, write your code in the comment below.๐Ÿ˜Š

    Program find next prime number

    A LIFE ABK






    c/c++ program solver,c++ program, new program, program code ,programing question

    prime number, odd prime number


    In this post, we will tell about the next prime number program. So please read this post carefully so that you can understand the program of next prime number.


    First of all, you can imagine the output screen

    Enter any number: 17
    19 Next prime number:

    Enter any number: 16
    17 Next prime number:

    Enter any number: 36
    37 Next prime number:















    you must have this knowledge






    Source Code next prime number 



    Output Screen

    prime number, odd prime number





    Recommended Post

















    ๐Ÿ˜Š

    Now next you are, write your code in the comment below.๐Ÿ˜Š

    function overloading sphere and cuboid

    A LIFE ABK






    c/c++ program solver,c++ program, new program, program code ,programing question

    function overloading




    Define two overloaded versions of function calculating volume of sphere and cuboid




    Source code function overloading sphere and cuboid 





    Output Screen






    function overloading




    Recommended Post






    ๐Ÿ˜Š

    Now next you are, write your code in the comment below.๐Ÿ˜Š

    factorial program in cpp using function

    A LIFE ABK







    c/c++ program solver,c++ program, new program, program code ,programing question

    factorial program in cpp using function, factorial program



    In this example, we will explain to you write a factorial program in c++. To understand this topic it is necessary to have knowledge of basic CPP, function, and loop. Please read this article carefully so that you can understand the factorial program in c++.



    First of all, you can imagine the output screen then build your logic.


     Enter N number : 5
    factorial of 5 is 120














    You must have this knowledge




    Program logic


    Create a variable named n of int type. Then take input into it.

    After taking the input call the function named pro. And pass n variable to it.

    Create a fact name variable inside the pro function and assign 1 to it.

    Then put a loop. And i = 1 in the condition of the loop. And run up to i<= n. And when the condition of the loop is true. So multiply the fact with i variable inside the loop. result Assign to the fact.

    This way the loop will continue. Until 1 is equal to n.


    After the loop is over, the return statement will run. then The cursor will move on from where the function call was made. After this, the result will be printed.



    Source code factorial program in cpp using function


    Output Screen

    factorial program in cpp using function, factorial program



    Recommended Post






    ๐Ÿ˜Š

    Now next you are, write your code in the comment below.๐Ÿ˜Š

    HCF program default arguments in cpp

    A LIFE ABK






    c/c++ program solver,c++ program, new program, program code ,programing question

    HCF program default arguments in cpp, default argument


    write a c++ program to find HCF of two numbers and three numbers with help of the default argument.


    You must have this knowledge





    HCF program default arguments in cpp

    Output Screen

    HCF program default arguments in cpp, default argument





    Recommended post


    ๐Ÿ˜Š

    Now next you are, write your code in the comment below.๐Ÿ˜Š



    Coprights @ 2021-2022, Ancient Code Designed By AbK