Showing posts with label C-Programing. Show all posts
Showing posts with label C-Programing. Show all posts

Sunday, 26 May 2013

0 A C - PROGRAM TO RIGHT ROTATE (WITHOUT CALLING FUNCTION) A GIVEN INTEGER

RIGHT ROTATION

Bit Rotation: A rotation (or circular shift) is an operation similar to shift except that the bits that fall off at one end are put back to the other end.
In left rotation, the bits that fall off at left end are put back at right end.
In right rotation, the bits that fall off at right end are put back at left end.
Example:
Let n is stored using 8 bits. Left rotation of n = 11100101 by 3 makes n = 00101111 (Left shifted by 3 and first 3 bits are put back in last ). If n is stored using 16 bits or 32 bits then left rotation of n (000…11100101) becomes 00..0011100101000.
Right rotation of n = 11100101 by 3 makes n = 10111100 (Right shifted by 3 and last 3 bits are put back in first ) if n is stored using 8 bits. If n is stored using 16 bits or 32 bits then right rotation of n (000…11100101) by 3 becomes 101000..0011100.


PROGRAM IS :


#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,r;
    printf("Enter the unsigned int \n");
    scanf("%d",&i);
    printf("Enter the no of bits \n");
    scanf("%d",&j);
    r=i>>j;
    printf("The value of %d after rotating %d bits to the right is = %d \n ",i,j,r);
    getch();
}


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software) 
Or else you can try this demo file and use it ... 
Click HERE to download this file. 
(Press ctrl+z and hit Enter to end the program).. 
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program... 


IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.




0 A C - PROGRAM TO RIGHT ROTATE (USING CALLING FUNCTION) A GIVEN INTEGER

RIGHT ROTATION

Bit Rotation: A rotation (or circular shift) is an operation similar to shift except that the bits that fall off at one end are put back to the other end.
In left rotation, the bits that fall off at left end are put back at right end.
In right rotation, the bits that fall off at right end are put back at left end.
Example:
Let n is stored using 8 bits. Left rotation of n = 11100101 by 3 makes n = 00101111 (Left shifted by 3 and first 3 bits are put back in last ). If n is stored using 16 bits or 32 bits then left rotation of n (000…11100101) becomes 00..0011100101000.
Right rotation of n = 11100101 by 3 makes n = 10111100 (Right shifted by 3 and last 3 bits are put back in first ) if n is stored using 8 bits. If n is stored using 16 bits or 32 bits then right rotation of n (000…11100101) by 3 becomes 101000..0011100.


PROGRAM IS :


#include<stdio.h>
#include<conio.h>
int rightrot(int x,int y);
int i,j,k,r;
void main()
{
    printf("Enter a unsigned int \n");
    scanf("%d",&i);
    printf("Enter the number of bits to rotate \n");
    scanf("%d",&j);
    k=rightrot(i,j);
    printf("The value of %d after rotating %d bits to the right = %d \n",i,j,k);
    getch();
}
int rightrot(int x,int y)
    {

        r=x>>y;
        return r;
}




Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software) 
Or else you can try this demo file and use it ... 
Click HERE to download this file. 
(Press ctrl+z and hit Enter to end the program).. 
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program... 



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C - PROGRAM TO REVERSE A GIVEN STRING.

REVERSE A GIVEN STRING
This program reverses a string entered by the user. For example if a user enters a string "reverse me" then on reversing the string will be "em esrever".

 THE PROGRAM IS :

#include<stdio.h>
#include<conio.h>
void reverse(char[]);
char str[100],r[100],revstr[100];
int i,j,k;
void main()
{
    printf("Enter the string \n");
    gets(str);
    reverse(str);
}
    void reverse(char r[100])
    {
        k=0;
        for(i=0;r[i]!='\0';i++)
        {
            k++;
        }
        j=0;
        for(i=k-1;i>=0;i--)
        {
            revstr[j]=r[i];
            j++;
        }
        printf("The original string is \n");
        puts(str);
        printf("The reversed string is \n");
        for(i=0;i<k;i++)
        {
            printf("%c",revstr[i]);
        }
        printf("\n");
        getch();
    }



Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software) 
Or else you can try this demo file and use it ... 
Click HERE to download this file. 
(Press ctrl+z and hit Enter to end the program).. 
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program... 



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C - PROGRAM FOR MATCH ANY CHARACTER BETWEEN TWO ENTERED STRINGS (WORDS)

