difference of two no's with out using - operator
Answers were Sorted based on User's Feedback
Answer / arpit
void count()
{
int c=0;
for(i=a;i<=b;i++)
{
c++;
}
return(c);
}
c=b-a :...easy and best .....
| Is This Answer Correct ? | 10 Yes | 5 No |
Answer / gg
Try this....
main()
{
int a,b;
printf("Enter two integers \n");
scanf("%d%d",&a,&b);
printf("The diff is : %d ",a+(~b+1));
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / supri
see subtraction itself is the addition of the number with
its 2's complement....
add(int a,int b)
{
if(!a)
return b;
else
return(add((a&b)<<1,a^b));
}
main()
{
int a,b;
scanf("%d%d",&a,&b);
b=add(~b,1);
printf("%d",add(a,b));
return;
}
u can try this...
| Is This Answer Correct ? | 2 Yes | 1 No |
#include<stdio.h>
#include<conio.h>
//To calculate a-b
void main()
{
int a,b,min,max;
printf("Enter the value of a and b \n");
scanf("%d %d",&a,&b);
min = (a<b)?a:b;
max = (a>b)?a:b;
while(min--) max--;
if(a<b)
printf("-%d",max);
else
printf("%d",max);
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sandeep
int count(int a , int b)
{
int c=0;
if(a<b)
for(i=a;i<=b;i++)
{
c++;
}
else
for(i=b;i<=a;i++)
{
c++;
}
return(c); }
www.NSITFORUM.co.cc
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / dally
#include<stdio.h>
int main()
{
int a=9,b=4;
if(a>b)
{
while(a--)
b = b--;
}
else
printf("Difference is not possible\n") ;
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / vignesh1988i
its simple logic , wat i think is to AND these two inputs.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,m;
scanf("%d %d",&m,&n);
if(m>n)
printf("%d",m&n);
else
printf("%d",n&m);
getch();
}
thank u
| Is This Answer Correct ? | 1 Yes | 10 No |
Explain what is the benefit of using #define to declare a constant?
What is difference between constant pointer and constant variable?
Look at the Code: #include<string.h> void main() { char s1[]="abcd"; char s2[10]; char s3[]="efgh"; int i; clrscr(); i=strcmp(strcat(s3,ctrcpy(s2,s1))strcat(s3,"abcd")); printf("%d",i); } What will be the output? A)No output B) A Non Integer C)0 D) Garbage
Why is c platform dependent?
What is 1d array in c?
main() { int i; printf("%d", &i)+1; scanf("%d", i)-1; }
please give me some tips for the selection in TCS.
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
How to run c Program without using IDE of c. means if program made in notepad.then how to compile by command prompt.
write a program to find the given number is prime or not
2 Answers Accenture, Vasutech,
What are disadvantages of C language.
How can you read a directory in a C program?