//Roman numbers to decimal conversion ,c++ program
#include<iostream.h>
#include<process.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
int s=0,beg=0,k,end=k,i,c=0,mid,m[50],p,j;
char a[50];
clrscr();
cout<<"ENTER THE ROMAN NUMBER\n";
gets(a);
k=strlen(a);
for(i=0;i<k;i++)
{
switch(a[i])
{
case 'I':
p=1;
m[i]=p;
c++;
break;
case 'V':
p= 5;
m[i]=p;
c++;
break;
case 'X':
p=10;
m[i]=p;
c++;
break;
case 'L':
p=50;
m[i]=p;
c++;
break;
case 'C':
p=100;
m[i]=p;
c++;
break;
case 'D':
p=500;
m[i]=p;
c++;
break;
case 'M':
p=1000;
m[i]=p;
c++;
break;
default:cout<<"sorry INVALID\n";
getch();
exit(0);
}
}
for(i=0;i<k;i++)
{
while(beg<end)
{
mid=(end+beg)/2;
end=mid;
if(beg==end)
{
s=s+m[beg];
beg=beg+1;
end=k;
}
else if((end-beg)==1)
{
if(m[end]>m[beg])
{
s=s+(m[end]-m[beg]);
beg=end+1;
end=k;
}
}
}
}
cout<<"Decimal value "<<s;
getch();
}
Saturday, March 16, 2013
number guesser program in c.
Guess a number sequence using the limit (1,6) ,the program will guess the number within 8 steps
you must provide(input) 1. how many terms are in the exact position (first input)
2.how many terms are misplaced (second input)
try example 1443(i am guessing this..)
guesser output chooser output
1111 1 0
2221 0 1
3313 1 1
4143 2 2
1443 4 0
got it......!!!!
#include<conio.h> // number guesser program in c.
#include<process.h>
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i,j,n=2,r,p=2,q,t=4,a[4]={1,1,1,1},c,d,k=3,z,m=0;
clrscr();
z=a[k];
while(1)
{
for(i=0;i<4;i++)
{
printf("%d",a[i]);
}
scanf("%d",&c);
scanf("%d",&d);
if(c==4)
{
printf("Got it !!!\n");
break;
}
else if((c==0)&&(d==0))
{
printf("hai 1\n");
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;
}
else if((c+d)==1)
{
printf("hai 3\n");
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;a[k]=z;k--;
if(k==0)
{
m++;
}
}
else if((c==1)&&(d==1))
{
printf("hai 4\n");
t--;
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;
a[k]=z;
k--;
if(k==0)
{
m++;
}
}
else if((c==1)&&(d==2))
{
printf("hai 5\n");
t--;
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;a[k]=z;k--;
if(k==0)
{
m++;
}
}
else if((c+d)==3)
{
printf("hai 10\n");
t--;
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;a[k]=z;k--;
if(k==0)
{
m++;
}
}
else if((c==2)&&(d==2))
{
printf("hai 6\n");
t=t-2;
for(i=0;i<t;i++)
{
r=a[i];
a[i]=a[i+1];
a[i+1]=r;
}
}
else if((c+d)==4)
{
printf("hai 8\n");
t=t-2;
for(i=0;i<t;i++)
{
r=a[i];
a[i]=a[i+1];
a[i+1]=r;
}
}
}
getch();
}
you must provide(input) 1. how many terms are in the exact position (first input)
2.how many terms are misplaced (second input)
try example 1443(i am guessing this..)
guesser output chooser output
1111 1 0
2221 0 1
3313 1 1
4143 2 2
1443 4 0
got it......!!!!
#include<conio.h> // number guesser program in c.
#include<process.h>
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i,j,n=2,r,p=2,q,t=4,a[4]={1,1,1,1},c,d,k=3,z,m=0;
clrscr();
z=a[k];
while(1)
{
for(i=0;i<4;i++)
{
printf("%d",a[i]);
}
scanf("%d",&c);
scanf("%d",&d);
if(c==4)
{
printf("Got it !!!\n");
break;
}
else if((c==0)&&(d==0))
{
printf("hai 1\n");
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;
}
else if((c+d)==1)
{
printf("hai 3\n");
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;a[k]=z;k--;
if(k==0)
{
m++;
}
}
else if((c==1)&&(d==1))
{
printf("hai 4\n");
t--;
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;
a[k]=z;
k--;
if(k==0)
{
m++;
}
}
else if((c==1)&&(d==2))
{
printf("hai 5\n");
t--;
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;a[k]=z;k--;
if(k==0)
{
m++;
}
}
else if((c+d)==3)
{
printf("hai 10\n");
t--;
for(i=m;i<t;i++)
{
a[i]=p;
}
p++;a[k]=z;k--;
if(k==0)
{
m++;
}
}
else if((c==2)&&(d==2))
{
printf("hai 6\n");
t=t-2;
for(i=0;i<t;i++)
{
r=a[i];
a[i]=a[i+1];
a[i+1]=r;
}
}
else if((c+d)==4)
{
printf("hai 8\n");
t=t-2;
for(i=0;i<t;i++)
{
r=a[i];
a[i]=a[i+1];
a[i+1]=r;
}
}
}
getch();
}
Subscribe to:
Posts (Atom)