MATCH STRING 
THIS IS A PROGRAM TO MATCH ANY CHARACTER OF TWO ENTERED STRING (WORDS) AND DISPLAY THE POSITION (FIRST POSITION) OF THE CHARACTER MATCHED FROM THE 1ST ENTERED STRING.


THE PROGRAM IS :
#include<stdio.h>
#include<stdio.h>
int matchany(char [],char []);
void main()
{
    int pos;
    char s1[20],s2[20];
    printf("Enter the first string \n");
    gets(s1);
    printf("Enter the second string \n");
    gets(s2);
        pos=matchany(s1,s2);
        printf("\n The first string is %s \n",s1);
        printf("\n The second string is %s \n",s2);
        if(pos==-1)
        {
            printf("\n no character of %s is present in %s \n",s1,s2);
        }
        else
        {
            printf("\n the match letter in %s is at position = %d \n",s1,pos);
        }
        getch();
}
        int matchany(char s1[],char s2[])
        {
            int i,j;
            for(i=0;s1[i]!='\0';i++)
            {
                for(j=0;s2[j]!='\0';j++)
                {
                    if(s1[i]==s2[j])
                    {
                        return (i+1);
                    }
                }
            }
            return -1;
        }
 



Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software) 
Or else you can try this demo file and use it ... 
Click HERE to download this file. 
(Press ctrl+z and hit Enter to end the program).. 
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program... 


IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C PROGRAM TO FIND WHETHER THE GIVEN NUMBER IS PRIME OR NOT.

PRIME NUMBER :
A natural number (i.e. 1, 2, 3, 4, 5, 6, etc.) is called a prime or a prime number if it has exactly two positive divisors, 1 and the number itself.Natural numbers greater than 1 that are not prime are called composite.
Among the numbers 1 to 6, the numbers 2, 3, and 5 are the prime numbers, while 1, 4, and 6 are not prime. 1 is excluded as a prime number, for reasons explained below. 2 is a prime number, since the only natural numbers dividing it are 1 and 2. Next, 3 is prime, too: 1 and 3 do divide 3 without remainder, but 3 divided by 2 gives remainder 1. Thus, 3 is prime. However, 4 is composite, since 2 is another number (in addition to 1 and 4) dividing 4 without remainder:
4 = 2 · 2.
5 is again prime: none of the numbers 2, 3, or 4 divide 5. Next, 6 is divisible by 2 or 3, since
6 = 2 · 3.
Hence, 6 is not prime. The image at the right illustrates that 12 is not prime: 12 = 3 · 4. No even number greater than 2 is prime because by definition, any such number n has at least three distinct divisors, namely 1, 2, and n. This implies that n is not prime. Accordingly, the term odd prime refers to any prime number greater than 2. In a similar vein, all prime numbers bigger than 5, written in the usual decimal system, end in 1, 3, 7, or 9, since even numbers are multiples of 2 and numbers ending in 0 or 5 are multiples of 5.


THE PROGRAM IS :
 #include<stdio.h>
#include<stdio.h>
int isprime(int);
int i,r,n,c=0;
void main()
{
  
    printf("Enter the number \n");
    scanf("%d",&n);
    r=isprime(n);
    if(r==1)
    {
        printf(" %d is a prime number \n",n);
    }
    else
    {
        printf(" %d is not a prime number \n",n);
    }
    getch();
}
    int isprime(int x)
    {
        for(i=1;i<=x;i++)
        {
            if(x%i==0)
            {
                c++;
            }
        }
        if(c==2)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }




Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software) 
Or else you can try this demo file and use it ... 
Click HERE to download this file. 
(Press ctrl+z and hit Enter to end the program).. 
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program... 



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!


Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C PROGRAM TO MULTIPLY TWO MATRIX AND DISPLAY THE RESULT

MATRIX MULTIPLICATION :
In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries. An example of a matrix with 2 rows and 3 columns is
\begin{bmatrix}1 & 9 & -13 \\20 & 5 & -6 \end{bmatrix}.
Matrices of the same size can be added or subtracted element by element. But the rule for matrix multiplication is that two matrices can be multiplied only when the number of columns in the first equals the number of rows in the second.
A matrix is a rectangular array of numbers or other mathematical objects, for which operations such as addition and multiplication are defined

 Matrices are commonly written in box brackets:

