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:
**



12 comments:

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

    ReplyDelete
  2. 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.

    ReplyDelete
  3. where use i value

    ReplyDelete
  4. what does i=i+2

    ReplyDelete
  5. what does i+2?

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

      Delete
  6. 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 .

    ReplyDelete
  7. sorry odd numbers will get printed.

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

    ReplyDelete
  9. /*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.

    ReplyDelete
    Replies
    1. how make this program with for loop? please code

      Delete
  10. how make this program with for loop? please code

    ReplyDelete