: I'm trying to solve this problem in chapter 1 of a C programming book. I want this program to read in 5 integers then determine and print the largest and smallest. My problem is I don't want it to print everything just the smallest and largest values. Is my comparison of the integers correct?
:
:
:
: #include <stdio.h>
: #include <stdlib.h>
:
: int main()
: {
: int a,b,c,d,e;
:
: printf("enter your five numbers and I'll tell you something\n");
: scanf("%d%d%d%d%d", &a,&b,&c,&d,&e);
:
: /* if(a>b)
: printf("%d\n",a);
:
: if(a>c)
: printf("%d\n",a);
:
: */
: if(a>b,c,d,e)
: {
: printf("%d\n",a);
: }
: if(a<b,c,d,e)
: {
: printf("%d\n",a);
: }
: if(b>a,c,d,e)
: {
: printf("%d\n",b);
: }
: if(b<a,c,d,e);
: {
: printf("%d\n",b);
: }
: if(c>a,b,d,e);
: {
: printf("%d\n",c);
: }
: if(c<a,b,d,e)
: {
: printf("%d\n",c);
: }
: if(d>a,b,c,e)
: {
: printf("%d\n",d);
: }
: if(d<a,b,c,e)
: {
: printf("%d\n",d);
: }
: if(e>a,b,c,d)
: {
: printf("%d\n",e);
: }
: if(e<a,b,c,d)
: {
: printf("%d\n\n",e);
: }
:
:
HI friend ,
there is some prob with ur code.
when u compare a>b,c,d,e
this comparision is eqvlent to a>e. this due to comma(,) operator in C.
Read K&RC or some othr book for details abt comma operator.
I wud probably send u soln to this tomrw.