THE PROGRAM IS : 
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p,q;
printf("Enter the size of the matrix A \n");
scanf("%d%d",&m,&n);
printf("Enter the size of the matrix B \n");
scanf("%d%d",&p,&q);
if(n!=p)
{
    printf("Matrix multiplication is not possible \n");
}
else
{
    printf("Enter the elements of matrix A \n");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    printf("Enter the elements of matrix B \n");
    for(i=0;i<p;i++)
    {
        for(j=0;j<q;j++)
        {
            scanf("%d",&b[i][j]);
        }
    }
    for(i=0;i<m;i++)
    {
        for(j=0;j<q;j++)
        {
            c[i][j]=0;
            for(k=0;k<n;k++)
            {
                c[i][j]=c[i][j]+a[i][k]*b[k][j];
            }
        }
    }
    printf("Matrix A is \n");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            printf(" %d ",a[i][j]);
        }
        printf("\n");
    }
    printf("The Matrix B is \n");
    for(i=0;i<p;i++)
    {
        for(j=0;j<q;j++)
        {
            printf(" %d ",b[i][j]);
        }
        printf("\n");
    }
    printf("The resultant matrix is \n");
        for(i=0;i<m;i++)
        {
            for(j=0;j<q;j++)
            {
                printf(" %d ",c[i][j]);
            }
            printf("\n");
        }
}
getch();
}


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software) 
Or else you can try this demo file and use it ... 
Click HERE to download this file. 
(Press ctrl+z and hit Enter to end the program).. 
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program... 


IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.


0 A C - PROGRAM TO FIND THE VALUE OF exp(0.5) USING TAYLOR SERIES

