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.

  • JAVA CODE FOR BEGINNERS!! Write a program that reads three strings from the keyboard. Although the...

    JAVA CODE FOR BEGINNERS!! Write a program that reads three strings from the keyboard. Although the strings are in no particular order, display the string that would be second if they were arranged lexicographically.

  • 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 finds the row totals and column totals of a Matrix. The...

    Write a C Program that finds the row totals and column totals of a Matrix. The user is prompted to enter the numbers to fill in a two-dimensional array of any size (say 3x3). The program then finds the sum of row elements and prints them along-side rows, and finds the sum of columns and prints them along-side corresponding columns. You will need nested for loops please help!

  • 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...

  • Write a piece of code that constructs a two-dimensional array of integers with 5 rows and...

    Write a piece of code that constructs a two-dimensional array of integers with 5 rows and 10 columns. Fill the array with a multiplication table, so that array element [i][j] contains the value i * j. Use nested for loops to build the array. java Program

  • 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.

  • Part 2) write a C++ program that declares a 2 dimensional array: int CSIIAssign3 [10][12]; Initialize...

    Part 2) write a C++ program that declares a 2 dimensional array: int CSIIAssign3 [10][12]; Initialize your array using a text file, user input or assign value while declaring the array, you can choose the method. Then, a. Write a loop to print first row of the array on one line, using cout. b. Write a loop to print first column of the array on one line, using cout. c. Write a loop to print first five rows of the...

  • Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to...

    Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to enter an item’s name for each position in the array. The program then prints uses a loop to output the array. Example 1: Banana 2: Orange 3: Milk 4: Carrot 5: Chips Banana, Orange, Milk, Carrot, Chips Problem 2: Print Characters in String Array    Declare a string array of size 5. Prompt the user enters five strings that are stored in the array....

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