-->

program to read age of any 100 persons and count the number of persons in the age group between 20 and 40.

/*program to read age of any 100 persons and count the number of persons in the age group between 20 and 40.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int total_person,person_age,count=0,k;
printf("enter total number of persons\n");
scanf("%d",&total_person);
for(k=1;k<=total_person;k++)
   {
        printf("enter age of persons\n");
         scanf("%d",&person_age);
           if(person_age>=20 && person_age<=40)
               {
                 count=count+1;
               }
    }
printf("total persons falling in range=%d",count);
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------------------
logics in mind:-
->we need person's age,total persons,and count variable
->enter total number of persons o you can take 100 as  fixed value
->use loop to enter age repeatedly 100 times.
               ->input age inside loop
->we have to count ages so we use 'if' inside loop as shown above.
->inside loop, if the condition matches then 'count' goes for increment.
->this testing goes for 100 times
->then it stops
->last value of 'count' is then displayed.

note:
better to use array for above program.

program to get/display digits which are odd in a number.



//program to get/display digits which are odd in a number.
#include<stdio.h>
#include<conio.h>
void main()
{
   int n,rem;
   printf("enter a number for 'n'\n");
  scanf("%d",&n);
  while(n!=0)
    {
      rem=n%10;
       if(rem%2!=0)
        {
          printf("%d",rem);
          }
       n=n/10;    
   }
getch();
}
--------------------------------------------------------------------------------------------------
logics in mind:-
>first we enter a number(for 'n').
->If we have number 123 then its  odd digits  are 1 and 3 only. It means, first we have to get 3 then 2 and then 1 to check all digits.        
                  ->For this, 
                 ->we have to divide by 10 to get last digit as remainder. 
                 ->we divide that 'remainder' by 2 to get remainder.If 'remainder' is not '0' then we understand that the digit is odd and if not then that is not.
                 ->Then we display that.
                -> to get second digit, we get first 12 and for this , we use 123/10.It is done to get integer                           part  only.
->We repeat this until the value reaches 0. We use loop for this as shown above in the code.        

program to get/display digits which are even in a number.

//program to get/display digits which are even in a number.
#include<stdio.h>
#include<conio.h>
void main()
{
   int n,rem;
   printf("enter a number for 'n'\n");
  scanf("%d",&n);
  while(n!=0)
    {
      rem=n%10;
       if(rem%2==0)
        {
          printf("%d",rem);
          }
       n=n/10;    
   }
getch();
}
--------------------------------------------------------------------------------------------------
logics in mind:-
>first we enter a number(for 'n').
->If we have number 123 then its even digits are 2 only. It means, first we have to get 3 then 2 and then 1 to check all digits.        
                  ->For this, 
                 ->we have to divide by 10 to get last digit as remainder. 
                 ->we divide that 'remainder' by 2 to get remainder.If 'remainder' is 0 then we understand that the digit is even and if not then that is not.
                 ->Then we display that.
                -> to get second digit, we get first 12 and for this , we use 123/10.It is done to get integer                           part  only.
->We repeat this until the value reaches 0. We use loop for this as shown above in the code.        

program to get/display digits which are odd positioned in a number.

//program to get/display digits which are odd positioned in a number.
#include<stdio.h>
#include<conio.h>
void main()
{
   int n,rem,count=0;
   printf("enter a number for 'n'\n");
  scanf("%d",&n);
  while(n!=0)
    {
      rem=n%10;
       count++;
       if(count%2!=0)
        {
          printf("%d",rem);
          }
       n=n/10;    
   }
getch();
}
--------------------------------------------------------------------------------------------------
logics in mind:-
>first we enter a number(for 'n').
->If we have number 123 then its odd positioned digits are 1 and 3(from both side). It means, first we have to get 3 then 2 and then 1 to check all digits.        
                  ->For this, 
                 ->we have to divide by 10 to get last digit. 
                 ->we also use 'count' with initial value '0' to to know position  of digits.
                 ->we divide that count by 2 to get remainder.If count is not equal to 2 then we understand that the digit is in odd position and if not then that is not.
                 ->Then we display that.
                -> to get second digit, we get first 12 and for this , we use 123/10.It is done to get integer                           part  only.
->We repeat this until the value reaches 0. We use loop for this as shown above in the code.        

program to get/display digits which are even present in a number.

//program to get/display digits which are even position present in a number.
#include<stdio.h>
#include<conio.h>
void main()
{
   int n,rem,count=0;
   printf("enter a number for 'n'\n");
  scanf("%d",&n);
  while(n!=0)
    {
      rem=n%10;
       count++;
       if(count%2==0)
        {
          printf("%d",rem);
          }
       n=n/10;    
   }
getch();
}
--------------------------------------------------------------------------------------------------
logics in mind:-
>first we enter a number(for 'n').
->If we have number 123 then its even positioned digits are 2(from both side). It means, first we have to get 3 then 2 and then 1.        
                  ->For this, 
                 ->we have to divide by 10 to get last digit. 
                 ->we also use 'count' to to know position  of digits.
                 ->we divide that count by 2 to get remainder.If count is 2 then we understand that the digit is in even position and if not then that is not.
                 ->Then we display that.
                -> to get second digit, we get first 12 and for this , we use 123/10.It is done to get integer                           part  only.
->We repeat this until the value reaches 0. We use loop for this as shown above in the code.        

program to get sum of all digits present in a number.

//program to get sum of all digits present in a number.
#include<stdio.h>
#include<conio.h>
void main()
{
   int n,rem,sum=0;
   printf("enter a number for 'n'\n");
  scanf("%d",&n);
  while(n!=0)
    {
      rem=n%10;
       sum=sum+rem;
        n=n/10;    
   }
   printf("the sum=%d",sum);
getch();
}
--------------------------------------------------------------------------------------------------------
logics in mind:-
>first we enter a number(for 'n').
->to get sum of digits,first we have to get all digits one by one.If we have number 123 then its sum is 3+2+1=6. It means, first we have to get 3 then 2 and then 1.        
     ->For this, 
                 ->we have to divide by 10 to get last digit. 
                ->Then we go for sum using sum=sum+digit.
                -> to get second digit, we get first 12 and for this , we use 123/10.It is done to get integer                           part  only.
->We repeat this until the value reaches 0 and last sum is received. We use loop for this as shown above in the code.             
->then final sum is displayed.    


program to reverse a number.

//program to reverse a number.
#include<stdio.h>
#include<conio.h>
void main()
{
   int n,rem;
   printf("enter a number for 'n'\n");
  scanf("%d",&n);
  while(n!=0)
    {
      rem=n%10;
       printf("%d",rem);
       n=n/10;    
   }
getch();
}
--------------------------------------------------------------------------------------------------------
logics in mind:-
>first we enter a number(for 'n').
->If we have number 123 then its reverse is 321. It means, first we have to get 3 then 2 and then 1.        ->For this, 
                 ->we have to divide by 10 to get last digit. 
                 ->Then we display that.
                -> to get second digit, we get first 12 and for this , we use 123/10.It is done to get integer                           part  only.
->We repeat this until the value reaches 0. We use loop for this as shown above in the code.