hot post

Arithmetic instruction in c programming(part 4) |c programming

Arithmetic instruction in c programming



In the c language learning series, we have learnt about what is operator in Arithmetic instruction in c and also learnt  about unary function. Today, we will study about second operators which is Arithmetic operators.

Arithmetic instruction in c programming(part 13)

What is Arithmetic operators in Arithmetic instruction in c programming?

"*, /, %, +, and -" are the arithmetic operators in Arithmetic instruction in c programming.
  • "/,*,%" has high priority in Arithmetic instruction in c programming.
  • "+, - " has low priority in Arithmetic instruction in c programming.
If in any program the priority of two operators are same then we use associativity rule

What is Associativity rule 


The associativity rules of a language specify which operator is evaluated first when two operators with the same precedence are adjacent in an expression.

Now lets take an example :

#include<stdio.h>
#include<conio.h>
void main()
{
int =x;
clrscr();

x=3+4;
printf("%d",x);
getch();
}

When we run this program we get 7 on out put screen. Similarly when we subtract this number then we get -1 and in case of multiply we get 12 on output screen. But when we divide this number then we get 0 not in decimal form because in Arithmetic instruction in c programming when we add, subtract, or divide two integer then we get only integer not real constant(0.00).

If one number is real constant and another number is integer then we get result in real constant in Arithmetic instruction in c programming. for example :

#include<stdio.h>
#include<conio.h>
void main()
{
float =x;
clrscr();

x=3.0/4;
printf("%d",x);
getch();
}

When we run this program  then we get 0.75 on output screen.
If you write this code and you do not change data type then output screen will show 0 because 'int data type' does not store decimal expression.so, you have to write 'float 'or 'double' data type at the place of int which is mentioned above.

What is Modulo operation (%)


In computing, the modulo operation finds the remainder or signed remainder after division of one number by another (called the modulus of the operation).
for example:

#include<stdio.h>
#include<conio.h>
void main()
{
float =x;
clrscr();

x=3%4;
printf("%d",x);
getch();
}

When we run this program then we get remainder.
 I am trying my best to explain the c language to you, please stay with me and share this post and if there is any mistake then you comment on comment box

 Thanks for reading this post

Post a Comment

0 Comments