Tuesday 12 September 2017

Decimal to binary

Convert a number to its binary.

Copy the code and paste it in here

#include <iostream>
#include<conio.h>
using namespace std;
void main()
{
int q, r, a, b[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
int i = 0;
cout << "\nEnter a number between -32768 and 32767....";
cin >> a;
if (a>0)
{
q = a;
}
else
{
q = -a;
b[15] = 1;
}
cout << "\nBinary in 16-bit format ";
for (i = 0; q != 1; i++)
{
r = q % 2;
b[i] = r;
q /= 2;
}
b[i] = 1;
for (int j = 0; j<16; j++)
{
if (j % 4 == 0)
cout << " ";
cout << b[15 - j];
}
_getch();
}

Comment below.





Monday 11 September 2017

Doraemon

Do you need to see Doraemon? Try the code below.

#include "graphics.h"
#include <iostream>
using namespace std;
void main()
{
initwindow(800, 800, "Doraemon");
int x = 800, y = 800;
circle(x / 2, y / 2 - 20, 5);//nose
line(x / 2, y / 2 - 20 + 5, x / 2, y / 2);//nose
line(x / 2 - 20, y / 2, x / 2 + 20, y / 2);//mouth
arc(x / 2, y / 2, 180, 360, 20);//mouth
arc(x / 2, y / 2 + 20, 30, 150, 10);//toungue
ellipse(x / 2 - 10, y / 2 - 35, 0, 360, 8, 15);//left eye
ellipse(x / 2 - 10, y / 2 - 35, 0, 360, 2, 5);//left eye;//left eye dot
ellipse(x / 2 + 10, y / 2 - 35, 0, 360, 8, 15);//right eye
ellipse(x / 2 + 10, y / 2 - 35, 0, 360, 2, 5);//right eye dot
arc(x / 2, y / 2 - 10, 110, 250, 40);//left curve
arc(x / 2, y / 2 - 10, 290, 70, 40);//right curve
line(x / 2 - 15, y / 2 + 29, x / 2 + 15, y / 2 + 29);//line joining two curve
arc(x / 2, y / 2 - 20, 90, 270, 50);//left head
arc(x / 2, y / 2 - 20, 270, 90, 50);//right head
line(x / 2 - 20, y / 2 - 20, x / 2 - 45, y / 2 - 30);//left moustache
line(x / 2 - 20, y / 2 - 10, x / 2 - 45, y / 2 - 10);//left moustache
line(x / 2 - 20, y / 2, x / 2 - 45, y / 2 + 10);//left moustache
line(x / 2 + 20, y / 2 - 20, x / 2 + 45, y / 2 - 30);//right moustache
line(x / 2 + 20, y / 2 - 10, x / 2 + 45, y / 2 - 10);//right moustache
line(x / 2 + 20, y / 2, x / 2 + 45, y / 2 + 10);//right moustache
//body
arc(x / 2 - 15, y / 2 + 70, 90, 200, 40);//left hand arc
arc(x / 2 + 15, y / 2 + 70, 340, 90, 40);//right hand arc
circle(x / 2 - 42, y / 2 + 80, 10);//left hand palm
circle(x / 2 + 42, y / 2 + 80, 10);//right hand palm
ellipse(x / 2 - 20, y / 2 + 65, 90, 250, 15, 40);//left body
ellipse(x / 2 + 20, y / 2 + 65, 290, 90, 15, 40);//right body
ellipse(x / 2 - 20, y / 2 + 110, 0, 360, 20, 10);//left shoe
ellipse(x / 2 + 20, y / 2 + 110, 0, 360, 20, 10);//right shoe
arc(x / 2, y / 2 + 60, 180, 360, 20);//pocket
line(x / 2 - 20, y / 2 + 60, x / 2 + 20, y / 2 + 60);//pocket
circle(x / 2, y / 2 + 39, 10);//bell
arc(x / 2, y / 2 + 70, 180, 360, 25);//curve between body and pocket
ellipse(x / 2 - 5, y / 2 + 60, 100, 200, 20, 30);//curve between body and pocket
ellipse(x / 2 + 5, y / 2 + 60, 340, 100, 20, 30);//curve between body and pocket

getch();
}



The output will be


 Comment your views below. Ask any other characters.

Sunday 10 September 2017

Calculator

This is my Calculator program. In this program you can enter the entire expression instead of only 2 numbers.Try it and comment below.




#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int a,b;
char c;
system("cls");
cout << "Enter the expression....";
cout << "\nPress '= 'after entering expression....";
cin >> a;
do
{
cin >> c;
switch (c)
{
case '+':cin >> b; a += b; break;
case '-':cin >> b; a -= b; break;
case '*':cin >> b; a *= b; break;
case '/':cin >> b; a /= b; break;
}
} while (c != '=');
cout << a;
_getch();
}