Saturday 30 April 2016

Integer to Roman Numerals program in C programming language

Using Code::Blocks  (cross-platform IDE):-


//Algorithm by Dharmendra Agrawal to convert integer to roman number
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void upto9(void);
void upto99(void);
void fun100to399(void);
void fun400to899(void);
void upto999(void);

int i,x;  //global data
int main()
{
do
{
system("cls");

printf("Enter any number: ");
scanf("%d",&i);
system("cls");
printf("\aRoman number of %d is: (",i);
if(i>1)
{
if(i>999)
{
for(x=1000;x<=i;x=x+1000)
printf("M");
i=i%1000;
}
upto999();
upto99();
upto9();
}
else
{
system("cls");
printf("(Invalid entry");
}
printf(")\n\nPress \"ESC\" to exit or any other key to continue");
}
while(getch()!=27);
return 0;
}
void upto9()
{
if(i>0&&i<4)
{
r123:
for(x=0;x<i;x++)
printf("I");
}
else if(i==4)
printf("I");
if(i>3&&i<9)
printf("V");
if(i>5&&i<9)
{
i=i-5;
goto r123;
}
if(i==9)
printf("IX");
}
void upto99()
{
if((i>-1&&i<40)||(i>49&&i<90))
{
if(i>49&&i<90)
{
printf("L");
i=i-50;
}
for(x=10;x<=i;x=x+10)
printf("X");
i=i%10;
}
else
{
if(i<50)
{
printf("XL");
i=i-40;
}
else
{
printf("XC");
i=i-90;
}
}
}
void fun100to399()
{
for(x=100;x<=i;x=x+100)
printf("C");
i=i%100;
}
void fun400to899()
{
if(i>499)
{
printf("D");
i=i-500;
fun100to399();
}
else
{
printf("CD");
i=i-400;
}
}
void upto999()
{
if(i>99&&i<400)
fun100to399();
else if(i>399&&i<900)
fun400to899();
else if(i>899)
{
printf("CM");
i=i-900;
}
}


Using Turbo C (A discontinued  C/C++ compiler):-


//Algorithm by Dharmendra Agrawal to convert integer to roman number

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

void upto9(void);
void upto99(void);
void fun100to399(void);
void fun400to899(void);
void upto999(void);

int i,x;  //global data
int main()
{
do
{
clrscr();
printf("Enter any number: ");
scanf("%d",&i);
clrscr();
printf("\aRoman number of %d is: (",i);
if(i>1)
{
if(i>999)
{
for(x=1000;x<=i;x=x+1000)
printf("M");
i=i%1000;
}
upto999();
upto99();
upto9();
}
else
{
clrscr();
printf("(Invalid entry");
}
printf(")\n\nPress \"ESC\" to exit or any other key to continue");
getch();
}
while(getch()!=27);
return 0;
}
void upto9()
{
if(i>0&&i<4)
{
r123:
for(x=0;x<i;x++)
printf("I");
}
else if(i==4)
printf("I");
if(i>3&&i<9)
printf("V");
if(i>5&&i<9)
{
i=i-5;
goto r123;
}
if(i==9)
printf("IX");
}
void upto99()
{
if((i>-1&&i<40)||(i>49&&i<90))
{
if(i>49&&i<90)
{
printf("L");
i=i-50;
}
for(x=10;x<=i;x=x+10)
printf("X");
i=i%10;
}
else
{
if(i<50)
{
printf("XL");
i=i-40;
}
else
{
printf("XC");
i=i-90;
}
}
}
void fun100to399()
{
for(x=100;x<=i;x=x+100)
printf("C");
i=i%100;
}
void fun400to899()
{
if(i>499)
{
printf("D");
i=i-500;
fun100to399();
}
else
{
printf("CD");
i=i-400;
}
}
void upto999()
{
if(i>99&&i<400)
fun100to399();
else if(i>399&&i<900)
fun400to899();
else if(i>899)
{
printf("CM");
i=i-900;
}
}


must watch:-
    

Monday 4 April 2016

Happy Birthday wish in programming (c++) style using a special code

