Question

1. Write a function that converts a string into an int. Assume the int is between...

1. Write a function that converts a string into an int. Assume the int is between 10 and 99. Do not use the atoi() or the stoi() function.

2. Write a function prototype for problem 1.

3. Write a function call for the function you defined in problem 1.

4. Write a function that converts an int between 10 and 99 into a string.

5. Write a function prototype for problem 4.

6. Write a function call for function you defined in problem 4.

7. Declare a 2-dimensional array with 30 rows and 40 columns

8. Write a function that takes the 2-dimensional array argument from problem 7 and assigns the even rows random even numbers between 1 and 100 and assigns the odd rows random odd numbers between 1 and 100.

9. Write a function prototype for problem 8.

10. Write a function call for function you defined in problem 8.

11. What's the output from the following ...

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1) int convertToInteger(char str[]) {
  int i, n = 0;
 
  for (i = 0; str[i] != '\0'; i++) {
    n = n * 10 + str[i] - '0';
  }
 return n;
}

(2) Function Prototype
 int convertToInteger(char *str);

(3) Function Call
char str[] = "12";
convertToInteger(str);


4) char *convertToString(int n) {
  char str[3];
   int temp , i=1;
  while (n!=0){
    temp = n%10;
    n = n/10;
    str[i] = temp;
    i = i-1;
   }
  str[2]= '\0';
 return str;
}

(5) Function Prototype
 char *convertToString(int n);

(6) Function Call
int n  = 12;
convertToString(n);


(7) int arr[30][40];

(8)void fun(int arr[30][40]){
   int r ;
   for(int i = 0;i<30;++i){
      for(int j = 0;j<40;++j){
            if(i%2==0){
                r = rand()%99 + 1;
               if(r%2 !=0 )
                  r = r +1;
                arr[i][j] = r;
              }else{
                   
              r = rand()%99 + 1;
               if(r%2 ==0 )
                  r = r +1;
                arr[i][j] = r;
              }
       }
}


9) void fun(int arr[30][40]);

(10)fun(arr)
 
Add a comment
Know the answer?
Add Answer to:
1. Write a function that converts a string into an int. Assume the int is between...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write MIPS code that converts a string containing a number into an actual number. The function...

    Write MIPS code that converts a string containing a number into an actual number. The function to do this conversion, atoi (Array To Integer) should have a single input (the string) and output a single number (the integer). The Java/C code is as follows: atoi(a0: array) { int digit, number, i = 0; while( (array[i] >= '0') && (array[i] <= '9') ) { digit = array[i] - '0'; number = 10 * number + digit; i++; } return number; }

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • Write a function getScores(...) that is given a string, an int type array to fill and...

    Write a function getScores(...) that is given a string, an int type array to fill and the max number of elements in the array as parameters and returns an integer result. The function will find each substring of the given string separated by space characters and place it in the array. The function returns the number of integers extracted. For example: int values[3]; getScores("123 456 789", values, 3 ); would return the count of 3 and fill the array with...

  • sort.c #include <stdlib.h> #include <stdio.h> #include "libsort.h" int main() {     int* array;     int size,...

    sort.c #include <stdlib.h> #include <stdio.h> #include "libsort.h" int main() {     int* array;     int size, c;     float median;     printf("Enter the array size:\n");     scanf("%d", &size);     array = (int*) malloc(size * sizeof(int));     printf("Enter %d integers:\n", size);     for (c = 0; c < size; c++)         scanf("%d", &array[c]);     sort(array, size);     printf("Array sorted in ascending order:\n");     for (c = 0; c < size; c++)         printf("%d ", array[c]);     printf("\n");     median = find_median(array,...

  • Part II. Write a programming segment that generates 25 random integers between 0 and 99. Place...

    Part II. Write a programming segment that generates 25 random integers between 0 and 99. Place the even numbers in an array called EVEN and then place the odd numbers in an array called ODD. Print the EVEN array and Print the ODD array

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • 17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int...

    17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int array1[20] = {3, 18, 1, 25, 4, 7, 30, 9, 80, 16, 17}; int numElements = 11; cout << "Part 1" << endl; // Part 1 // Enter the statement to print the numbers in index 4 and index 9 // put a space in between the two numbers    cout << endl; // Enter the statement to print the numbers 3 and 80...

  • please do all in C++ code, thank you. Worth 1 point Checkpoint 7.12 Write a statement...

    please do all in C++ code, thank you. Worth 1 point Checkpoint 7.12 Write a statement that assigns the value 10 to the first elementof an array of integers named minutes. Type your program submission here Worth 1 point Checkpoint 7.14 Write a cout statement that will display contents of the second element of an array named courseNumbers Type your program submission here Submit Worth 1 point Checkpoint 7.15 Write a cin statement that will store the user's input in...

  • Refer to the following array definition for questions 1 & 2 int numberArray[9)[11] 1. Write a...

    Refer to the following array definition for questions 1 & 2 int numberArray[9)[11] 1. Write a statement that assigns 145 to the first column of the first row of this array. 2. Write a statement that assigns 18 to the last column of the last row of this array. values is a two-dimensional array of floats, with 10 rows and 20 columns. Write code that sums all of the elements in the array and stores the sum in the variable...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT