-->

program to get series (Fibonacci)0,1,1,2,3,5,8....15th term.

//program to get series 0,1,1,2,3,5,8....15th term.
#include<stdio.h>
#include<conio.h>
void main()
{
    int i=0,j=1,n,k;
     printf("%d\n",i);
     printf("%d\n",j);
      printf("enter  nth  number for 'n'\n");
  scanf("%f",&n);
  for(i=1;i<=n-2;i++)
    {          
         k=i+j;     
          printf( "%d\n",k);
        i=j;
       j=k;
    }
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->take two initial numbers as 'i' and 'j' for first two values '0' and '1'. If you want then you can input these numbers and display them.
->since we need to display 15th terms so we input 15 or 16 for variable 'n'. We can also fix it inside loop.
->Fibonacci series is that where we get terms by adding two previous terms.
->We have displayed first two terms (0 and 1). now we need to display only 13th terms.
->We display that using loop.
->inside loop, we get next term by adding fist two terms (look above).
     ->we display that.
     ->now we assign value of 'j' to 'i' and 'k' to 'j'. it works and goes on working for next cycle/iteration

program to test whether a number is palindrome or no

//program to test whether a number is palindrome or not
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
   int n,n1,n2,rem,sum=0,count=0;
   printf("enter a number for 'n'\n");
  scanf("%d",&n);
n1=n;
n2=n;
  while(n!=0)
    {
       count=count+1;
       n=n/10;    

   }
count--;
while(n1!=0)
    {
       rem=n1%10;
       sum=sum+rem*(pow(10,count));
       n1=n1/10;
       count--;     
   }
if(sum==n2)
{
printf("it's palindrome\n");
}
else
{
printf("it's not palindrome");
}
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
a palindrome number is that which is same from both the sides i.e. from left to right and from right . e.g. 101 or 121 or 1221 etc.
->first we enter a number.
->before we go for further process,we first need to get total digits present in that number. For this, we have used loop (first,look above in code) with a variable 'count'. We have used logic 
                                                                                              ->count=count+1
                                                                                             ->n=n/10
->We decrease the value of 'count' by one. Let's take an example, 121.
                                                   ->we have to reverse it. for this, we first get last digit '1'. To get '1', we divide it                                                                     by 10 and get remainder. 
                                                  ->121 can be written as 100+20+1(in reverse order)
                                                                                        1x102+2x101+1x100
                                                  ->If we look at this expression then we can see the power is decreasing from 2                                                             to 0. So we have to start power from 2 and not from 3. So we have written                                                        count --
->We use again loop to get sum after reversing the entered number. We have also used power(count) in   decreasing order.
->as we get sum then we check that with original value.


program to get 1+1,1+2,1+3,1+4,1+5,.... to nth term.

//program to get of 1+1,1+2,1+3,1+4,1+5,....           to nth term.
#include<stdio.h>
#include<conio.h>
void main()
{
   int i,n,k=1;
      printf("enter  positive number for 'n'\n");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {               
         printf("%d+%d,",k,i);
        }
  
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range for which you want to get/print , say 'n'.
->let a variable k=1 with initial value '1'. We take this because first term has value '1'.
->Now we display each of the term using special format as shown above using printf.
->For first term we take variable k then we put characters '+' and ten 'i' because its value is changing 
  as the loop changes. We get that term.

program to get sum of 1+1,1+2,1+3,1+4,1+5,.... to nth term.

//program to get sum of 1+1,1+2,1+3,1+4,1+5,....           to nth term.
#include<stdio.h>
#include<conio.h>
void main()
{
   float i,n,k=1,sum=0;
      printf("enter  positive number for 'n'\n");
  scanf("%f",&n);
  for(i=1;i<=n;i++)
    {               
          sum=sum+(k+i);
        }
  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=0 with initial value '0'
->we get sum using formula sum=sum+k+i because in terms 1+1,1+2,1+3,1+4,1+5,....        ,the first value is same 
 and second value is changing so for first, k is working and for second, 'i' is working
->at last we display final sum.

program to test whether a number is prime or not.

//program to test whether a number is prime or not.
#include<stdio.h>
include<conio.h>
void main()
{
   int n,count=0,i;
   printf("enter a number for 'n'\n");
  scanf("%d",&n);
  for(i=2;i<n;i++)
    {
      if(n%i==0)
        {                
            count=1;
        }
   }
if(count==0)
{
printf("it's prime\n");
}
else
{
printf("it's not");
}
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
a prime number is that which is divisible by '1' and itself. It means there are only two numbers which can divide that given number. And any 3rd number is not there.
so here we check whether 3rd number is there or not.
->enter a number to be checked
->declare a variable with an initial value 0(u can use any other value)
-> use repetitive process from number 2 to one less than entered number 'n' i.e we divide given number 'n by 2,3... and n-1. This we can apply using loop as shown above.If we get zero as remainder while dividing then we assign value '1' to count.
->later, as the loop terminates then we check whether 'count' has got value 0 or 1.If it has '0' it means it is prime and if it has 1 then it is not prime.

we can also use following technique.
//program to test whether a number is prime or not.
#include<stdio.h>
include<conio.h>
void main()
{
   int n,count=0,i;
   printf("enter a number for 'n'\n");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      if(n%i==0)
        {                
            count++;
        }
   }
if(count==2)
{
printf("it's prime\n");
}
else
{
printf("it's not");
}
getch();

}
----------------------------------------
logics in mind:
->here, we have used same concept but in different way.
->we have used value from 1 to entered number 'n' in loop to count total numbers which can divide entered number
->obviously if count is 2 then it is prime and if not then it is not

program to print/display 1+1/1,1+1/2,1+1/3,1+1/4,1+1/5,.... to nth term.

//program to print/display 1+1/1,1+1/2,1+1/3,1+1/4,1+1/5,....           to nth term.
#include<stdio.h>
#include<conio.h>
void main()
{
   int i,n,k=1;
      printf("enter  positive number for 'n'\n");
  scanf("%d",&n);
  printf("%d+%d/%d,",k,k,k);
  for(i=2;i<=n;i++)
    {               
          printf("%d+%d/%d,",k,k,i);
        }
  
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range for which you want to display, say 'n'.
->let a number k with initial value '1'
->display this using printf with characters '/' and others. so or first term, we displayed it.
->for rest of terms,     ->we have to go for repetitive process from number 2 to entered number 'n'.
     ->we display each of term using printf and all other characters as shown above.
     ->If we get same value then then we display that.
     

program to print/display all perfect square numbers lying between 1 and 'n'.

//program to print/display all perfect square numbers lying between 1 and 'n'.
#include<stdio.h>
#include<conio.h>
#include<math.h>void main()
{
   int factors,i,n;
   printf("enter  positive number for 'n'\n");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      if(sqrt(i)==int(sqrt(i))
        {                
          printf("the perfect squares are=%d ",i);
        }
  }
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range to get perfect square
->we have to go for repetitive process from number 1 to entered number 'n'.
->we get square root of number and then its integer value . This we can apply using loop as shown above.
->If we get same value then then we display that.
     for this, we have used 
                if(sqrt(i)==int(sqrt(i))
              it checks square root and its integer value