Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *Program Name :
- *Written By :
- */
- #include <stdio.h>
- #include <stdlib.h>
- void DisplayClassInfo(void);
- void DisplayProgramMenu(void);
- int extractLargestDigitOccurrence();
- int countDigits();
- int main() {
- DisplayClassInfo();
- DisplayProgramMenu();
- return 0;
- }
- void DisplayClassInfo() {
- printf("CIS 26 - C Programming\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("Assignment Information --\n");
- printf(" Assignment Number: Lab 07\n");
- printf(" Coding Assignment -- Exercise 1\n");
- printf(" Written By: \n");
- printf(" Submitted Date: December 11, 2011\n");
- printf("\n");
- return;
- }
- void DisplayProgramMenu(){
- int MenuOption;
- do
- {
- printf("\n******************************************************\n");
- printf("* MENU *\n");
- printf("* 1) Calling extractLargestDigitOccurrenceYourname() *\n");
- printf("* 2) Quit *\n");
- printf("******************************************************\n");
- printf("Enter your option (1 or 2) : ");
- scanf("%d", &MenuOption);
- switch (MenuOption) {
- case 1:
- extractLargestDigitOccurrence();
- break;
- case 2:
- break;
- default:
- printf("\n WRONG OPTION!\n\n");
- }
- } while (MenuOption != 2);
- printf("\n Have fun ...\n");
- return;
- }
- int countDigits(int X) {
- int NumDigits = 0;
- do {
- ++NumDigits;
- X /= 10;
- } while (X);
- return NumDigits;
- }
- int extractLargestDigitOccurrence() {
- int I, x, Length, Number = 0, Digit, numofInts = 0, count;
- int LargestDigit = 0, Position, Divisor = 1, size;
- printf("\n Calling extractLargestDigit() - \n");
- printf("How many integers (must be greater than 1)? ");
- scanf("%d", &numofInts);
- /**int *px = NULL;
- px = (int*) malloc(numofInts*sizeof(int));
- *px = (numofInts + 1);
- */
- // attempting to use malloc but have no clue what im doing here
- for (count = 0; count < numofInts; count++)
- {
- printf(" Enter an integer: ");
- scanf("%d", &Number);
- }
- if (Number < 0)
- Number *= -1;
- Length = countDigits(Number);
- for (I = 1; I < Length + 1; I++) {
- Digit = (Number / Divisor) % 10;
- Divisor *= 10;
- if (Digit > LargestDigit) {
- LargestDigit = Digit;
- Position = I;
- }
- }
- printf(" The largest digit : %d\n", LargestDigit);
- printf(" Its position : %d\n", Position);
- return LargestDigit;
- free (px);
- px = NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement