Tuesday, November 25, 2014

C using convert pro



C Program to Convert Binary to Octal

#include 
#include 
int main()
{
    long int binarynum, octalnum = 0, j = 1, remainder;
    clrscr();
    printf("Enter the value for  binary number: ");
    scanf("%ld", &binarynum);
    while (binarynum != 0)
    {
        remainder = binarynum % 10;
        octalnum = octalnum + remainder * j;
        j = j * 2;
        binarynum = binarynum / 10;
    }
    printf("Equivalent octal value: %lo", octalnum);
    return 0;
}
 
Output
        
Enter the value for binary number: 10101
Equivalent octal value: 25

C Program to check whether a given Number is Armstrong

#include 
#include
#include 
void main()
{
    int number, sum = 0, rem = 0, cube = 0, temp;
    clrscr();
    printf ("enter a number");
    scanf("%d", &number);
    temp = number;
    while (number != 0)
    {
        rem = number % 10;
        cube = pow(rem, 3);
        sum = sum + cube;
        number = number / 10;
    }
    if (sum == temp)
        printf ("The given no is armstrong no");
    else
        printf ("The given no is not a armstrong no");
    getch();
}
 
Output

Enter a number370
The given no is armstrong no
 

C Program to check whether a given Number is Perfect Number

#include 
#include 
int main()
{
    int number, rem, sum = 0, i;
    clrscr();
    printf("Enter a Number\n");
    scanf("%d", &number);
    for (i = 1; i <= (number - 1); i++)
    {
        rem = number % i;
   if (rem == 0)
        {
            sum = sum + i;
        }
    }
    if (sum == number)
        printf("Entered Number is perfect number");
    else
        printf("Entered Number is not a perfect number");
    return 0;
}
 
Output

Enter a Number
6
Entered Number is perfect number

C Program to Shutdown or Turn off the Computer in Linux

 
#include 
#include
int main()
{
    clrscr();
    system("Shutdown -P now");
    return 0;
}
 
Output
            
            Shutdown: Need to be root
C program to Increase 1 to all of the given Integer Digit
#include 
#include
int main()
{
    int number, sum = 0, remainder, count;
    clrscr();
    printf("Enter a number: ");
    scanf("%d", &number);
    while (number)
    {
        remainder = number % 10;
        sum  = sum + (remainder + 1);
        number /= 10;
    }
    printf("increasing 1 to all digits:  %d", sum);
    return 0;
}

Output

Enter a number: 3456
Increasing 1 to all digits:  22
C Program to add two Complex Numbers
#include 
#include
struct complex
{
   int realpart, imaginary;
};
 
main()
{
    struct complex a, b, c;
    clrscr();
    printf("Enter value of a and b complex number a + ib.\n");
    printf("Value of complex number a is = ");
    scanf("%d", &a.realpart);
    printf("Value of complex number b is = ");
    scanf("%d", &a.imaginary);
    printf("Enter value of c and d complex number c + id.\n");
    printf("Value of complex number c is = ");
    scanf("%d", &b.realpart);
    printf("Value of complex number d is = ");
    scanf("%d", &b.imaginary);
    c.realpart = a.realpart + b.realpart;
    c.imaginary = a.imaginary + b.imaginary;
    if (c.imaginary >= 0)
        printf("complex numbers sum is = %d + %di\n", c.realpart, c.imaginary);
    else
        printf("complex numbers sum = %d %di\n", c.realpart, c.imaginary);
    return 0;
}

Output
 
Enter value of a and b complex number a + ib.
Value of complex number a is = 10
Value of complex number b is = 12
Enter value of c and d complex number c + id.
Value of complex number c is = 15
Value of complex number d is = 22
Complex numbers sum is = 25 + 34i

No comments:

Post a Comment