Help me right a C code for a logic statement

Status
Not open for further replies.

alangs

Member level 3
Joined
Feb 5, 2010
Messages
57
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
india
Activity points
1,681
the input are as follow 1,12,23,34,45,56,67,78,89. If i got any one of this input then i need to add a number with 571. If not the input is different other than the given numbers then i need to add the number with 572. sombody can tell me solution for this in c without using if loop and switch case statement.
 

Re: need help in logic

you may check the following code

Code:
int Add_Numbers(int input_number){
	float mod_value = 0;
	int return_value = 0;
	mod_value = (input_number+11-1)%11; //get modulo value
	if(mod_value==0){
		return_value = input_number+571;
	}
	else {
		return_value = input_number+572;
	}

	return return_value;
}

hope your comments

regards
bassa
 

Re: need help in logic

I love single-line code

Code:
unsigned int test(unsigned int n){
    return n + 571 + (n % 11 != 1)  ;
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…