Well.. I'm not sure if we have to consider negative numbers..fR0D wrote:do we hav to consider negative numbers???if yes wat will be the result of -20 + -20.
But my output for the input "-20 + -20" is..
1111111100000 + 1111111100000 = -64
Moderator: Board moderators
Well.. I'm not sure if we have to consider negative numbers..fR0D wrote:do we hav to consider negative numbers???if yes wat will be the result of -20 + -20.
Code: Select all
#include<iostream>
using namespace std;
#include<math.h>
int main()
{
char h1[4],h2[4],t[1];
char con[16][5]={"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
int val[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},d1,d2,N,i,j,k,l1,l2;
scanf("%d",&N);
for (i=0;i<N;i++)
{
d1=0,d2=0;
scanf("%s%s%s",&h1,&t,&h2);
printf("0");
for (j=3;j>strlen(h1);j--)
printf("%s",con[0]);
l1=strlen(h1);
for (k=0;k<l1;k++,j--)
{
if (isdigit(h1[k]))
{
printf("%s",con[h1[k]-48]);
d1+=(int)pow(16,j-1)*val[h1[k]-48];
}
else
{
printf("%s",con[h1[k]-55]);
d1+=(int)pow(16,j-1)*val[h1[k]-55];
}
}
printf(" %c ",t[0]=='+'?'+':'-');
printf("0");
for (j=3;j>strlen(h2);j--)
printf("%s",con[0]);
l2=strlen(h2);
for (k=0;k<l2;k++,j--)
{
if (isdigit(h2[k]))
{
printf("%s",con[h2[k]-48]);
d2+=(int)pow(16,j-1)*val[h2[k]-48];
}
else
{
printf("%s",con[h2[k]-55]);
d2+=(int)pow(16,j-1)*val[h2[k]-55];
}
}
printf(" = %d\n",t[0]=='+'?d1+d2:d1-d2);
}
}
check <math.h> will it be <cmath>??
Nope. My AC program didn't. There's subtraction of two positive integers but nothing likefR0D wrote:do we hav to consider negative numbers???
Code: Select all
-FA + -40
(1) ChangefR0D wrote:can u pls point wats wrong with my program???
it gives run time error.
Code: Select all
scanf("%s%s%s",&h1,&t,&h2);
Code: Select all
scanf("%s%s%s",h1,t,h2);
Your code doesn't match the sample input / output.Ivo Sluganovic wrote:I am trying to solve the Kibbles ``n'' Bits ``n'' Bits ``n'' Bits problem.
It seems like a very easy problem, and it is, but I keep getting WA.
I coded it several times...
Please help me if you see any mistake...
I don't know what could be wrong in such short code.