Question

Three C Code Questions: 5. Write a C program that declares an array of 10 strings,...

Three C Code Questions:

5. Write a C program that declares an array of 10 strings, each of max length 50 characters, and then reads an entire line of text from the keyboard into each string.

6. Write C code that finds the longest name in this array of strings that you read in Q5. Hint: find the position of the longest string, not the string itself.

7. Write a C program that creates a 4 x 6 two dimensional array of integers. Your program should then prompt the user to enter 24 values to fill the array. Once this is done, you should then calculate the sum and maximum value of each row of the array separately. Your program should use nested loops to do this, and display the output in the following form:

Row 1: Sum of numbers is 31, maximum value 11

Row 2: Sum of numbers is 13, maximum value 5

Row 3: Sum of numbers is 105, maximum value 52

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main(){
    char arr[10][50];
    int i;

    for(i = 0;i<10;i++){
        scanf(" %[^\t\n]s",&arr[i]);
    }

    return 0;
}

=====================================

#include <stdio.h>
#include <string.h>

int main(){
    char arr[10][50];
    int i, max = 0;

    for(i = 0;i<10;i++){
        scanf(" %[^\t\n]s",&arr[i]);
    }

    for(i = 1;i<10;i++){
        if(strlen(arr[max]) < strlen(arr[i])){
            max = i;
        }
    }

    printf("Longest string index : %d\n",max);

    return 0;
}

=====================================

#include <stdio.h>

int main(){
    int arr[4][6];
    int i,j,max,sum;
    
    printf("Enter 24 values:\n");
    for(i = 0;i<4;i++){
        for(j = 0;j<6;j++){
            scanf("%d",&arr[i][j]);
        }
    }
    
    
    for(i = 0;i<4;i++){
        sum = 0;
        max = arr[i][0];
        for(j = 0;j<6;j++){
            if(max < arr[i][j]){
                max = arr[i][j];
            }
            sum = sum + 1;
        }
        printf("Row %d: Sum of numbers is %d, maximum value %d\n",i+1,sum,max);
    }
    
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Three C Code Questions: 5. Write a C program that declares an array of 10 strings,...
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 the line that declares a two-dimensional array of strings named chessboard. That is, how would...

    Write the line that declares a two-dimensional array of strings named chessboard. That is, how would I declare a two-dimension array of strings that is called chessboard? You would declare a String array by saying " String []" correct? Now that's just a single array. How can I make that a two-dimension array? And how would I name it chessboard? Write the line that declare and creates a two-dimensional array of chars, tictactoe, with 3 rows, each with 3 elements...

  • Q1) C-Programming Create a C program to declare an array of 5 pointers to strings and...

    Q1) C-Programming Create a C program to declare an array of 5 pointers to strings and to allocate the exact memory needed to store strings of less than 8 characters. The program should read 5 strings and display the longest one. If more than one string is the longest, the program is to display the one found first.

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • Write a C++ program that reads a string and creates a cyclical array. A cyclical array...

    Write a C++ program that reads a string and creates a cyclical array. A cyclical array is an array when the last element is pointing to the first one. Then write a loop that uses pointers and loops through the array starting from the first element and finishes after it visits the first element 5 times.

  • Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The...

    Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The first row has length 1, the second row has length 2, the third row has length 3, and so on. Then initialize the array using nested for loops so that the value of A[i][j] is i+j. Finally, print out the array in a nice triangular form.

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • Structures in C++ :- 1. Write a program that declares a structure to store the code...

    Structures in C++ :- 1. Write a program that declares a structure to store the code number, salary and grade of an employee. The program defines two structure variables, inputs record of two employees and then displays the record of the employee with more salary. 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then...

  • C programming 1 String Merging Write a program that reads two strings s1 and s2 from...

    C programming 1 String Merging Write a program that reads two strings s1 and s2 from the keyboard and merges them to a string s3. Strings s1 and s2 are statically allocated whereas s3 is dynamically allocated to fit exactly s1 and s2. The two original strings are no longer than 100 characters long. Use the following function to merge the two strings. char *stringMerge(char s1[], char s2 []); Example: Enter the first string: Hello world Enter the first string:...

  • Use c-strings for the following project: Write a C++ program that declares an array containing up...

    Use c-strings for the following project: Write a C++ program that declares an array containing up to a maximum of 20 sentences, each sentence of maximum 81 characters long, using c-strings. Continue reading sentences from the user and store them in the array of sentences, until the user enters a NULL string for the sentence or 20 sentences have been entered. Then, one by one, display each sentence entered by the user and present the following menu of operations on...

  • c programming

    Write a c program that reads a string with a maximum length of 30 from the keyboard[1]. The program should then copy the characters from that input string into a second character array (in order of input). However, only if a character is a vowel (a, e, i, o, u) should it be copied into the second array. Once copied, the program should output the values stored in the second array (in order of input). The program should then count...

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