Saturday, April 11, 2009

Plays a one-time guessing game with user.User enters a number which is compared with target

/*Plays a one-time guessing game with the user.The user enters a number,which is compared with TARGET.The computer issues a diagnostic message & then the correct result*/

Solution Code:-
=========


#include <stdio.h>
#define TARGET 17
int test(int i,int target);
int main(void)

{
int i;
printf("Enter target number : ");
scanf("%d",&i);
test( i,TARGET);
return 0;
}

void test(int i,int target)
{
if ( i > target)
printf("\nTarget number is smaller than %d,try again",i);
else if ( i < target)
printf("\nTarget number is greater than %d,try again",i);
else if ( i == target )
printf("\nFinally you could make it");

}

No comments: