Modulus function of C ( % )
/* The MODULUS OPERATOR i.e. which extracts the remainder from a division operation in C is % */
#include math.h
main( )
{
int a, b, c;
a= 15;
b= 4;
c= a % b;
printf( "The remainder is %d", c );
}
Output
The remainder is 3
Study this program
#include stdio.h
#include string.h
#define NULL '0\'
main ( )
{
int i;
char name[] = " Subhajit is doing C programming";
for (i=0; i<=strlen(name); i++)
{
printf( "%c the length is %d\n", name[i], i+1; }
for (i=0; i<=strlen(name); i++)
{
if ('C' = = name[i]
printf( "%c the length is %d\n", name[i], i+1);
}
}
Output is
S the length is 1
u the length is 2
b the length is 3
h the length is 4
a the length is 5
j the length is 6
i the length is 7
t the length is 8
the length is 9
i the length is 10
s the length is 11
the length is 12
d the length is 13
o the length is 14
i the length is 15
n the length is 16
g the length is 17
the length is 18
C the length is 19
the length is 20
p the length is 21
r the length is 22
o the length is 23
g the length is 24
r the length is 25
a the length is 26
m the length is 27
m the length is 28
i the length is 29
n the length is 30
g the length is 31
the length is 32
C the length is 19
18/06/2001