0% found this document useful (0 votes)
33 views7 pages

Set 5

The document contains details about a test for the course "Programming for Problem Solving" including: - Course learning rationale and outcomes related to arrays, functions, and data types in Python. - Six questions in Part A asking students to write C/C++ or Python code to solve problems related to arrays, functions, strings, matrices, Fibonacci sequences, and calculating placement eligibility from semester marks. - The questions test students on course learning outcomes around arrays, functions, control statements, and basic Python data types and programming concepts.

Uploaded by

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

Set 5

The document contains details about a test for the course "Programming for Problem Solving" including: - Course learning rationale and outcomes related to arrays, functions, and data types in Python. - Six questions in Part A asking students to write C/C++ or Python code to solve problems related to arrays, functions, strings, matrices, Fibonacci sequences, and calculating placement eligibility from semester marks. - The questions test students on course learning outcomes around arrays, functions, control statements, and basic Python data types and programming concepts.

Uploaded by

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

REG NO.

SRM Institute of Science and Technology


SET 5
College of Engineering and Technology
School of Computing
SRM Nagar, Kattankulathur – 603203, Chengalpattu District, Tamil Nadu
Academic Year: 2023-24 (ODD)

Test: CLA-T2 Date: 6-11-2023


Course Code & Title: 21CSS101J & Programming for Problem Solving Duration: 1 hour 40 mins
Year & Sem: I Year / I Sem Max. Marks: 50

Course Learning Rationale (CLR):


CLR-3: Store and retrieve data in a single and multidimensional array.
CLR-4: Create custom designed functions to perform repetitive tasks in any application.
CLR-5: Create basic Abstract Data Types with python.
Course Learning Outcomes (CLO/CO):
CLO-3: Create string processing applications with single and multi-dimensional arrays.
CLO-4: Create user defined functions with required operations. To implement pointers in applications with dynamic
memory requirements.
CLO-5: Create programs using the python data types, loops, control statements for problem solving.

Course Articulation Matrix: (to be placed)


Course
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
Outcome
CLO3/CO3 2 3 - - - - - - - - - - - - -
CLO4/CO4 2 3 - - - - - - - - - - - - -
CLO5/CO5 2 3 - - - - - - - - - - - - -

Part – A
(5 x 10 = 50 Marks)
Answer any FIVE Questions
Q. Question Marks CO PO BL PI
No Code
1 Ajay and Akash both are working with their mathematics 10 2 3 2,3 2.6.3
homework problem on matrix. Write a c program to help them
to solve matrix addition problem.
Use:
# define MAX 20
Utilize MAX to define array size as int A[MAX][MAX];
Read row_size r1, r2 and column_size c1, c2
Check condition r1 equals r2 and c1 equals c2 before addition
Test Case:
Input:

A= B=
Output:

C=

#include <stdio.h>
# define MAX 20
int main()
{
int i,j,k,r1,r2,c1,c2;
int a[MAX][MAX],b[MAX][MAX],c[MAX][MAX];
step1:
printf("\n Enter the size of matrix A:");
scanf("%d %d",&r1,&c1);
printf("\n Enter the size of matrix B: ");
scanf("%d %d",&r2,&c2);
if((c1==c2)&&(r1==r2))
goto step2;
else
goto step1;
step2:
printf("\n Enter the elements of matrix A \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n Enter the elements of matrix B \n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n The resultant matrix after addition of A & B is\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
return 0;
}

2 Ramu has stored his subject marks in an array in the following 10 2 3 2,3 2.6.3
order: CS, CHEM, PHY, MATH, S_LANG, F_SLANG.
Write a C program to write his marks in reverse order as F_ANG,
S_LANG, MATH, PHY, CHEM, CS.
Use: Array pointers: int Marks[10], rev_Marks[10];
int *p (use p to point to array Marks)
use pointer to read input and display output.
use p++ and p--
Test Case:
Input: 97, 98, 85, 88, 76, 67
Output: 67, 76, 88, 85, 98, 97

#include <stdio.h>
int main()
{
int Marks[10],n,i,j,rev_Marks[10];
int *p;
p=Marks;
printf("Enter the number of Elements: ");
scanf("%d",&n);
printf("Enter %d Elements:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",p++);
}
printf("The elements in order:\n");
for(i=0;i<n;i++)
{
printf("%d\n",Marks[i]);
}
printf("The elements in reverse order:\n");
for(j=n-1;j>=0;j--)
{
rev_Marks[j]=*p;
printf("%d\n",*(--p));
}
return 0;
}

3 Sita wants to text her password to her father. Sita wants to add 10 3 3 2,3 2.6.3
security to the text. Help her to encrypt her password using the
following technique.
Encryption Method: ‘A’ ad ‘C’, ‘B’ as ‘D’, ….., ‘X’ as ‘Z’, ‘Y’
as ‘A’, ‘Z’ as ‘B’ and so on..
Use:
scanf() function with appropriate control string– to read string
input
use do… while …. loop
Test Case:
Input: “INDIA”
Output: “KPFKC”
#include <stdio.h>
int main() {
char pswd[20],encrypt_pswd[20];
int i=0;
printf("Enter password for encryption:");
scanf("%s",&pswd);
while(pswd[i]!='\0')
{
encrypt_pswd[i]=pswd[i]+2;
i++;
}
encrypt_pswd[i]='\0';
printf("Your encrypted password is %s",encrypt_pswd);
return 0;
}

