Press "Enter" to skip to content

C – Arithmetic Operations

Writing code with C language, we use some arithmetical terms. Thanks to these terms , we can do easily arithmetical operations. In this essay , I will make program , using with the arithmetical terms. Some Arithmetic terms and their meanings ;

To increase the count by 1: number++ , ++number , number+=1

To sum the number with another number: number+=5 , number = number + 5

To decrease the count by 1: number – – , – -number , number – =1

To reduce the number with another number : number -=5 , number = number – 5

To multiply or divide a number by a number : number = number * 5 , number = number / 5

#include<stdio.h>
int main()
{
int a=5 , b=7 , c=6 ;
printf("a=%d , b=%d , c=%d\n",a,b,c);
a=a*b;
b=b+b;
c++;
printf("a=%d , b=%d , c=%d\n",a,b,c);
/* Value of a is change because we make the a a*b
Same thing happen the b and c .
*/
a--;
b=a+c;
c= c-7;
printf("a=%d , b=%d , c=%d\n",a,b,c);
return 0;
}

Screen Output :

a=5 , b=7 , c=6
a=35 , b=14 , c=7
a=34 , b=41 , c=0

In above , In code syntax we use some terms like \n .There are terms in C like that. Some of the terms and their meanings ;

\n : Bottom line down.

\t : Leave a tab space.

\r : It makes a new line.

\\  : \ Makes this sign on the screen.

/* */ : Make comment lines.

// : Make a comment line . Comment lines do not appear on the screen.

I will make a program, using with the while loops . Program will take numbers from the user and count the taken numbers.

#include<stdio.h>
int main()
{
int number1 , number2 , sum = 0 ;
while(1){
printf("Enter the first number:");
scanf("%d",&number1);
printf("Enter the second number:");
scanf("%d",&number2);
sum = number1 + number2 ;
printf("Sum of the entered numbers : %d \n\n",sum);
}
return 0;
}

Screen Output ;

Enter the first number: 5
Enter the second number: 5
Sum of the entered numbers : 10
 
Enter the first number: 8
Enter the second number: 9
Sum of the entered numbers : 17
 
Enter the first number: 54
Enter the second number: 15
Sum of the entered numbers : 69
 
Enter the first number: 235
Enter the second number: 48
Sum of the entered numbers : 283

 

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *