Freshers Aptitude technical questions
Freshers Job Alert
Bookmark and Share

C Programming Tutorial

Learn C programming in an easy way.This C programming tutorial is completly free for your use.

How you can help us back is let us know about more tutorials and send us the tutorial with your small photo and name.We will publish tutorial in your name.

 

<< Tutorial Home

ARITHMETIC OPERATORS
The symbols of the arithmetic operators are:-

Operation Operator Comment Value of Sum before Value of sum after
Multiply * sum = sum * 2; 4 8
Divide / sum = sum / 2; 4 2
Addition + sum = sum + 2; 4 6
Subtraction - sum = sum -2; 4 2
Increment ++ ++sum; 4 5
Decrement -- --sum; 4 3
Modulus % sum = sum % 3; 4 1
The following code fragment adds the variables loop and count together, leaving the result in the variable sum
sum = loop + count;

Note: If the modulus % sign is needed to be displayed as part of a text string, use two, ie %%

#include <stdio.h>

main()
{
int sum = 50;
float modulus;

modulus = sum % 10;
printf("The %% of %d by 10 is %f\n", sum, modulus);
}

Sample Program Output
The % of 50 by 10 is 0.000000

 

CLASS EXERCISE C5
What does the following change do to the printed output of the previous program?

printf("The %% of %d by 10 is %.2f\n", sum, modulus);

#include <stdio.h>

main() {

int sum = 50;

float modulus;

modulus = sum % 10;

printf("The %% of %d by 10 is %.2f\n", sum, modulus); }

The % of 50 by 10 is 0.00

 

 

<< Tutorial Home