204-PS - Practical Sheet With Solution Unit 1-2-3
204-PS - Practical Sheet With Solution Unit 1-2-3
Y-2023-2024
FYBCA-SEM2-204 – Programming Skills
Unit-1- C Programming Practical sheet
Multidimensional Numeric & String Array
1. Write C program to calculate Addition of two Matrices.
/*Addition of two matrix in C */
#include<stdio.h>
#include<conio.h>
int main()
{
int a[3][3],b[3][3],sum[3][3],i,j;
clrscr();
printf("Enter Matrix A Elements: ");
for(i=0;i<3;i++)// rows
{
for(j=0;j<3;j++) //cols
{
printf("\n Enter Array element A[%d][%d] :",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter Matrix B Elements: ");
for(i=0;i<3;i++) // rows
{
for(j=0;j<3;j++) //cols
{
printf("\n Enter Array element B[%d][%d] :",i,j);
scanf("%d",&b[i][j]);
}
}
printf("\n Matrix A : \n");
printf("~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("\n Matrix B : \n");
printf("~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d ",b[i][j]);
}
printf("\n");
}
printf("\n Sum of two matrices : \n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
for(i=0;i<3;i++)
int main()
{
int arr[10];
int n, mm = 1, ctr = 0;
int i, j;
#include <stdio.h>
#include<conio.h>
#define SIZE 3
int main()
{
int A[SIZE][SIZE];
int row, col, sum = 0;
void main()
{
char text[10][80];
int i,n;
clrscr();
flushall();
for(i = 0; i < n ; i++)
{
printf("\n Enter Some string for index %d: ", i + 1);
gets(text[i]);
}
getch();
}
printf("Enter Words:\n");
for(i=0;i<n;i++)
{
printf("\n Enter String %d : ",i+1);
scanf("%s[^\n]",str[i]);
}
for(i=0;i < n-1;i++)
{
for(j=i+1;j < n;j++)
{
if(strcmp(str[i],str[j]) > 0)
{
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
}
printf("\nIn Lexicographical order: \n");
for(i=0;i < n;i++)
puts(str[i]);
getch();
return 0;
}
getch(); return 0;
}
3. Write C Program to find diameter, circumference and area of circle using User defined
Function.
#include <stdio.h>
#include<conio.h>
#include <math.h>
int main() {
// Declare variables
float radius, diameter, circumference, area;
return 0;
}
4. Write C program to convert centimeter to meter and kilometer using User defined
Function.
#include <stdio.h>
#include<conio.h>
int main() {
meter = cm_to_meter(cm);
km = cm_to_kilometer(cm);
return 0;
}
5. Write C program to convert temperature from degree Celsius to Fahrenheit using UDF.
#include <stdio.h>
#include<conio.h>
int main()
{
float celsius, fahrenheit;
printf("Enter the temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit = celsiusToFahrenheit(celsius);
printf("The temperature in Fahrenheit is: %f\n", fahrenheit);
return 0;
}
int main()
{
int Number, Sum = 0;
}
Explanation
In the next line, We are calculating the Sum of the series 1²+2²+3²+4²+5² using above formula
7. Write C Program to find maximum and minimum element in array using UDF.
#include<stdio.h>
#include<conio.h>
getch();
return 0;
}
Structure programme
1. Write a C program that creates structure of an array of structures that stores information
of 5 students and prints it.
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct student
{
int rollno;
struct StudentData
{
int studid;
char studname[50];
int total_marks;
};
int main()
{
int n, i;
3. Write a C program that creates structure Employee with id, name and salary. Enter data
of five employees. Display data of those employees whose salary is more than 5000.
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct employee
{
int eid;
char empname[10];
int salary;
};
int main()
{
int i,n,high;
struct employee emp[10];
clrscr();
printf("Enter Total number of Records:");
scanf("%d",&n);
printf("Enter Records of %d students",n);
for(i=0;i<n;i++)
{
printf("\nEnter Employee Name:");
scanf("%[^\n]s",&emp[i].empname);
printf("\nEnter Employee ID:");
scanf("%d",&emp[i].eid);
printf("\nEnter Employee Salary:");
scanf("%d",&emp[i].salary);
4. Create a C structure, volume with fields: liter and millilitre. Read the value of two volumes
and add them, if the value of millilitre is more than 1000 then add it to liter value. (APRIL-
2022)
#include <stdio.h>
struct volume
{
int liter;
int milliliter;
};
int main()
{
struct volume v1, v2, result;
int total_ml;
printf("Enter the value of first volume in liter and milliliter separated by a space: ");
scanf("%d %d", &v1.liter, &v1.milliliter);
printf("Enter the value of second volume in liter and milliliter separated by a space: ");
scanf("%d %d", &v2.liter, &v2.milliliter);
return 0;
}
5. Write C program to check the given string is palindrome or not using UDF.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void chkpalin()
{
char s1[100],s2[100];
clrscr();
if(!strcmp(s1,s2))
printf("string is palindrome");
else
printf("string is not palindrome");
}
int main()
{
chkpalin();
getch();
return 0;
}
Unit-2-3(Python Programming)
Do the following Practice programmes in Python Programming.
1. Write a Python program to display an average of 3 inputted numbers.
# Get the input from the user.
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
average = (num1 + num2 + num3) / 3
print("The average of the three numbers is:", average)
length = 5
width = 8
result = area_simple_multiplication(length, width)
print(f"Area of Rectangle: {result}")
celsius = 20
fahrenheit = celsius_to_fahrenheit(celsius)
print(fahrenheit)
8. Write a python function which accept Fahrenheit and convert into Celsius.
C= (F-32) * 5 / 9
def fahrenheit_to_celsius(fahrenheit):
celsius = (5 * (fahrenheit - 32)) / 9.0
return celsius
fahrenheit = 100
celsius = fahrenheit_to_celsius(fahrenheit)
print(f"The temperature in Celsius is: {celsius:.2f}°C")
9. Write a Python program to check whether the entered alphabet is vowel or consonant.
letter = input("Enter an alphabet: ")
# Check if the alphabet is a vowel.
if letter in ('a', 'e', 'i', 'o', 'u'):
print(letter, "is a vowel.")
else:
print(letter, "is a consonant.")
10.Write a python UDF to calculate the sum of digits of the entered number.(No:1234
Ans=10)
num = input("Enter Number: ")
sum = 0
for i in num:
sum = sum + int(i)
print(sum)
13.Write a Python program to prints all letters except 'a' and 't'
# prints all letters except 'a' and 't'
i=0
str1 = 'SDJ International College'
while i < len(str1):
if str1[i] == 'a' or str1[i] == 't':
i += 1
continue
print('Current Letter :', str1[i])
i += 1
print(max_of_two(3, 5))
print(max_of_two(10, -2))
15.Write a Python program to check whether a character is alphabet or not.
print("Enter a Character: ")
c = input()
if c>='a' and c<='z':
print("\nIt is an alphabet")
elif c>='A' and c<='z':
print("\nIt is an alphabet")
else:
print("\nIt is not an alphabet!")
16.Write a Python program to check whether a character is uppercase or lowercase
alphabet.
string = 'GEEKSFORGEEKS' # Define a string containing only uppercase letters
print(string.isupper()) # Check if all characters in the string are uppercase and print the result
string = 'GeeksforGeeks'# Define a string with a mix of uppercase and lowercase letters
Output:
True
False
17.Write a Python program to input marks of five subjects Physics, Chemistry, Biology,
Mathematics and Computer. Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
rno=input("Enter Student Roll Number :")
sname=input("Enter Student Name :")
sub1=int(input("Enter marks of Physics: "))
sub2=int(input("Enter marks of Chemistry: "))
sub3=int(input("Enter marks of Biology: "))
sub4=int(input("Enter marks of Mathematics: "))
sub5=int(input("Enter marks of Computer: "))
tot=sub1 + sub2 + sub3 + sub4 + sub5
avg=tot / 5
print("Student Roll No is : ",rno)
print("Student Name is :",sname)
print("Marks of Physics:",sub1)
print("Marks of Chemistry:",sub2)
print("Marks of Biology:",sub3)
print("Marks of Mathematics:",sub4)
print("Marks of Computer:",sub5)
print("Total Marks : ",tot)
print("Percentage Marks : ",avg)
if(avg>=90):
print("Grade: A")
elif(avg>=80):
print("Grade: B")
elif(avg>=70):
print("Grade: C")
elif(avg>=60):
print("Grade: D")
elif(avg>=40):
print("Grade: E")
else:
print("Grade: F")
18.Write a Python program to input basic salary of an employee and calculate its Gross
salary according to following:
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary <= 20000 : HRA = 25%, DA = 90%
Basic Salary > 20000 : HRA = 30%, DA = 95%
basic_salary = float(input("Enter basic salary: "))
Python Loops:
1. Write a Python program to print the multiplication table of a given number using for
loop.
4. Write a Python program to calculate the factorial of a given number using for loop.
def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result
# Print the 'final_list,' which contains elements from both 'list1' and 'list2'
print(final_list)
4. Write a python code to print the sum of the given list in python.
total = 0
Input: [12, 15, 3, 10]
list1 = [11, 5, 17, 18, 23]
Output: 40
for i in range(0, len(list1)):
total = total + list1[i]
print("Sum of all elements in given list: ", total)
vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
result = ""
for i in range(len(string)):
if string[i] not in vowels:
result = result + string[i]
Extra Practice:
#Use the for loop to iterate a dictionary in the Python script.
capitals = {"USA":"Washington D.C.", "France":"Paris", "India":"New Delhi"}
names=['Deepak','Reema','John','Deepak','Munna','Reema','Deepak','Amit','John','Reema']
nameset=set(names)
print(nameset)