Posts

Find the Armstrong number in cpp

Image
 How to find the Armstrong number in the cpp programming language? Here , you will find the solution to the problem to find the Armstrong number in cpp. Following is the code to find the Armstrong number.First,you know  What is Armstrong Number? A positive number which the sum of cube power of every digit is equal to the original number is called the Armstrong number. For example: Armstrong Number Code: #include <iostream> using namespace std; int main() {     int numb, original, rem, result = 0;     cout << "Enter a three-digit integer: ";     cin >> numb;     original= numb;     while (original != 0) {                  rem = original % 10;                  result += rem * rem * rem;                           original /= 10;     }     if (result == numb)         cout << numb << " is Armstrong number.";     else         cout << numb << " is not Armstrong number.";     return 0; } Output: Enter a three-digit integer

C Program convert octal to binary number

 Here, you will find the solution on how to convert the octal number to binary number in the c programming language. Following is the solution to the problem: Code: #include <math.h> #include <stdio.h> int main() {     int octal,original;     printf("Enter an octal number: ");     scanf("%d", &octal);   original=octal;     int deci = 0, i = 0;     long long bini = 0;     // convert octal to decimal     while (octal != 0) {         deci += (octal % 10) * pow(8, i);         ++i;         octal /= 10;     }     int a = 1;    // convert decimal to binary     while (deci != 0) {         bini += (deci % 2) * a;         deci /= 2;         a*= 10;     }         printf("%d in octal = %lld in binary", original, bini);     return 0; } Output: Enter an octal number: 25 25 in octal = 10101 in binary

C program to convert binary to octal number

 Here,we will find the solution of the conversion of the binary to the octal number system in the c programming language. Following is the solution of conversion: Code: #include <math.h> #include <stdio.h> int main() {     long long bina,original;     printf("Enter a binary number ? ");     scanf("%lld", &bina);          original=bina;     int oct = 0, deci = 0, i = 0;     // convert binary to decimal     while (bina != 0) {         deci += (bina % 10) * pow(2, i);         i++;         bina /= 10;     }     int j = 1;     // convert to decimal to octal     while (deci != 0) {         oct += (deci % 8) * j;         deci /= 8;         j *= 10;     }  printf("%lld in binary= %d in octal", original, oct);    return 0; } Output: Enter a binary number ? 10101 10101 in binary= 25 in octal

C Program convert octal to decimal Number

In this example,we will discuss how to convert octal to decimal number system in the c programming language. Following is the solution to the problem. Code: #include <stdio.h> #include <math.h> using namespace std; int main() {    int octalNumber,originalnumber;     printf("Enter a octal number: ");     scanf("%d", &octalNumber);   originalnumber=octalNumber;     int decimalNumber = 0, i = 0, remainder;     while (octalNumber != 0)      {            decimalNumber += (octalNumber%10) * pow(8,i);         ++i;         octalNumber/=10;     }      printf("%d in octal = %d in decimal", originalnumber, decimalNumber);    return 0; } Output: Enter a octal number: 74 74 in octal = 60 in decimal  

C Program convert decimal to octal Number

 In this example,we will discuss about how to convert decimal to octal in the c programming language.Following is the solution of the problem. code: #include <stdio.h> #include <math.h> using namespace std; int main() {    int deciNumber,originalnumber;     printf("Enter a decimal number: ");     scanf("%d", &deciNumber);   originalnumber=deciNumber;     int octalnumber = 0, i = 1, remainder;     while (deciNumber != 0)      {            remainder = deciNumber % 8;         deciNumber /= 8;         octalnumber += remainder * i;         i *= 10;     }      printf("%d in decimal = %d in octal", originalnumber, octalnumber);    return 0; } Output: Enter a decimal number: 60 60 in decimal = 74 in octal

C program to convert decimal to binary number

 In this example, we will learn how to convert decimal to binary number system in a c programming language. Following is the solution to the problem. Code: #include <math.h> #include <stdio.h> int main() {     int num,original;     printf("Enter a decimal number: ");     scanf("%d", &num);     original=num;      long long binary = 0;     int remainder, i = 1;     while (num != 0) {         remainder = num % 2;         num /= 2;         binary += remainder * i;         i *= 10;     }     printf("%d in decimal = %lld in binary", original, binary);     return 0;    } Output: Enter a decimal number: 15 15 in decimal = 1111 in binary

C Program to convert binary to decimal number

 In this example, we will learn how to convert the binary to decimal number in the c programming language. Following is the solution to the problem. code: #include <math.h> #include <stdio.h> int main() {     long long num,original;     printf("Enter a binary number: ");     scanf("%lld", &num);     original=num;          int deci = 0, i = 0, remainder;     while (num != 0) {         remainder = num % 10;         num /= 10;         deci += remainder * pow(2, i);         ++i;     }     printf("%lld in binary = %d in decimal", original, deci);     return 0; } Output: Enter a binary number: 111 111 in binary = 7 in decimal