Journal Format
Journal Format
Journal Format
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.
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
Maheknaik(139)
pg. 8
Programming Skills
Journal-1
1) Print length of string
2) Concatenate two strings
3) Reverse the string using slicing
2)string1="hello"
string2="world"
concatenated_string=string1+" "+string2
print(concatenated_string)
Output:
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:
Output:
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
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)
Output:
Maheknaik(139)
pg. 13
Programming Skills
Journal-1
Maheknaik(139)
pg. 14