arraytest


Submit solution

Points: 10 (partial)
Time limit: 8.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C

Get the size of 2D array and the input values from the user. Print the array and sum.


Comments


  • 0
    24kayush  commented on May 27, 2023, 10:39 a.m.

    Answer all Questions Part A [25 Marks – 1 hour 15 minutes]

    1. Dharani is practicing the concept of character arrays in C programming. She needs to identify the number of alphabets (both uppercase and lowercase included) and nonalphabets (both digits and special characters) in any entered string. Towards this task, she needs to read a string (which has both uppercase and lowercase alphabets + one or more words separated by a single space) and an integer between 1 and 5. The integer is used as the choice of operation to be performed on the input string: - 1 - Display the string. 2 - Display the length of the string. 3 - Display the count of alphabets (both uppercase and lowercase together) present in the string. 4 - Display the count of non-alphabets (in the string. 5 - Encrypt the string. Encryption is performed in the following way - Read an integer, count its number of even digits say D, and replace each alphabet in odd indices by D letters before it. Digits and Special characters are left as they are. For example, if the input integer is 476, D will be 2, as digits 4 and 6 are even. Let the string be "Old is Gold". The encryption replaces characters at indices 1, 5, 7, and 9. Index 3 has a space, and hence left as it is. The alphabets to be modified are l, s, G, and l. They are replaced as j, q, E, Page 2 of 5 and j respectively. The encrypted string will be " Ojd iq Eojd ". The alphabets follow a cycle; i.e; if the letter to be replaced is A and D is 3, it is replaced by X. Help Dharani to write a C program that reads a string and an integer between 1 and 5 indicating the operation to be performed, and outputs the result based on the operation selected. If the integer option is outside the range specified, the program displays –1.
    2. A NxN square matrix with size N being ODD, is said to be a PLUS (+) Matrix if both of the following conditions hold: i. All the elements present in the + shaped positions of the matrix are zero ii. All other elements are non-zero. Write a C program that reads dimension N for a sqaure matrix as well as the elements of the matrix. Then the program checks whether it is an ODD-order square matrix (N is ODD). If N is a ODD, the program should also check whether the matrix is a PLUS-matrix. If N is not ODD, the program prints the matrix in its proper form. If N is ODD, the program prints YES if the matrix is a PLUS-Matrix. If N is ODD, but not a PLUS-Matrix, then the program should print NO. Example : Input Matrix: 6 1 0 8 5 3 7 0 8 2 0 0 0 0 0 2 4 0 5 9 8 9 0 2 7 Output: YES Example 2: Input Matrix: 4 0 9 0 0 2 8 0 1 Output: NO Page 3 of 5 Part B [15 Marks, 45 Minutes]
    3. a. Assume that a C code is written using switch statement to print the day of week upon receiving an integer (1 <= n <= 7). The switch statement has seven integer constants, namely, 1 to 7 with the first three cases having a break statement at the end of each case and the remaining four cases having no break statement. A default case is also there to print the error message “Incorrect input”. What will be the code’s output for various inputs given below? [CO3][BTL2][2 marks] Input Output 1 3 6 9 b. The code below must print the Floyd triangle as given below. The Floyd triangle is filled with alphabets or digits from the starting (from 1 if digit or from ‘a’/’A’ if letter), instead of repeating the same digit or letter along rows. If the number of rows is maximum, the alphabets must be filled in cyclic fashion. Find out and write down the missing instructions in the code below. [CO3][BTL2][3 marks] Page 4 of 5
    4. The formula for the volume of a sphere is 𝑉 = 4/3 𝜋 𝑎 2 𝑏, where a and b are the halflengths of the major and minor axes respectively. The following C program reads values for a and b and then calculates and displays the volume. Complete the missing parts in the program. Use appropriate variable declarations in the program (do not use any additional variables) and write only 1 statement on each blank line. [CO1][BTL1][5 marks] #include<stdio.h> /*declare the constant value of 𝜋 as 3.141593

    int main() { / declare variables /


    /read the values of a and b from the keyboard/


    /compute the volume of the sphere /


    /display the result onto the screen/


    return 0; } 5. a. Predict the output of the following code snippet. [CO2][BTL2][2 Marks]

    include <stdio.h>

    void fn() { int i = 10; printf("%d ", ++i); } int main() { fn(); fn(); }

    Page 5 of 5 b. Predict the output of the following code [CO2][BTL2][3 Marks]

    include<stdio.h>

    int a=10; void disp(); main() { int a=20; { int a=30; printf("Value of a:%d\n",a); } printf("Value of a:%d\n",a); disp(); return; } void disp() { printf("Value of a:%d\n",a); return; }


    CO Marks BTL Marks CO01 5 BTL 1 5 CO02 5 BTL 2 10 CO03 5 BTL 3 25 CO04 25 BTL 4