4 In every flowering plants, the number of petals on the flowers is 10 3 3 2,3 2.6.3
a Fibonacci number. Write a c function to read the number of
petals and print the Fibonacci sequence of a flower.
Use:
void FlowerPetals(int Petals);
Test Case:
Input: 20 Petals
Output: 0, 1, 1, 2, 3, 5, 8.

#include <stdio.h>
void FlowerPetals(int Petals);
int main() {
int p;
printf("Enter number of Petals:");
scanf("%d",&p);
FlowerPetals(p);
return 0;
}
void FlowerPetals(int Petals)
{
int sum=0, f, f0=0, f1=1;
printf("The Fibonacci Sequence:\n%d\n%d\n", f0, f1);
sum=f0+f1;
while(sum<Petals)
{
f=f0+f1;
sum=sum+f;
f0=f1;
f1=f;
printf("%d\n",f);
}
printf("No of Petals in the flower is %d", sum);
}

5 RTO office assigns 4-digit number for every new vehicle coming 10 3 3 2,3 2.6.3
for registration. Once the number are generated, they are checked
for their sum of digits. If the sum of digits is not 8 then the
number is assigned for the vehicle and is the sum is 8 then the
number is discarded.
Write a C function ‘CheckNum’ to get a number and calculates
its sum and checks whether the sum is 8 or not. If sum is 8 then
return 0 otherwise return 1. In main function, the display
appropriate message as ‘Discard Number’ if the returned value
is 0 else display ‘Assign Number’.
Use:
int CheckNum(int number);
return 0, return 1
Test Case:
Input: 7010
Output: Discard Number
Input: 0102
Output: Assign Number

#include <stdio.h>
int CheckNum(int number);
int main() {
int num, T;
printf("Enter number for New vehicle registration:");
scanf("%d",&num);
T = CheckNum(num);
if (T==1)
printf("Assign Number");
else
printf("Discard Number");
return 0;
}
int CheckNum(int number)
{
int sum=0, r;
while(number>0)
{
r=number%10;
sum=sum+r;
number=number/10;
}
if (sum==8)
return 0;
else
return 1;
}

6 1. Ashwin is a final year B.Tech student. He stored his 10 4 3 2,3 2.6.3


marks from semesters 1 to 7 in a ‘Sem_Marks’ list.
Write a Python code to calculate the percentage of
all the semester scores, and show the eligibility
criteria for placement according to the following
constraints:
1. Above 90 : “Eligible for Marquee placement”
2. 80 to 89 : “Eligible for Super dream offer”
3. 70 to 79 : “Eligible for Dream offer”
4. 60 to 69: “Day sharing”
5. Below 60: “Not eligible”
Output:
Sem_Marks = [80, 85, 90, 75, 95, 85, 80]
The percentage of all the semester scores is: 84.285
The placement category: Eligible for Super dream offer.

Sem_Marks = []
n = int(input("Enter no of semester: "))
print("Enter {} semester Percentage/Grade Points".format(n))
for i in range(n):
marks = int(input())
Sem_Marks.append(marks)
percent = sum(Sem_Marks)/n
print("The percentage of semester scores: ",percent)
if percent>=90:
print("Eligible for Marguee Placement")
elif 80<=percent<=89:
print("Eligible for Super Dream offer")
elif 70<=percent<=79:
print("Eligible for Dream offer")
elif 60<=percent<=69:
print("Day Sharing")
else:
print("Not Eligible")

7 The mountains of India and their elevation heights in meters are 10 4 3 2,3 2.6.3
read and stored in a Dictionary ‘Indian_Mountain’. Mountain
names are stored as keys and its elevation is stored as its value.
(i) Ashok wants to prepare for a quiz on mountains
and their heights. Write a python code to display all
the mountain names along with its heights which
facilitates him to learn.
Use: dict.keys() – loop through keys
(ii) The next day in the quiz competition, he was asked
the height of Trisul. Write a python code to fetch
the height of Trisul.
Use: dict.items()
Use:
Create dictionary using loop
Test Case:
Input: {Kangchenjunga:8586 m, NandaDevi: 7816 m, Kamet:
7756 m, SaltotoKangri: 7742 m, SaserKangri: 7672 m,
MamostrongKangri: 7516 m, Rimo: 7385 m, Hardeol: 7151 m,
Chaukhamba: 7138 m, Trisul: 7120 m}
Output:
(i) Kangchenjunga:8586, NandaDevi: 7816, Kamet:
7756, SaltoroKangri: 7742, SaserKangri: 7672,
MamostrongKangri: 7516, Rimo: 7385, Hardeol:
7151, Chaukhamba: 7138, Trisul: 7120
(ii) Height of Trisul is 7120

Indian_Mountains = {}
n = int(input("Enter number of Mountains entries:"))
print("Enter {} mountains name and their heights".format(n))
for i in range(n):
Mt_name = input("Mountain Name:")
height = int(input("Height:"))
Indian_Mountains[Mt_name]=height
print("Here you have the Mountains height details:")
for key in Indian_Mountains.keys():
print(key," : ",Indian_Mountains[key])
Ques = input("Say the height of ")
for key,value in Indian_Mountains.items():
if key==Ques:
print(key," : ",value)

You might also like