ccplusplus.com
Learn C, C++ Concepts
Sunday, September 11, 2011
check number is positive negative or smaller in c
/****************************************************** * File : check-number-is-positive-negative-or-smaller.c * Author : Saurabh Gupta * Desc : checking from a given numbers which number * is smaller greater and minimum etc * Source : http://saurabhgupta0527.blogspot.com/ * Created : PM 07:05 11 September 2011 * Note : *****************************************************/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> int main() { int count=0; float value, high, low, sum=0, average, range; printf ("-------------------------------------------------------------------\n"); printf("Enter numbers in a line: input a NEGATIVE number to end, for example\n"); printf ("12 4 777 123 32 1 0 99 -56\n"); printf ("-------------------------------------------------------------------\n"); input: scanf("%f",&value); if(value<0) { goto output; } count+=1; if(count==1) { high=low=value; } else if(value>high) { high=value; } else if(value<=low) { low=value; } sum += value; goto input; output: average=sum/count; range = high-low; printf("\n\n"); printf("Total values: %d\n", count); printf("Highest-value: %f\n Lowest-value: %f\n", high, low); printf("Range : %f\nAverage : %f\n", range, average); return 0; } /* * OUTPUT * [sgupta@rhel54x64 c]$ gcc -o check-number-is-positive-negative-or-smaller check-number-is-positive-negative-or-smaller.c [sgupta@rhel54x64 c]$ ./check-number-is-positive-negative-or-smaller ------------------------------------------------------------------- Enter numbers in a line: input a NEGATIVE number to end, for example 12 4 777 123 32 1 0 99 -56 ------------------------------------------------------------------- 22 4 1 0 8 -9 Total values: 5 Highest-value: 22.000000 Lowest-value: 0.000000 Range : 22.000000 Average : 7.000000 [sgupta@rhel54x64 c]$ */
See also
Other popular tricky C Sample Codes and language Concept
.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment