Solution for Exercise 19-20
ex1920
#include <stdio.h> int main() { char *fruit[] = { "apricot", "banana", "pineapple", "apple", "persimmon", "pear", "blueberry" }; char *temp; int a,b,x; for(a=0;a<6;a++) for(b=a+1;b<7;b++) if(*(fruit+a) > *(fruit+b)) { temp = *(fruit+a); *(fruit+a) = *(fruit+b); *(fruit+b) = temp; } for(x=0;x<7;x++) puts(fruit[x]); return(0); }
Output
apricot
banana
pineapple
apple
persimmon
pear
blueberry
Notes
* Is Line 19 how you compare strings in the C language?
Copyright © 1997-2024 by QPBC.
All rights reserved