Advertisement
itchydani3l

Maximum.c

Jul 19th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. // Daniel's written-from-scratch Maximum C program!
  3. // Part of Test 2, Enjoy!
  4. int vfind;
  5. void main(int argc, char *argv[])
  6. {
  7. printf("How many numbers to input? ");
  8. scanf("%d",&vfind);
  9. printf("Enter numbers in any order:\n");
  10. int nlist[vfind];
  11. int index=0;
  12. while(index<vfind)
  13. {
  14. scanf("%d",&nlist[index]);
  15. index++;
  16. //Get the numbers
  17. }
  18. int i;
  19. int j;
  20. int maxind;
  21. for(i=0;i<3;i++)
  22. {
  23. for(j=0;j<vfind;j++)
  24. {
  25. if (nlist[maxind]<nlist[j])
  26. {
  27. maxind=j;
  28. }
  29. }
  30. if (i<2) nlist[maxind]=-1000000; // I would ideally find a better way to exclude max 2, but I'm short on time.
  31. }
  32. printf("3rd Maximum Value:\n%d",nlist[maxind]);
  33. printf("\n");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement