## INDEX

### C program to print all odd numbers between 1 and 100

#include<stdio.h>
int main(){
int i;
for(i=1;i<100;i=i+2){
printf("%d\n",i);
}
}

Alogrithm:
**

Unknown said...

i dont understand the solutions pliiz help.....what does "%d"/n",i mean?

Priyanka kumari said...

prinf function is formated function.
"%d\n" is format. Here
%d represent decimal number or integer type number
\n is new line character.

We have used %d since variable is integer type variable and in the output %d will be replaced by value i.

If you have still doubt the you are welcome.

Anonymous said...

where use i value

Anonymous said...

what does i=i+2

Anonymous said...

what does i+2?

Anonymous said...

since the program is to find odd numbers from 1 to 100 , we use for loop. Here i=2 is the initialization,i<100 is the condition and i=i+2 is the increment operation i.e it will increment the condition. Here i=i+2 is to find for odd numbers.So all the numbers b/w 1 and 100 will get printed .

Anonymous said...

sorry odd numbers will get printed.

Anonymous said...

Initially i value is 1 so loop add 1+2 = 3

Anonymous said...

sir if user prints two unknown number and we have to find all the odd numbers between them then what should we do????

Anonymous said...

/*Find the even no and their sum*/
#include
main()
{
int i=1,n,s=0;
printf("enter the value of n\n");
scanf("%d",&n);
while(i<=n)
{
if(i%2==0)
{
printf(" %d ",i);
s=s+i;
}
i++;
}
printf("\n");
printf("s=%d\n",s);
}

if you want to take input i also user than not declare i=0, also take value of i from user same taken from n,but carefully at user input end I is less than N.

Anonymous said...

how make this program with for loop? please code

Anonymous said...

how make this program with for loop? please code

Unknown said...

Well explained

APURBA said...

in line number 14 you have stated if (i%2==0), what does it mean?

unknown said...

It means if d value of i is divided by 2 and if d remainder is equal to 0 den the value of i is an even number!! for eg. assume that if i=2 den from d if condition it is divisible by 2 n d remainder is 0 so the value of i wud b printd as an even number

Unknown said...

why the program is coming when the void is placed in it ????????

Unknown said...

one more way of doing is

#include

int main()
{
int i;
int a;
for(i=0;i<50;i++)
{
a=(2*i)+1;
printf("%d",a);
}
}

Unknown said...

one more way of doing is

#include

int main()
{
int i;
int a;
for(i=0;i<50;i++)
{
a=(2*i)+1;
printf("%d",a);
}
}

Unknown said...
This comment has been removed by the author.