Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Journal Format

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Programming Skills

Journal-1

1 Write a C program that accepts a string and replaces all the even
number characters with their place position using UDF.
Ans. Program Code:
#include <stdio.h>
#include <conio.h>
void replaceEvenChars(char *str)
{
int i = 0;
while (str[i] != '\0') {
if ((i + 1) % 2 == 0) {
str[i] = '0' + (i + 1);
}
i++;
}
}
void main() {
char str[100];
int i = 0;
printf("Enter a string: ");
while (1) {
str[i] = getch();
if (str[i] == '\r') {
str[i] = '\0';
break;
}
else
{
printf("%c", str[i]);
i++;
}
}
printf("\n");
replaceEvenChars(str);
printf("String with even positions replaced: %s\n", str);
getch();
}
Output:

Maheknaik(139)
pg. 1
Programming Skills
Journal-1
2 Write a program that input string. Pass string in User Defined Function
as parameter to count Total Consonants and vowels.
Ans Program code:
#include <stdio.h>
#include<conio.h>
void main()
{
char str[100];
int i, vowels, consonants;
i = vowels = consonants = 0;
printf("\n Please Enter any String : ");
gets(str);
while (str[i] != '\0')
{
if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' ||str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i]
== 'O' || str[i] == 'U')
{
vowels++;
}
else
consonants++;
i++;
}
printf("\n Number of Vowels in this String = %d", vowels);
printf("\n Number of Consonants in this String = %d", consonants);
getch();
}

Output:

3 Write a c program that creates structure Student with sid, sname, sem,
per (%).
 Input 5 Students
 Display those Student's name who have achieved more than

Maheknaik(139)
pg. 2
Programming Skills
Journal-1
70% in sem 3.

Ans Program code:


#include <stdio.h>
#include<conio.h>
#include <string.h>
struct Student
{
int sid;
char sname[50];
int sem;
float per;
};
void main()
{
struct Student students[5];
int i;
clrscr();
printf("Enter details for 5 students:\n");
for ( i = 0; i < 5; i++) {
printf("Student %d:\n", i + 1);
printf("Student ID: ");
scanf("%d", &students[i].sid);
printf(" Student Name: ");
scanf("%s", students[i].sname);
printf(" Semester: ");
scanf("%d", &students[i].sem);
printf(" Percentage: ");
scanf("%d", &students[i].per);
}
printf("\nStudents who achieved more than 70%% in sem 3:\n");
for ( i = 0; i < 5; i++)
{
if (students[i].sem == 3 )
{
printf("id:%d,sname:%s,semester:%d,percentage:%d\n",students[i].sid,students[i].sname,
students[i].sem,students[i].per);
}
if(students[i].per>70)
{
printf("id:%d,sname:%s,semester:%d,percentage:%d\
n",students[i].sid,students[i].sname,students[i].sem,students[i].per);
}
}
getch();
}

Output:

Maheknaik(139)
pg. 3
Programming Skills
Journal-1

4 Write a program that creates structure Employee with id, name and
Maheknaik(139)
pg. 4
Programming Skills
Journal-1
salary. Enter data of five Employees. Display data of those employees
whose salary is less than 15,000.
Ans Program code:
#include <stdio.h>
#include<conio.h>
struct Employee
{
int id;
char name[40];
float salary;
};
void main()
{
struct Employee employees[5];
int i;
clrscr();
printf("Enter details of 5 employees:\n");
for (i = 0; i < 5; i++) {
printf("Employee %d:\n", i+1);
printf("ID: ");
scanf("%d", &employees[i].id);
printf("Name: ");
scanf("%s", employees[i].name);
printf("Salary: ");
scanf("%f", &employees[i].salary);

}
printf("\nEmployees with Salary Less than 15000:\n");
for (i = 0; i < 5; i++)
{
if(employees[i].salary<15000)
{
printf("ID: %d, Name: %s, Salary: %d\n",employees[i].id, employees[i].name,employees[i].salary);
}
getch();
}

}
getch();
}

Output:

Maheknaik(139)
pg. 5
Programming Skills
Journal-1

