all_assignment
all_assignment
ASSIGNMENT 1 – C PROGRAMMING
Answer:-
#include <stdio.h>
int main()
scanf("%d", &matrix[i][j]);
max = matrix[0][0];
max = matrix[i][j];
return 0;
1|Page
DIv:- 5 Roll No:- 472
Question 2:- Write a program to transpose of matrix and store it into 2nd matrix.
Answer:-
#include <stdio.h>
int main()
scanf("%d", &matrix[i][j]);
transpose[j][i] = matrix[i][j];
printf("\n");}
return 0;
2|Page
DIv:- 5 Roll No:- 472
Answer:-
#include <stdio.h>
#include <string.h>
int main()
int n = 5;
scanf("%s", cities[i]);
strcpy(temp, cities[i]);
strcpy(cities[i], cities[j]);
strcpy(cities[j], temp);
printf("%s\n", cities[i]);
return 0;
3|Page
DIv:- 5 Roll No:- 472
Question 4:- .Create a structure student having data member like rollno, name and array of three
subject marks. Write a program to list the name of students who have failed in any one of the
subjects. (Failing Criteria: Marks < 35)
Answer:-
#include <stdio.h>
#include <string.h>
struct Student
int rollno;
char name[50];
int marks[3];
};
int main()
int n;
scanf("%d", &n);
scanf("%d", &students[i].rollno);
printf("Name: ");
scanf("%s", students[i].name);
scanf("%d", &students[i].marks[j]);
4|Page
DIv:- 5 Roll No:- 472
break;
}}}
return 0;
Question 5:- Write a recursive function for finding factorial of given number.
Answer:-
#include <stdio.h>
if (n == 0 || n == 1) {
return 1;
int main()
int num;
scanf("%d", &num);
else
5|Page
DIv:- 5 Roll No:- 472
}return 0;
Question 6:- Write menu-driven program that will perform following tasks using UDFs by
passing a string argument to each function. a. Exit | b. Print String | c. Length of
String | d. Copy First String into Second String | e. Copy Second String into First String | f.
Compare Two String | g. Reverse String h. Concat Two String
Answer:-
#include <stdio.h>
#include <string.h>
int main()
int choice;
scanf("%s", str1);
scanf("%s", str2);
do{
6|Page
DIv:- 5 Roll No:- 472
printf("0. Exit\n");
scanf("%d", &choice);
switch (choice){
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
strcpy(str2, str1);
break;
case 6:
strcpy(str1, str2);
break;
case 7:
break;
case 8:
strcpy(temp, str1);
strrev(temp);
7|Page
DIv:- 5 Roll No:- 472
break;
case 9:
strcpy(temp, str2);
strrev(temp);
break;
case 10:
strcat(str1, str2);
break;
case 0:
printf("Exiting...\n");
break;
default:
printf("Invalid choice!\n");
return 0;
8|Page
DIv:- 5 Roll No:- 472
ASSIGNMENT 2 – PS ASSIGNMENT 1
Question 1:- Write a program to multiply 2 matrix and store it into 3rd matrix.
Answer:-
if c1 != r2:
for i in range(r1):
for j in range(c2):
for k in range(c1):
return C
print(f"{name} matrix:")
if __name__ == "__main__":
result = matrix_multiply(A, B)
if isinstance(result, str):
print(result)
else:
matrix_display(A, "First")
matrix_display(B, "Second")
9|Page
DIv:- 5 Roll No:- 472
matrix_display(result, "Resultant")
Question 2:- Write a program to transpose of matrix and store it into 2nd matrix.
Answer:-
def matrix_transpose(A):
r, c = len(A), len(A[0])
for i in range(r):
for j in range(c):
B[j][i] = A[i][j]
return B
print(f"{name} matrix:")
if __name__ == "__main__":
B = matrix_transpose(A)
matrix_display(A, "Original")
matrix_display(B, "Transposed")
Answer:-
def string_length(s):
return len(s)
if __name__ == "__main__":
10 | P a g e
DIv:- 5 Roll No:- 472
s = "Hello, World!"
Answer:-
if __name__ == "__main__":
target = "banana"
if search_string(string_list, target):
else:
Question 5:- Write a program to copy 5 strings into another array and print new array.
Answer:-
def copy_strings(original_list):
return original_list[:]
if __name__ == "__main__":
copied_list = copy_strings(original_list)
11 | P a g e
DIv:- 5 Roll No:- 472
ASSIGNMENT 3 – PS ASSIGNMENT 2
Question 1:- .Write a recursive function for finding factorial of given number.
Answer:-
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
if __name__ == "__main__":
num = 15
Answer:-
def fibonacci(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
series = fibonacci(n - 1)
series.append(series[-1] + series[-2])
return series
if __name__ == "__main__":
12 | P a g e
DIv:- 5 Roll No:- 472
num = 15
Question 3:- Write menu-driven program that will perform following tasks using UDFs by passing a
string argument to each function.
Answer:-
def print_string(s):
print(f"String: {s}")
def string_length(s):
return len(s)
def copy_string(s):
return s[:]
return s1 == s2
def reverse_string(s):
return s[::-1]
return s1 + s2
def menu():
13 | P a g e
DIv:- 5 Roll No:- 472
while True:
print("\nMenu:")
print("8. Exit")
if choice == 1:
print_string(s1)
elif choice == 2:
elif choice == 3:
s2 = copy_string(s1)
elif choice == 4:
s1 = copy_string(s2)
elif choice == 5:
print("Strings are equal" if compare_strings(s1, s2) else "Strings are not equal")
elif choice == 6:
elif choice == 7:
elif choice == 8:
14 | P a g e
DIv:- 5 Roll No:- 472
break
else:
if __name__ == "__main__":
menu()
Question 9:- Write a program that will pass an array of numbers to the function and returns count of
odd numbers from the function.
Answer:-
def count_odd_numbers(arr):
if __name__ == "__main__":
15 | P a g e
DIv:- 5 Roll No:- 472
ASSIGNMENT 4 – PS ASSIGNMENT 3
Answer:-
def celsius_to_fahrenheit(celsius):
if __name__ == "__main__":
Answer:-
def check_number(n):
if n > 0:
return "Positive"
elif n < 0:
return "Negative"
else:
return "Zero"
if __name__ == "__main__":
16 | P a g e
DIv:- 5 Roll No:- 472
Answer:-
def check_odd_even(n):
if n % 2 == 0:
return "Even"
else:
return "Odd"
if __name__ == "__main__":
17 | P a g e
DIv:- 5 Roll No:- 472
Question 4:- Python Program to Check Leap Year (Formula : (Year % 400 == 0) or (Year % 100 != 0)
and (Year % 4 == 0) )
Answer:-
def is_leap_year(year):
if __name__ == "__main__":
if is_leap_year(year):
else:
18 | P a g e