Translate

Ad-Horizontal

Search This Blog

Friday 29 March 2019

How to write a C++ program (Turbo C++) to input a Decimal Number and find it's equivalent Binary Number.

We are gonna see how to write a C++ program (Turbo C++) to input a Decimal Number and find it's equivalent Binary Number.

The following codes have been run and compiled in C++(Turbo C++).


The writing in the right-hand side of this "//" in the codes are called comments of the code. They are not a necessary part of the codes and can be omitted in the codes. They are just mentioned so as to tell you the use/purpose of writing the left-hand side of the "//" or the codes.   In some special cases depending upon the Fond & Size of the text on your device the comments may entered the right hand-side of the "//"(next line) and come in between the main codes. so as to, make it easier for you to understand/distinguish the comments from the main codes; we have written the main code and comments in different sizes.
Example: Main codes: "  #include<iostream.h>  "
                 Comments: "   //It is a header file and used to call the input-output classes(Pre-defined library in C++).  " .


The Variables are user initialized with zero, so that they won't store any garbage value and hamper the final output of the program.

For more accurate result, users may replace "int" and "float" with "long" and "double" respectively.




The code are as follows:


#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int dec_num=0,bin_num=0,rem=0,i=0;
cout<<"Enter the decimal number:"<<"\n";
cin>>dec_num;
while(dec_num!=0)
{
rem=dec_num%2;
bin_num=bin_num+rem*pow(10,i);
dec_num=dec_num/2;
i++;
}
cout<<"The Binary equivalent of the Decimal Number,"<<dec_num<<" is = "<<bin_num<<"\n";
getch();
}


Program:


Code



Output:


Result



Result



Result





Hope that the Blog have helped you in your work. 


Do visit again to see more Coding related blogs.

Saturday 23 March 2019

How to write a C++ program (Turbo C++) to input a number and check whether it is a perfect number or not.

We are gonna see how to write a C++ program (Turbo C++) to input a number and check whether it is a perfect number or not.

The following codes have been run and compiled in C++(Turbo C++).


The writing in the right-hand side of this "//" in the codes are called comments of the code. They are not a necessary part of the codes and can be omitted in the codes. They are just mentioned so as to tell you the use/purpose of writing the left-hand side of the "//" or the codes.   In some special cases depending upon the Fond & Size of the text on your device the comments may entered the right hand-side of the "//"(next line) and come in between the main codes. so as to, make it easier for you to understand/distinguish the comments from the main codes; we have written the main code and comments in different sizes.
Example: Main codes: "  #include<iostream.h>  "
                 Comments: "   //It is a header file and used to call the input-output classes(Pre-defined library in C++).  " .


The Variables are user initialized with zero, so that they won't store any garbage value and hamper the final output of the program.

For more accurate result, users may replace "int" and "float" with "long" and "double" respectively.




The code are as follows:


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num=0,sun=0,i=0;
cout<<"Enter the number:"<<"\n";
cin>>num;
for(i=0;i<num;i++)
{
if(num%i==0)
{
sum=sum+i;
}
}
if(sum==num)
{
cout<<"The number,"<<num<<" is a Perfect number."<"\n";
}
else
cout<<"The number,"<<num<<" is not a Perfect number."<"\n";
getch();
}


Program:


Code


Code


Code




Output:


The Output pictures will soon be available




Hope that the Blog have helped you in your work. 


Do visit again to see more Coding related blogs.