Maheknaik(139)
pg. 6
Programming Skills
Journal-1
5 Create a C structure, volume with fields: litter and millilitre. Read the
value of two volumes and add them, if the value of millilitre is more than
1000 then add it to litter value.
Program code:

#include <stdio.h>
#include<conio.h>
struct Employee {
int id;
char name[40];
float salary;
};

void main()
{
struct Employee employees[5];
int i;
clrscr();
printf("Enter details of 5 employees:\n");
for (i = 0; i < 5; i++) {
printf("Employee %d:\n", i+1);
printf("ID: ");
scanf("%d", &employees[i].id);
printf("Name: ");
scanf("%s", employees[i].name);
printf("Salary: ");
scanf("%d", &employees[i].salary);
}
printf("\nEmployees with Salary Less than 15000:\n");
for (i = 0; i < 5; i++)
{
if(employees[i].salary<15000)
{
printf("ID: %d, Name: %s, Salary: %d\n",employees[i].id, employees[i].name,employees[i].salary);
}
}
getch();
}

Output:

Maheknaik(139)
pg. 7
Programming Skills
Journal-1

6 Write a python program that performs following:

Maheknaik(139)
pg. 8
Programming Skills
Journal-1
1) Print length of string
2) Concatenate two strings
3) Reverse the string using slicing

Ans Program code:


1)my_string="hello,world!"
print(len(my_string))

2)string1="hello"
string2="world"
concatenated_string=string1+" "+string2
print(concatenated_string)

3)original_string = "Hello, World!"


reversed_string = original_string[::-1]
print(reversed_string)

Output:

7 Create a python list and perform the following operation:


1) Sort the list
Maheknaik(139)
pg. 9
Programming Skills
Journal-1
2) Display sum of the all elements of the list
3) Display last element of the list

Ans Program code:

list = [9, 3, 6, 1, 8, 2, 4, 5, 7]

1)list.sort()
print("Sorted List:",list)

2)sum_of_elements = sum(list)
print("Sum of all elements:", sum_of_elements)

3)last_element = list[-1]
print("Last element of the list:", last_element)

Output:

8 Write Python code to print the sum of the given list in Python.
Ans Program code:

def print_list_sum(input_list):
list_sum = sum(input_list)
print("The sum of the list is:", list_sum)

Maheknaik(139)
pg. 10
Programming Skills
Journal-1

given_list = [1, 2, 3, 4, 5]
print_list_sum(given_list)

Output:

9 Write a python program that store characters of a word as list elements


and removes vowels from the list.
Ans def remove_vowels(word):
vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
word_list = list(word)
filtered_list = [char for char in word_list if char not in vowels]
return filtered_list
Maheknaik(139)
pg. 11
Programming Skills
Journal-1

word = input("Enter a word: ")


result = remove_vowels(word)
print("Word without vowels:", ''.join(result))

Output:

10 Write a Python program that accepts input as marks 30 of 3 subjects for


each student.
 Display total marks, percentage and grade (if per > 70 then
grade DIST, per > 60 then grade FIRST, per > 50 then grade
SECOND, per > 40 then grade PASS) of each student

Ans Program code:

Maheknaik(139)
pg. 12
Programming Skills
Journal-1

def calculate_grade(percentage):
if percentage > 70:
return "DIST"
elif percentage > 60:
return "FIRST"
elif percentage > 50:
return "SECOND"
elif percentage > 40:
return "PASS"
else:
return "FAIL"

def calculate_result(marks):
total_marks = sum(marks)
percentage = (total_marks / (len(marks) * 100)) * 100
grade = calculate_grade(percentage)
return total_marks, percentage, grade

num_students = int(input("Enter the number of students: "))

for i in range(num_students):
print(f"\nStudent {i+1}:")
marks = []

for j in range(3):
subject_marks = int(input(f"Enter marks for subject {j+1}: "))
marks.append(subject_marks)

total_marks, percentage, grade = calculate_result(marks)

print(f"Total Marks: {total_marks}")


print(f"Percentage: {percentage}%")
print(f"Grade: {grade}")

Output:

Maheknaik(139)
pg. 13
Programming Skills
Journal-1

Maheknaik(139)
pg. 14

You might also like