Using DEV C++ compiler:-

#include<windows.h>
#include<iostream>
#include<stdlib.h> //for system("cls");
using namespace std;

int main()
{
int i;
char h=3;
system("cls");
system("color f5"); //f->white background, 5->purple text
cout<<"\t\t\tFrom: Dharmendra Agrawal\n";
Sleep(2000);
cout<<"\t\t\tTo  : Person's name\n\n";
Sleep(2000);
cout<<"\t\t";
for(i=0;i<42;i++)
cout<<"_";
cout<<"\n\n";
system("color f9"); //f->white background, 9->light blue text

Sleep(2000);
cout<<"\t\t\t\ti i i i i\n";

Sleep(2000);
cout<<"\t\t\t\ti i i i i\n";

Sleep(2000);
cout<<"\t\t\t      __i_i_i_i_i__\n";

Sleep(2000);
cout<<"\t\t\t     |"<<h<<"           "<<h<<"|\n";

Sleep(2000);
cout<<"\t\t\t   __| "<<h<<"  dd/mm  "<<h<<" |__\n";

Sleep(2000);
cout<<"\t\t\t  | "<<h<<"   "<<h<<"       "<<h<<"   "<<h<<" |\n";

Sleep(2000);
cout<<"\t\t\t__|"<<h<<"   HAPPY     "<<h<<"   "<<h<<"|__\n";

Sleep(2000);
cout<<"\t\t       | "<<h<<"   "<<h<<"     BIRTHDAY    "<<h<<" |\n";

Sleep(2000);
cout<<"\t\t       |"<<h<<"  "<<h<<"     "<<h<<"    "<<h<<"     "<<h<<"   "<<h<<"|\n";


Sleep(2000);
cout<<"\t\t       | "<<h<<" "<<h<<" "<<h<<" "<<h<<" N A M E "<<h<<" "<<h<<" "<<h<<" "<<h<<" |\n";

Sleep(2000);
cout<<"\t\t       |_________________________|\n";

cout<<"\n\n\n\n\n";
system("pause");
return 0;
}


Using TURBO C++ compiler:-

#include<iostream.h> //for I/O in dos based compiler's
#include<conio.h>
#include<dos.h> //for delay();

int main()
{
char h=3;
clrscr();
cout<<"\t\t\tFrom: Dharmendra Agrawal\n";
delay(2000);
cout<<"\t\t\tTo  : Person's name\n\n";
delay(2000);
cout<<"\t\t";
for(int i=0;i<42;i++)
cout<<"_";
cout<<"\n\n";

delay(2000);
cout<<"\t\t\t\ti i i i i\n";

delay(2000);
cout<<"\t\t\t\ti i i i i\n";

delay(2000);
cout<<"\t\t\t      __i_i_i_i_i__\n";

delay(2000);
cout<<"\t\t\t     |"<<h<<"           "<<h<<"|\n";

delay(2000);
cout<<"\t\t\t   __| "<<h<<"  dd/mm  "<<h<<" |__\n";

delay(2000);
cout<<"\t\t\t  | "<<h<<"   "<<h<<"       "<<h<<"   "<<h<<" |\n";

delay(2000);
cout<<"\t\t\t__|"<<h<<"   HAPPY     "<<h<<"   "<<h<<"|__\n";

delay(2000);
cout<<"\t\t       | "<<h<<"   "<<h<<"     BIRTHDAY    "<<h<<" |\n";

delay(2000);
cout<<"\t\t       |"<<h<<"  "<<h<<"     "<<h<<"    "<<h<<"     "<<h<<"   "<<h<<"|\n";


delay(2000);
cout<<"\t\t       | "<<h<<" "<<h<<" "<<h<<" "<<h<<" N A M E "<<h<<" "<<h<<" "<<h<<" "<<h<<" |\n";

delay(2000);
cout<<"\t\t       |_________________________|\n";

cout<<"\n\n\n\n\n";
getch();
return 0;
}



must watch:-




Adon: You can use my link to buy from two of the best wireless earphones under 2000 rupees which I personally recommend: