Computer Scientists are Pretty Pessimistic

Showing posts with label Basic Problems. Show all posts
Showing posts with label Basic Problems. Show all posts

Friday, 4 September 2015

WAP to swap the values of two integer variables, without using extra variable

#include <stdio.h>
int main ()
{
    int a,b;
    printf("Enter 1st number: ");
    scanf("%d",&a);
    printf("Enter 2nd number: ");
    scanf("%d",&b);
    printf("a = %d  b = %d\n",a,b);

    a=a+b;
    b=a-b;
    a=a-b;

    printf("After swaping a = %d  b = %d\n",a,b);
    return 0;
}

WAP to find out the quotient and remainder of two numbers. ( Without using modulus ( % ) operator)

#include <stdio.h>
int main ()
{
    int x,y,q,r;
    printf("Enter Divisor: ");
    scanf("%d",&x);
    printf("Enter Dividend: ");
    scanf("%d",&y);

    q=y/x;
    r=y-(x*q);

    printf("Quotient is %d\n",q);
    printf("Remainder is %d\n",r);
    return 0;
}

WAP to input a number and print its equivalent character code.

#include <stdio.h>
int main ()
{
    int n;
    printf("Enter a number: ");
    scanf("%d",&n);
    printf("\nEquivalent Character is %c\n",n);
    return 0;
}

WAP to input 4 integers a, b, c, d and check that the equation a3 + b3 +c3 = d3 is satisfied or not.

#include <stdio.h>
int cube (long long n);
int main ()
{
    long long a,b,c,d;
    printf("Enter the value of a,b,c,d:\n");
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    if((a*a*a)+(b*b*b)+(c*c*c)==(d*d*d))
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}