0% found this document useful (0 votes)
54 views12 pages

Lab 4

This document provides instructions for a programming lab assignment on 1D arrays and strings in C programming. It describes 3 problems to solve involving inputting arrays, multiplying array elements, rearranging array elements, and extracting substrings from a string. It specifies how to name, save, and submit the source code files for each problem. It also outlines the marking schemes and points allocated for each part of the problems.

Uploaded by

Suhani Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views12 pages

Lab 4

This document provides instructions for a programming lab assignment on 1D arrays and strings in C programming. It describes 3 problems to solve involving inputting arrays, multiplying array elements, rearranging array elements, and extracting substrings from a string. It specifies how to name, save, and submit the source code files for each problem. It also outlines the marking schemes and points allocated for each part of the problems.

Uploaded by

Suhani Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

CS19003:

Programming and
Data Structure Lab
Lab 4: 1D Arrays, Strings
Sandip Chakraborty
Submission Requirements
 On top of your code, enter your name and roll numbers within
comments.
/***********************************
* Name: Your Name
* Roll: Your Roll
**********************************/
Programming Practices
 Do not copy the code from others. Any form of plagiarism will lead
to zero marks.
 Take help of the Internet to solve the problem.
 If you get a compilation error, try to read the error message and find
out the reason behind the error.
 If you do not get the expected output, try to debug your code with
extra printf statements.
Submission Instructions
 Once you are done with a code, save the code in your local machine as
A4_P1.c, A4_P2.c and A4_P3.c for Problem 1, Problem 2, and Problem 3,
respectively

 Upload A4_P1.c, A4_P2.c, and A4_P3.c in Moodle course page,


corresponding to Assignment 4 -- https://moodlecse.iitkgp.ac.in/

 No late submission or email submission is allowed.


Problem 1
Consider an array named arr_base of floating-point numbers. Assume that there are five
numbers are being stored in the array.
Write a C program to
(a) Take five elements as an input to arr_base, so that each input is larger than the
previous input. In case the input is not larger than the previous one, return an error and ask
the user to enter the next element. Populate the array with five such elements.
(a) Multiply the array elements pair-wise from arr_base and populate a second array
arr_mult with the multiplication results. For arr_mult, the first element will be the same
as the first element of arr_base, the second element will be the multiplication of the first
and the second elements from arr_base, the third element will be the multiplication of the
second and third element from arr_mult, and so on. Print arr_mult.
Problem 1: Example
Enter array element 1: 2.3
Enter array element 2: 3.2
Enter array element 3: 4.1
Enter array element 4: 2.2
Incorrect! Enter again: 5.1
Enter array element 5: 5.6
The multiplication array is:
2.3 7.36 13.12 20.91 28.56
Problem 1 - Marks
Entering the array: 2 marks
 Deduct 1 if the increment condition is not checked

Multiplication and populating the second array: 3 marks


Deduct 2 marks if the logic is not correct completely, but some sort of
multiplication is being done to populate the second array.
Problem 2
 Consider an integer array of size 10. The array contains integer numbers from 1 to
200. Write a C program that
 (a) Declares the array and asks the user to enter 10 integer numbers in between 1
and 200 (inclusive those). Once the user enters 10 integer numbers within the
range, the array is populated with those numbers.
 (b) Rearrange the numbers of the array elements as follows. You should not use
any additional array for this.
 The numbers less than 100 (including 100) are kept first, these numbers are sorted in the
decreasing order
 The numbers greater than 100 are kept next, these numbers are sorted in the increasing order
 (c) Print the output array after rearranging the elements.
Problem 2 - Example
 Entered array: 2 90 6 120 87 43 23 199 110 101
 Output array: 2 6 23 43 87 90 199 120 110 101

 Entered array: 89 76 54 23 49 65 78 90 99 12
 Output array: 12 23 49 65 54 76 78 89 90 99

 Entered array: 123 145 167 110 102 198 176 134 142 199
 Output array: 199 198 176 167 145 142 134 123 110 102
Problem 2 – Marks Distribution
 (a) Entering the numbers in the array: 3 Marks
 Deduct 2 Marks if the range 1 to 200 is not checked or less than 10 numbers are entered
 (b) Give marks if the code produces the correct output for each of the following
cases (no partial marks)
 All the array elements are less than 100: 2 Marks
 All the array elements are greater than 100: 2 Marks
 The array has a mix of elements from 1 to 200: 3 Marks
 Give 50% marks in Part (b) above, if an additional array is used to produce the
output.
Problem 3
 Declare a C string and initialize it as follows:
"Your_Roll_Number,Your_First_Name,Your_Last_Name"

 For example, if your roll number is 22CS10021, Your first name is Rohit and your last name is Raj,
then the C string will be "22CS10021,Rohit,Raj". Initialize this string statically in your code; you
do not take an input from the user.

 Now, write a C program to produce the following string in the output, from the above string.
"My name is Rohit Raj. My roll number is 22CS10021".

 To do this, your code should have a printf statement as follows:


printf("My name is %s %s. My roll number is %s", str1, str2, str3)
 Your C code should populate these three strings from the original string by extracting the relevant
substrings. Marks will not be given if you hardcode the output statement.
Problem 3 – Marks Distribution
 Correct output: 5 Marks
 There will be no partial marks for this problem.

You might also like