Sunday, April 12, 2020

c++ program to compute quotient and remainder

C++ Program to Compute Quotient and Remainder

#include 
using namespace std;

int main()
{    
    int divisor, dividend, quotient, remainder;

    cout << "Enter dividend: ";
    cin >> dividend;

    cout << "Enter divisor: ";
    cin >> divisor;

    quotient = dividend / divisor;
    remainder = dividend % divisor;

    cout << "Quotient = " << quotient << endl;
    cout << "Remainder = " << remainder;

    return 0;
}

Output

Enter dividend : 22
Enter divisor : 4
Quotient : 5
Remainder : 2

Happy Coding


Thanks for visiting my Blog.

Have any problem, feel free to contact us via Email : uoslondy@gmail.com

Have a good day!

Tuesday, April 7, 2020

c++ program to display name age and address

C++ program to display name age and address


#include 
using namespace std;

int main()
{
    int Number1, Number2, sum; 
    
    cout << "Enter  first integer number : ";
    cin >> Number1;
 cout << "Enter second integer number : ";
    cin >> Number2;
    // sum of two numbers in stored in variable sum
    sum = Number1 + Number2;

    // Prints sum 
    cout << Number1 << " + " <<  Number2 << " = " << sum;     

    return 0;
}

Output


Enter first number : 3
Enter second number : 5
3 + 5 = 8
Happy Coding

Thanks for visiting my Blog.

Have any problem, feel free to contact us via Email : uoslondy@gmail.com

Have a good day!

Monday, April 6, 2020

Thursday, April 2, 2020

c program to check given number is armstrong number or not

C program to check given number is armstrong number or not   

  • A Positive number is called Armstrong number.  

abcd.... = an + bn + cn + dn +

  • In this case of Armstrong number of 3 digits, the sum cubes of each digits is equal to the number of itself.

123 = 1*1*1 + 2*2*2 + 3*3*3
#include 
int main() 
{
    int num, originalNum, remainder, result = 0; // Integer values
    printf("Enter a three-digit integer: "); // Enter by user three digits
    scanf("%d", &num); // storing values
    originalNum = num; // replace number

    while (originalNum != 0) // while loop
    {
        // remainder contains the last digit
        remainder = originalNum % 10;
        
        result += remainder * remainder * remainder;
        
        // removing last digit from the orignal number
        originalNum /= 10;
    }

    if (result == num) // if else
        printf("%d is an Armstrong number.", num);
    else
        printf("%d is not an Armstrong number.", num);

    return 0;
}

Output

Enter three integer 371
371 is an Armstrong number
Happy coding

Thanks for visiting my Blog.

Have any problem, feel free to contact us via Email : uoslondy@gmail.com

Have a good day!

c program to print reverse of a number using while loop

C program to print reverse of a number using while loop


#include 
int main()
{
    int n, rev = 0, remainder; // Integer values
    printf("Enter an integer: "); // Enter user value
    scanf("%d", &n); // storing values
    
    while (n != 0) // while loop
    {
        remainder = n % 10;
        rev = rev * 10 + remainder;
        n /= 10;
    }
    printf("Reversed number = %d", rev); // finalize result
    return 0;
}
Output


Enter an integer : 2345
Reverse number is 5432
Happy Coding

Thanks for visiting my Blog.

Have any problem, feel free to contact us via Email : uoslondy@gmail.com

Have a good day!

c program to calculate power of a number

C program to calculate power of a number

  • The program takes two integer from user and then calculate power.
          For example : 2 pow 3 .
  • In case 2 is base number and 3 is exponent number.  (2*2*2)
#include 
int main() 
{
    int base, exp; // integer values 
    long long result = 1; // constant values
    printf("Enter a base number: "); // User enter 
    scanf("%d", &base); //storing values
    printf("Enter an exponent: "); // User enter 
    scanf("%d", &exp); // storing values

    while (exp != 0) // while loop
    {
        result = result * base;
        --exp;
    }
    printf("Answer = %lld", result); // finalize result
    return 0;
}
Output


Ente a base number 3
Enter exponent number 4
Answer = 81
Happy Coding

Thanks for visiting my Blog.

Have any problem, feel free to contact us via Email : uoslondy@gmail.com

Have a good day!

c program to check whether a number is palindrome or not using while loop

C program to check whether a number is palindrome or not using while loop

  • An integer is palindrome if the reverse of that number is equal to the original number.
#include 
int main() 
{
    int n, reversedN = 0, remainder, originalN;
    printf("Enter an integer: ");
    scanf("%d", &n);
    originalN = n;

    // reversed integer is stored in reversedN
    while (n != 0) 
 
    {
        remainder = n % 10;
        reversedN = reversedN * 10 + remainder;
        n /= 10;
    }

    // palindrome if orignalN and reversedN are equal
    if (originalN == reversedN)
        printf("%d is a palindrome.", originalN);
    else
        printf("%d is not a palindrome.", originalN);

    return 0;
}
Output


Enter an integer = 1001
1001 is palindrome 
Happy Coding

c program to check whether a character is uppercase or lowercase alphabet

c program to check whether a character is uppercase or lowercase alphabet 

#include 
int main()
{
    char c; // enter character value
    printf("Enter u to display uppercase alphabets.\n"); // U for uppcase
    printf("Enter l to display lowercase alphabets. \n"); // I for lowercase
    scanf("%c", &c); // storing values

    if (c == 'U' || c == 'u') 
     {
        for (c = 'A'; c <= 'Z'; ++c)
            printf("%c ", c);
     } else if (c == 'L' || c == 'l') 
 
     {
     for (c = 'a'; c <= 'z'; ++c)
            printf("%c ", c);
     } else 
 
     {
        printf("Error! You entered an invalid character.");
     }

    return 0;
}
Output


Enter u to display uppercase alphabets 
Enter l to display lowercase alphabets = I
a b c d e f g h i j k l m n o p q r s t u v w x y z 
Happy Coding

Thanks for visiting my Blog.

Have any problem, feel free to contact us via Email : uoslondy@gmail.com

Have a good day!

Recent Posts