While performin the division operation in a C program, we can get the reminted of division using the modulus operator. But getting quotient when the numbers are not completely divisble , for example if we divide 15 by 4, and want to find the quotient the usual divide operator will not be useful as it will give a floating point result.
We can use the div function for this which is a part of the stdlib library. The div function takes two arguments, first one being the divident, the second one being the divisor.
The return value of the div fundtion is a structure of the form div_t, which has two member variables , Quotient and reminder.Thus to get the quotient and reminder we just ned to access these member variables in the return value of div.
Here is a example program.
Search
bash script to generate fibonacci series
Here is a linux bash script to generate fibonacci series .Fibonacci series is a sequence of numbers where each number is generated by addition of the previous two numbers in the sequence.
The script asks the user to provide how many numbers of the series have to be generated and prints out the numbers in the fibonacci series as many requested by the user.
Save the script as fibonacci,sh , open the terminal and run the script using
The script asks the user to provide how many numbers of the series have to be generated and prints out the numbers in the fibonacci series as many requested by the user.
Save the script as fibonacci,sh , open the terminal and run the script using
Subscribe to:
Posts (Atom)