[ create a new paste ] login | about

Link: http://codepad.org/WlXTVI7s    [ raw code | output | fork ]

baojie - C, pasted on Jun 18:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Compare two integers without using any comparative operators

#include <stdio.h>

//return 1 if n1==n2, otherwise return 0
int compare(int n1, int n2){
	int t = n1 - n2;
	return !t;	
}

main()
{
	printf("5 and 6: "); 
	compare(5,6)?printf("equal\n"):printf("not equal\n");
	printf("5 and 5: "); 
	compare(5,5)?printf("equal\n"):printf("not equal\n");
	return 1;
}


Output:
1
2
5 and 6: not equal
5 and 5: equal


Create a new paste based on this one


Comments: