Anda di halaman 1dari 5

#include <iostream.

h>
#include <conio.h>
include <stdio.h>

main ()

int account no;


char name [30] , deposit , withdraw;

cout<< “

decimal to binary

#include <iostream.h>

void binary(int);

void main(void) {
int number;

cout << "Please enter a positive integer: ";


cin >> number;
if (number < 0)
cout << "That is not a positive integer.\n";
else {
cout << number << " converted to binary is: ";
binary(number);
cout << endl;
}
}

void binary(int number) {


int remainder;

if(number <= 1) {
cout << number;
return;
}

remainder = number%2;
binary(number >> 1);
cout << remainder;

1. #include<iostream.h>
2. #include<conio.h>
3. void main()
4. {
5. clrscr();
6. unsigned long int y,i=0,j=0,r,k[50];
7. unsigned long a,x,b[50];
8. cout<<"\nEnter a decimal no. ";
9. cin>>a;
10. y=a;
11. x=a-y;
12. while(y>0)
13. {
14. r=y%2;
15. k[i]=r;
16. i++;
17. y=y/2;
18. }
19. int m=0;
20. while(m<10)
21. {
22. x=x*2;
23. b[j]=int(x);
24. j++;
25. m++;
26. if(x>1)
27. x=x-1;
28. else
29. if(x==0)
30. break;
31. }
32. cout<<"\nDecimal no. "<<a<<" = ";
33. if(a>1)
34. {
35. for(int e=i-1;e>=0;e--)
36. cout<<k[e];
37. cout<<".";
38. for(int g=0;g<m;g++)
39. cout<<b[g];
40. }
41. else
42. {
43. cout<<"0.";
44. for(int f=0;f<m;f++)
45. cout<<b[f];
46. }
47. cout<<" in binary no. system";
48. getch();
49. }

This following program converts a decimal number to a binary number.


To convert a decimal number into binary,we follow the following steps:
Divide the decimal number by 2 and note the remainder
Divide the Quotient repeatedly by 2 and note the remainders till quotient is 0
Write remainder side by side in reverse order to know the binary number
For example 18
18 divide by 2 leaves quotient 9 remainder 0
9 divide by 2 leaves quotient 4 remainder 1
4 divide by 2 leaves quotient 2 remainder 0
2 divide by 2 leaves quotient 1 remainder 0
1 divide by 2 leaves quotient 0 remainder 1

So binary of 18 is 10010

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <conio .h>
using namespace std;
void main()
{
int dec,rem,i=1,sum=0;
cout< <"Enter the decimal to be converted:"<<endl;
cin>>dec;
do
{
rem=dec%2;
sum=sum + (i*rem);
dec=dec/2;
i=i*10;
}while(dec>0);
cout< <"The binary of the given number is:"<<sum<<endl;
getch();
}

#include<stdio.h>
#include<conio.h>
#include<iostream.h>

void main ()

int choice, a , var;


char deposit[20], withdraw[30],name[20];
cout<< “your complete name”<<endl;
cin>>name;
cout<<”cout<<"(1) DEPOSITE MONEY"<<endl;
cout<<"(2) WITHDRAW MONEY"<<endl;
cout<<"(3) FIND THE ACCOUNT BALANCE"<<endl;
switch (choice)
{
case 1:
deposite(); /*to deposite money*/

break;

case 2:
withdraw(); /*to withdraw money*/

break;

case 3: /*to see the balance*/


cout<<endl<<"This facility is not currently available"<<endl;
break;

default: /*if choice is not valid*/

cout<<"ERROR// PLEASE TRY AGAIN";


}
cout<<” Enter the amount of money to be deposited”<<endl;
cin>>money”; /*read the amount to be deposited*/
if(var>0)
cout<<”money"<<endl;
cin<< has been deposited in your account"<<endl;
}
else
cout<<"Please enter valid amount......."<<endl;
}
continue
void withdraw()
{
long int rem,f,t,e;
long int mon;
cout<<"Enter the amount of money to be withdrawn: ";
cin>>mon; /*read the amount to be withdrawn*/

if(mon>=20)
{
if(mon!=30)
{
f=mon/50; /*decides the notes of $50*/
rem=mon%50;
if(rem!=20)
{
if (rem==10||rem==30)
{
f-=1;
rem+=50;
}
}
t=rem/20; /*decides the notes of $20*/
e=rem%20;
if(e==0)
{
cout<<endl<<"Nos. of 50$ note : "<<f;
cout<<endl;
cout<<"Nos. of 20$ note : "<<t<<endl;
cout<<"TOTAL AMOUNT : "<<mon<<endl;
}
else
cout<<endl<<"This amount is not possible... Please try again"<<endl;
}
else /*if amount is not possible*/
{
cout<<endl;
cout<<"This amount is not possible... Please try again"<<endl;
}
}
else
{
cout<<endl;
cout<<"This amount is not possible... Please try again"<<endl;
}

Anda mungkin juga menyukai