-->

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

program to print/display all factors of number 'n'.

 //program to print/display all factors of  number 'n'.
#include<stdio.h>
include<conio.h>
void main()
{
   int number,factors,i;
   printf("enter any positive number\n");
  scanf("%d",&number);
  for(i=1;i<=number;i++)
    {
      if(number%i==0)
        {                printf("the factors are=%d ",i);
        }getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number whose factors value you want to find
->we have to go for repetitive process from number 1 to entered number 'number' i.e we divide given number 'number by 1,2,3... and itself. This we can apply using loop as shown above.If we get zero as remainder while dividing then we display that.

program to get factorial value of a positive number

//program to get factorial value of a positive number
#include<stdio.h>
include<conio.h>
void main()
{
   int number,fact=1,i;
   printf("enter any positive number\n");
  scanf("%d",&number);
if(number>0)

 for(i=1;i<=number;i++)
    {
     fact=fact*i;
   }
}
else
{
printf("the number is not +ve\n");
}
 printf("the factorial value for entered number=%d is =%d\n",number,fact);
getch();
}
------------------------------
logics in mind:
->enter a number whose factorial value you want to find
->we have to go for repetitive multiplication from number 1 to entered number 'number'. This we can apply using loop as shown above.
->display the final value of variable 'fact'.

   

program to convert hexadecimal number into binary number system.

//program to convert hexadecimal number into binary number system.
#include<stdio.h>
#define MAX 100
void main()
{
    char binaryNumber[MAX],hexaDecimal[MAX];
    long int i=0;

    printf("Enter any hexadecimal number: ");
    scanf("%s",hexaDecimal);

    printf("\nEquivalent binary value: ");
    while(hexaDecimal[i])
{
         switch(hexaDecimal[i])
      {
             case '0': printf("0000"); 
                              break;
             case '1': printf("0001"); 
                             break;
             case '2': printf("0010"); 
                             break;
             case '3': printf("0011"); 
                            break;
             case '4': printf("0100"); 
                             break;
             case '5': printf("0101"); 
                            break;
             case '6': printf("0110"); 
                           break;
             case '7': printf("0111"); 
                          break;
             case '8': printf("1000"); 
                           break;
             case '9': printf("1001"); 
                          break;
             case 'A': case 'a': printf("1010"); 
                         break;
             case 'B': case 'b': printf("1011"); 
                         break;
             case 'C': case 'c': printf("1100"); 
                         break;
             case 'D': case 'd': printf("1101"); 
                          break;
             case 'E': case 'e': printf("1110"); 
                         break;
             case 'F': case 'f': printf("1111"); 
                        break;
        
             default:  
                    printf("\nInvalid hexadecimal digit %c ",hexaDecimal[i]);

         }                           
         i++;
    }
    getch();

}
logics in mind/applied:
->we enter here hexadecimal number
->we make group of 4 bits equivalent of each digit
->for this, we check each digit.
->To check digit, we use loop and switch with each digit equivalent.


program to convert binary no. to hexadecimal number system.

//program to convert binary no. to hexadecimal number system.
#include<stdio.h>
#include<conio.h>
void main()
{
   
    long int binary_Number,hexadecimalNumber=0,j=1,remainder;
   
    printf("Enter any number any binary number: ");
    scanf("%ld",&binary_Number);
   
    while(binary_Number!=0)
{
    remainder=binary_Number%10;
    hexadecimalNumber=hexadecimalNumber+remainder*j;
        j=j*2;
        binary_Number=binary_Number/10;
      }

    printf("Equivalent hexadecimal value: %lX",hexadecimalNumber);

    getch();

}

-----------------------------------------------------------------------
logics in mind:-

->we have to input a binary number, say 111
->we make group of 3 bits from right side, and for this, we use 

hexdecimalNumber=hexadecimalNumber+remainder*j;

program to convert binary no. into octal number system

we have two methods for this conversion.
either we can convert binary to decimal and then decimal to octal
or we can directly convert into octal using 3 bits system.


//program to convert binary no. into octal number system
#include<stdio.h>
#include<conio.h>
void main()
{
   
    long int binary_Number,octalNumber=0,j=1,remainder;

    printf("Enter any number any binary number: ");
    scanf("%ld",&binary_Number);

    while(binary_Number!=0)
{
         remainder=binary_Number%10;
        octalNumber=octalNumber+remainder*j;
        j=j*2;
        binary_Number=binary_Number/10;
   }

    printf("Equivalent octal value: %lo",octalNumber);

    getch();
}

logics in mind:-

->we have to input a binary number, say 111
->we make group of 3 bits from right side, and for this, we use 
octalNumber=octalNumber+remainder*j;


        j=j*2;


program to convert octal no. into decimal number system.

//program to convert octal no. into decimal number system.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int k=1,m=0,n,rem,decimal=0;
printf("enter octal value/number for 'n'\n");
scanf("%d",&n);
while(n!=0)
   {
      rem=n%10;
      decimal=decimal+rem*pow(8,m);
      n=n/10;
      m++;
   }
printf("decimal is=%d\n",decimal);
getch();
}

logics in mind or applied:-
->if octal number is 234
-> we have to get first 4 and we multiply this with power( you can say increasing or decreasing)of 8
-> we have to add all 
->we display the last value