TAYLOR SERIES
The Taylor series of a real or complex-valued function Æ’(x) that is infinitely differentiable in a neighborhood of a real or complex number a is the power series
f(a)+\frac {f'(a)}{1!} (x-a)+ \frac{f''(a)}{2!} (x-a)^2+\frac{f^{(3)}(a)}{3!}(x-a)^3+ \cdots.  
1 + \frac{x^1}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \frac{x^5}{5!}+ \cdots = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + \frac{x^5}{120} + \cdots\! = \sum_{n=0}^\infty \frac{x^n}{n!}.



 THE PROGRAM :
#include<stdio.h>
#include<math.h>
#include<float.h>
#include<conio.h>
void main()
{
    double x=0.5,e=1.0,term=1.0,fact=1.0;
    int i;
    for(i=1;term>=FLT_EPSILON;i++)
    {
        fact=fact*i;
        term=pow(x,i)/fact;
        e=e+term;
    }
    printf("\n Sum without using library function exp(%lf) = %lf \n",x,e);
    printf("\n Sum using library function exp(%lf) = %lf \n",x,exp(x));
    getch();
}

Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it ...
Click HERE to download this file.

(Press ctrl+z and hit Enter to end the program)..
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...


IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C - PROGRAM TO FIND THE WORDLENGHT(without calling function) OF THE HOST MACHINE.

WORD LENGTH :

Word-length (also known as bit-depth) indicates how many digits are used to represent a value in a digital word. For instance, a word-length of 8-bits (8 digits) can only have values from 00000000 to 11111111 (in decimal, 0 to 255). A word-length of 16-bits can have values from 0000000000000000 to 1111111111111111 (0 to 65,536). A digital word doubles in resolution with each bit. For example a 16-bit sample has twice as many possible values (65,536) as a 15-bit word (32,768). 


THE PROGRAM IS :  
#include<stdio.h>
#include<conio.h>
void main()
{
    int count;
    unsigned int n;
    count=0;
    n=~0;
    while(n!=0)
    {
        n=n<<1;
        count++;
    }
    printf("word lenght of the machine is = %d bits \n",count);
    getch();
}


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it ...
Click HERE to download this file.

(Press ctrl+z and hit Enter to end the program)..
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C - PROGRAM TO FIND THE WORDLENGHT(calling function) OF THE HOST MACHINE.

WORD LENGTH :

Word-length (also known as bit-depth) indicates how many digits are used to represent a value in a digital word. For instance, a word-length of 8-bits (8 digits) can only have values from 00000000 to 11111111 (in decimal, 0 to 255). A word-length of 16-bits can have values from 0000000000000000 to 1111111111111111 (0 to 65,536). A digital word doubles in resolution with each bit. For example a 16-bit sample has twice as many possible values (65,536) as a 15-bit word (32,768). 



THE PROGRAM IS : 
 #include<stdio.h>
#include<conio.h>
int wordlenght();
void main()
{
    int x;
    x=wordlenght();
    printf("World lenght of the machine is = %d bits \n",x);
    getch();
}
int wordlenght()
{
    int count;
    unsigned int n;
    n=~0;
    count=0;
    while(n!=0)
    {
        n=n<<1;
        count++;
    }
    return count;
}


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it ...
Click HERE to download this file.

(Press ctrl+z and hit Enter to end the program)..
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C - PROGRAM TO BUBBLE SORT THE GIVEN NUMBERS.

BUBBLE SORT :
Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, most of the other sorting algorithms are more efficient for large lists.

THE PROGRAM IS :
#include<stdio.h>
#include<conio.h>
void main()
{
    int i,n,j,t,a[100];
    printf("Enter the no of elements \n");
    scanf("%d",&n);
    printf("Enter the elements of the array \n");
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(j=1;j<=n;j++)
    {
        for(i=0;i<n-1;i++)
        {
            if(a[i]>a[i+1])
            {
                t=a[i];
                a[i]=a[i+1];
                a[i+1]=t;
            }
        }
    }
    printf("The sorted array is \n");
    for(i=0;i<n;i++)
    {
        printf("%d",a[i]);
        printf("\n");
    }
    getch();
}
 


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it ...
Click HERE to download this file.

(PRESS ctrl+z to end the program)..
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...


IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C PROGRAM TO BINARY SEARCH ANY ELEMENT .

BINARY SEARCH :  
In computer science, a binary search or half-interval search algorithm finds the position of a specified value (the input "key") within a sorted array.In each step, the algorithm compares the input key value with the key value of the middle element of the array. If the keys match, then a matching element has been found so its index, or position, is returned. Otherwise, if the sought key is less than the middle element's key, then the algorithm repeats its action on the sub-array to the left of the middle element or, if the input key is greater, on the sub-array to the right. If the remaining array to be searched is reduced to zero, then the key cannot be found in the array and a special "Not found" indication is returned.
A binary search halves the number of items to check with each iteration, so locating an item (or determining its absence) takes logarithmic time. A binary search is a dichotomic divide and conquer search algorithm.
 Its a program to search any element by comparing with its middle term and changing its middle term after each execution.

THE PROGRAM IS :
#include<stdio.h>
#include<conio.h>
void main()
{
    int low,high,mid,i,n,a[50],key;
    printf("Enter the number of elements \n");
    scanf("%d",&n);
    printf("Enter the elements into an array \n");
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("Enter the element to be searched \n");
    scanf("%d",&key);
    low=0;
    high=n-1;
    mid=(low+high)/2;
    while(low<=high&&key!=a[mid])
    {
        mid=(low+high)/2;
        if(key>a[mid])
        {
            low=mid+1;
        }
        else
        {
            high=mid-1;
        }
    }
        if(key==a[mid])
        {
            printf("The element is present \n");
        }
        else
        {
            printf("The element is not present \n");
        }
        getch();
}



Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it ...
Click HERE to download this file.

(PRESS ctrl+z to end the program)..
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...


IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

Saturday, 25 May 2013

0 A C - PROGRAM TO REPLACE MORE BLANKS OF ANY STRING WITH SINGLE BLANK

THIS IS A PROGRAM WHICH WILL REPLACE MORE BLANK (IF PRESENT) WITH A SINGLE BLANK....
THE PROGRAM IS :
#include<stdio.h>
#include<conio.h>
int main(void)
{
    char c;
    int inspace;
    inspace=0;
    while((c=getchar(c))!=EOF)
    {
        if(c==' ')
        {
            if(inspace==0)
            {
                inspace=1;
                putchar(c);
            }
        }
        if(c!=' ')
        {
            inspace =0;
            putchar(c);
        }
    }
    getch();
}


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it ...
Click HERE to download this file.

(PRESS ctrl+z to end the program)..
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C - PROGRAM TO FIND THE SUM OF A POLYNOMIAL.

A POLYNOMIAL IS A FUNCTION WHICH IS FORMED BY THE COMBINATION OF VARIABLES AND CONSTANTS OR SOLELY VARIABLES...
IT MAY BE OF MANY TYPE , IT MAY CONTAIN MORE THAN ONE VARIABLE ALSO AND ETC.
A POLYNOMIAL IS GENERALLY DENOTED BY "f(x)" OR "p(x)" OR "f(x,y)" ETC..
HERE WE ARE DEALING WITH ONLY ONE VARIABLE i.e "x" .
 HERE IS A C PROGRAM TO FIND THE SUM OF A POLYNOMIAL GIVEN BELOW :
f(x) = ax^n + bx^(n-1) + cx^(n-2) + .......
The program will demand user to enter the value of "x" and will automatically print the necessary output....

THE PROGRAM IS :
#include<stdio.h>
#include<conio.h>
void main()
{
    int sum=0,x,a[20];
    int i,n;
    printf("Enter the number of coefficient \n");
    scanf("%d",&n);
    printf("Enter the %d polynomial(s)\n",n+1);
    for(i=0;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("Enter the value of x \n");
    scanf("%d",&x);
    sum=a[n]*x;
    for(i=n-1;i>0;i--)
    {
        sum=(sum+a[i])*x;
    }
        sum=sum+a[0];
        printf("The sum = %d \n",sum);
        getch();
}


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it to find the sum of a polynomial ...
Click HERE to download this file.

~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C - PROGRAM TO FIND WHETHER A NUMBER IS PALINDROME OR NOT.

PALINDROME  
 A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction.


                                                           THE PROGRAM IS :
#include<stdio.h>
#include<conio.h>
void main()
{
 int m,n,gcd,lcm,rem,p,q;
 printf("enter the no m and n \n");
 scanf("%d%d",&m,&n);
 p=m;
 q=n;
 while(n!=0)
 {
     rem=m%n;
     m=n;
     n=rem;
}
  gcd=m;
  printf("\n gcd of %d and %d is = %d\n",p,q,gcd);
  lcm=(p*q)/gcd;
  printf("\n lcm of %d and %d is = %d\n",p,q,lcm);
getch();
}


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it to find whether a number is palindrome or not ...
Click HERE to download this file.

~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...




IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C - PROGRAM TO FIND THE GREATEST COMMON DIVISIOR (GCD) AND LEAST COMMON MULTIPLE (LCM)

The greatest common divisor (GCD), which is also known as the greatest common factor (GCF), of two or more integers is the largest integer that is a common divisor (factor) of all the given integers.
Least Common Multiple
The least common multiple (LCM), which is also known as the least common denominator (LCD) in fractions, of two or more integers is the smallest integer that is a common multiple (denominator) of all the given integers.

THE PROGRAM IS TO FIND GCD AND LCM :
#include<stdio.h>
#include<conio.h>
void main()
{
 int m,n,gcd,lcm,rem,p,q;
 printf("enter the no m and n \n");
 scanf("%d%d",&m,&n);
 p=m;
 q=n;
 while(n!=0)
 {
     rem=m%n;
     m=n;
     n=rem;
}
  gcd=m;
  printf("\n gcd of %d and %d is = %d\n",p,q,gcd);
  lcm=(p*q)/gcd;
  printf("\n lcm of %d and %d is = %d\n",p,q,lcm);
getch();
}


Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it to find GCD and LCM ...
Click HERE to download this file.

~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...



IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

0 A C - PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION.

Here is a C program to find the roots of a quadratic equation.
Quadratic Equation is denoted by
ax^2+bx+c=0,\,
where "x" is unknown and its value will be the highest degree of the polynomial.
It can be calculated by knowing the coefficients i.e a , b, c..
The formula for calculating the is :
x=-\frac{b}{2a}\pm\frac{\sqrt{b^2-4ac\ }}{2a}=\frac{-b\pm\sqrt{b^2-4ac\ }}{2a}.
so now here is a C program fully executed and verified for how to finding the roots of any quadratic equation...
THE PROGRAM IS :
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
    float a,b,c,d,root1,root2,rpart,ipart;
    printf("Enter the values of a,b,and c\n");
    scanf("%f%f%f",&a,&b,&c);
    d=(b*b)-(4*a*c);
    if(d==0)
    {
        printf("The Roots are equal \n");
        root1=-b/(2*a);
        root2=root1;
        printf("The roots are root1 =%f and root2=%f \n",root1,root2);
    }
    else if(d>0)
    {
        printf("The roots are distinct \n");
        root1=(-b+sqrt(d))/(2*a);
        root2=(-b-sqrt(d))/(2*a);
        printf("The roots are \n root1 = %f \n and root2 = %f \n",root1,root2);
    }
    else
    {
        printf("The roots are imaginary \n");
        rpart=(-b/(2*a));
        ipart=(sqrt(fabs(d))/(2*a));
        printf("The roots are root1 = %f + i%f \n",rpart,ipart);
        printf("Root2 = %f-i%f \n",rpart,ipart);
    }
    getch();
}

Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this file and use it to find the roots of a quadratic equation ...
Click HERE to download this file.

~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...


IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.