Advertisement
Guest User

project 7

a guest
Dec 12th, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.74 KB | None | 0 0
  1. /**
  2.  *Program Name :
  3.  *Written By :
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. void DisplayClassInfo(void);
  10. void DisplayProgramMenu(void);
  11. int extractLargestDigitOccurrence();
  12. int countDigits();
  13.  
  14. int main() {
  15.  
  16.     DisplayClassInfo();
  17.    
  18.     DisplayProgramMenu();
  19.  
  20.     return 0;
  21. }
  22.  
  23. void DisplayClassInfo() {
  24.     printf("CIS 26 - C Programming\n");
  25.     printf("\n");
  26.     printf("\n");
  27.     printf("\n");
  28.     printf("\n");
  29.     printf("Assignment Information --\n");
  30.     printf("  Assignment Number:  Lab 07\n");
  31.     printf("                      Coding Assignment -- Exercise 1\n");
  32.     printf("  Written By:         \n");
  33.     printf("  Submitted Date:     December 11, 2011\n");
  34.     printf("\n");
  35.    return;
  36.  }
  37.  
  38. void DisplayProgramMenu(){
  39.  
  40. int MenuOption;
  41. do
  42. {
  43. printf("\n******************************************************\n");
  44. printf("*                         MENU                       *\n");
  45. printf("* 1) Calling extractLargestDigitOccurrenceYourname() *\n");
  46. printf("* 2) Quit                                            *\n");
  47. printf("******************************************************\n");
  48. printf("Enter your option (1 or 2) : ");
  49. scanf("%d", &MenuOption);
  50.  
  51. switch (MenuOption) {
  52.             case 1:
  53.                 extractLargestDigitOccurrence();
  54.                 break;
  55.             case 2:
  56.                
  57.                
  58.                 break;
  59.  
  60.             default:
  61.                 printf("\n    WRONG OPTION!\n\n");
  62. }
  63. } while (MenuOption != 2);
  64.     printf("\n  Have fun ...\n");    
  65.  
  66.    
  67. return;
  68. }
  69.  
  70.  
  71. int countDigits(int X) {
  72.     int NumDigits = 0;
  73.  
  74.    
  75.     do {
  76.         ++NumDigits;
  77.         X /= 10;
  78.     } while (X);
  79.  
  80.    
  81.     return NumDigits;
  82. }
  83.  
  84.  
  85. int extractLargestDigitOccurrence() {
  86.     int I, x, Length, Number = 0, Digit, numofInts = 0, count;
  87.     int LargestDigit = 0, Position, Divisor = 1, size;
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.     printf("\n  Calling extractLargestDigit() - \n");
  95.     printf("How many integers (must be greater than 1)? ");
  96.     scanf("%d", &numofInts);
  97.  
  98.         /**int *px = NULL;
  99.    
  100.     px = (int*) malloc(numofInts*sizeof(int));
  101.     *px = (numofInts + 1);
  102.     */
  103.  
  104.     // attempting to use malloc but have no clue what im doing here
  105.  
  106.  
  107.     for (count = 0; count < numofInts; count++)
  108.  
  109.     {
  110.     printf("    Enter an integer: ");
  111.     scanf("%d", &Number);
  112.     }
  113.    
  114.     if (Number < 0)
  115.         Number *= -1;
  116.  
  117.    
  118.     Length = countDigits(Number);
  119.  
  120.  
  121.     for (I = 1; I < Length + 1; I++) {
  122.         Digit = (Number / Divisor) % 10;
  123.         Divisor *= 10;
  124.         if (Digit > LargestDigit) {
  125.             LargestDigit = Digit;
  126.             Position = I;
  127.         }
  128.     }
  129.     printf("    The largest digit : %d\n", LargestDigit);
  130.  
  131.  
  132.     printf("    Its position : %d\n", Position);
  133.  
  134.     return LargestDigit;
  135. free (px);
  136. px = NULL;
  137. }
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement