This program uses five user defined functions 'getSum', 'getDifference', 'getProduct', 'getQuotient' and 'getModulo' to perform addition, subtraction, multiplication, division and modulus of two numbers. Multiplication, division and modulus operator have highest priority than addition and subtraction operator.Ĭ program for addition, subtraction, multiplication, division and modulus of two numbers using a function.Integer/Float = Float and Float/Integer = Float because of explicit type conversion.If both operands are integers, then the output is also integer and the compiler neglects the term after decimal point.Printf("\nMultiplication = %d", product) * returns remainder of after an integer division */ Quotient = (float)firstNumber / secondNumber Next, it prints the result on screen using printf function. It first takes two integers as input from user using scanf function and stores them in 'firstNumber' and 'secondNumber' int variables and performs addition, subtraction, multiplication, division and modulus operations and stores results in 'sum', 'difference', 'product', 'quotient' and 'modulo' variables respectively. This program performs basic binary arithmetic operation on two integer operands like addition, subtraction, division and modulus and prints result in screen. Returns remainder after an integer divisionĬ program for addition, subtraction, multiplication, division and modulus of two numbers All arithmetic operators compute the result of specific arithmetic operation and returns its result. Therefore, when the value of i2 is divided by 100.0, the system treats the division as a floating-point division and produces the result of 1.5, which is assigned to the float variable f1. There are five fundamental arithmetic operators supported by C language, which are addition( ), subtraction(-), multiplication(*), division(/) and modulus(%) of two numbers. Any operation between two values in C is performed as a floating-point operation if either value is a floating-point variable or constant.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |