-->

program to get sum of (2x3)/5+(4x5)/7+(6x7)/9+,.... to nth term.

//program to get sum of (2x3)/5+(4x5)/7+(6x7)/9+,....           to nth term.
#include<stdio.h>
#include<conio.h>
void main()
{
   float i,n,k=2,m=3,p=5,sum=0;
      printf("enter  positive number for 'n'\n");
  scanf("%f",&n);
  for(i=1;i<=n;i++)
    {               
          sum=sum+(k*m)/p;
           k=k+2;
           m=m+2;
          p=p+2;        }
  printf("the sum=%f",sum);
getch();
}
-------------------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range for which you want to get sum, say 'n'.
->let a variable 'sum' with initial value '0'
->we get sum using formula sum=sum+(k*m)/p because in terms (2x3)/5+(4x5)/7+(6x7)/9+,...     ,
        the first value is k(2),second is m(3) and third is p(5).the values in second and all other terms are changing 
       by +2 so
        we put
          k=k+2;
           m=m+2;
          p=p+2; inside loop.
->at last we display final sum.

program to get 0.9,0.99,0.999,0.9999.....nth terms.

//program to get 0.9,0.99,0.999,0.9999.....nth terms.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float n,j, k=0.9;
clrscr();
printf("enter number of terms\n");
scanf("%f",&n);
for(j=1;j<=n;j++)
{
printf("%f,",k);
k=k+0.9/(pow(10,j));
}
getch();
}
-------------------------------------------------------------------------------------------------------------------------
logics in mind for this:-
->0.9,0.99,0.999............. can be written as
             0.9,0.9+0.09,0.99+0.009.......
->         for second term 0.99, it can be written as 0.9+0.09
 ->further it can be as(taking only two terms)
            0.9+( 0.9+0.9/10)...
->it can be as
          0.9+(0.9+0.9/101)...
->now we have to convert it in a formula as
        k=k+0.9/(pow(10,j)).here k=0.9 is taken
->and to display all the terms we have used loop

or

we can apply following technique:
//getting 0.9,0.99,0.999.....nth term
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float k=9,n,p=10,j,dis,m=1;
clrscr();
printf("enter number of terms\n");
scanf("%f",&n);
for(j=1;j<=n;j++)
{
dis=k/(pow(10,j));
printf("%f,",dis);
m++;
k=pow(p,m)-1;
}
getch();
}

->take 9 as a fixed value
->we enter no. of terms for 'n'.
->to display 0.9, we divide it (9) by 101
->to get 0.99, we take here 99, and for this we use 100-1 concept. we do this using k=pow(p,m)-1
        here pow finds power of 10(p).
->in next execution we get 0.99 and so on..

-> this is how loop continues and we get all terms

we can use different technique for same program.

         similarly we can also get 
1)9,99,999,9999......
2)2,22,222,2222....
3)5,55,555,5555......
4)0.99999,0.9999,0.999,0.99,0.9
    for this,
      there are 5 nines so it can be written as
         (100000-1)/105,(10000-1)/104........
         (105-1)/105,(104-1)/104........  
       now make a formula to get this one. And it is easy task...  
                   

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.