0% found this document useful (0 votes)
15 views11 pages

1.PS Journal2.

The document contains a series of C programming exercises for a programming skills course, including tasks such as replacing characters in a string, counting digits and special characters, managing student records, calculating employee salaries, and comparing dates. Each task includes a description, sample code, and expected output. The exercises are designed to enhance programming skills through practical applications of C language features.

Uploaded by

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

1.PS Journal2.

The document contains a series of C programming exercises for a programming skills course, including tasks such as replacing characters in a string, counting digits and special characters, managing student records, calculating employee salaries, and comparing dates. Each task includes a description, sample code, and expected output. The exercises are designed to enhance programming skills through practical applications of C language features.

Uploaded by

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

F.Y.B.C.

A SEM-2 PROGRAMMING SKILLS DIV-1


JOURNAL-2
Q1 Create a C program that accepts a string and replaces all the odd
number characters with their place position using a UDF (User
Defined Function).
Input: SURAT
ANS //NAME:- KRISHNA ADIDRAVIDA
//ROLLNO:- 1
//DATE:-16/01/2025

#include <stdio.h>
#include <string.h>

void replaceOddPositionChars(char str[]);

int main() {
char str[100];

printf("Enter a string: ");


scanf("%s", str);

replaceOddPositionChars(str);

printf("Modified string: %s\n", str);

return 0;
}

void replaceOddPositionChars(char str[]) {


int i;
int len = strlen(str);

for(i = 0; i < len; i++) {


if((i + 1) % 2 != 0) {
str[i] = (i + 1) + '0';
}
}
}

*/ OUTPUT

Enter a string: KRISHNA


Modified string: 1R3S5N7

*/

1-ADIDRAVIDA KRISHNA 1
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2
Q2 Write a program to input a string and pass it to a UDF to count
the number of digits and special characters.
Input: Hello123@World!
ANS //NAME:- KRISHNA ADIDRAVIDA
//ROLLNO:- 1
//DATE:-16/01/2025

#include <stdio.h>
#include <ctype.h>

void countDigitsAndSpecials(char str[], int *digits, int *specials);

int main() {
char str[100];
int digits = 0, specials = 0;

printf("Enter a string: ");


scanf("%s", str);

countDigitsAndSpecials(str, &digits, &specials);


printf("Digits: %d, Special Characters: %d\n", digits, specials);
return 0;
}
void countDigitsAndSpecials(char str[], int *digits, int *specials) {
for (int i = 0; str[i] != '\0'; i++) {
if (isdigit(str[i])) {
(*digits)++;
} else if (!isalnum(str[i])) {
(*specials)++;
}
}
}

*/ OUTPUT
Enter a string: KRISHNA@123
Digits: 3, Special Characters: 1
*/

1-ADIDRAVIDA KRISHNA 2
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2
Q3 Write a program to create a structure of five student with a
member name, roll no, 3 subject marks calculate total and
percentage with formula and display it with proper format.
ANS //NAME:- KRISHNA ADIDRAVIDA
//ROLLNO:- 1
//DATE:-16/01/2025

#include <stdio.h>

struct Student {
char name[50];
int rollNo;
int marks[3];
int total;
float percentage;
};

int main() {
struct Student students[5];

for (int i = 0; i < 5; i++) {


printf("Enter details for Student %d\n", i + 1);
printf("Name: ");
scanf("%s", students[i].name);
printf("Roll No: ");
scanf("%d", &students[i].rollNo);

students[i].total = 0;
printf("Enter 3 subject marks: ");

for (int j = 0; j < 3; j++) {


scanf("%d", &students[i].marks[j]);
students[i].total += students[i].marks[j];
}

students[i].percentage = students[i].total / 3.0;


}

printf("\n%-10s %-10s %-15s %-15s\n", "Name", "Roll No", "Total Marks",


"Percentage");
for (int i = 0; i < 5; i++) {
printf("%-10s %-10d %-15d %-15.2f\n", students[i].name, students[i].rollNo,
students[i].total, students[i].percentage);
}

return 0;
}

1-ADIDRAVIDA KRISHNA 3
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2
*/ OUTPUT

Name Roll No Total Marks Percentage


KRISHNA 1 166 55.33
KARTIK 34 161 53.67
ROHIT 61 121 40.33
NAKUL 54 178 59.33
CHETAN 56 136 45.33

*/

1-ADIDRAVIDA KRISHNA 4
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2
Q4 Write a C program to create a structure employee with a member
employee I’d, employee name and basic salary.
Read employee information from user and calculate net salary
where net salary =basic salary +HRA+DA-PF. HRA is 10% of
basis salary, DA is 50% of basic salary and PF is 20% of basic
salary.
ANS //NAME:- KRISHNA ADIDRAVIDA
//ROLLNO:- 1
//DATE:-16/01/2025

#include <stdio.h>

struct Employee {
int id; char name[50];
float basicSalary;
float netSalary;
};

int main() {
struct Employee emp;

printf("Enter Employee ID: ");


scanf("%d", &emp.id); printf("Enter Employee Name: ");
scanf("%s", emp.name); printf("Enter Basic Salary: ");
scanf("%f", &emp.basicSalary);

float HRA = 0.1 * emp.basicSalary;


float DA = 0.5 * emp.basicSalary;
float PF = 0.2 * emp.basicSalary;

emp.netSalary = emp.basicSalary + HRA + DA - PF; printf("\nEmployee


Details:\n");

printf("ID: %d\nName: %s\nNet Salary: %.2f\n", emp.id, emp.name,


emp.netSalary);

return 0;
}

*/ OUTPUT

Employee Details:
ID: 1
Name: KRISHNA
Net Salary: 70000.00
*/

1-ADIDRAVIDA KRISHNA 5
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2
Q5 Write a C program to create user define recursive function to find
factorial of inputted number.
ANS //NAME:- KRISHNA ADIDRAVIDA
//ROLLNO:- 1
//DATE:-16/01/2025

#include <stdio.h>

int factorial(int n);

int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);

printf("Factorial of %d is %d\n", num, factorial(num));


return 0;
}
int factorial(int n)
{
if (n == 0 || n == 1) return 1;
return n * factorial(n - 1);
}

*/ OUTPUT
Enter a number: 10
Factorial of 10 is 3628800
*/

1-ADIDRAVIDA KRISHNA 6
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2
Q6 Write a program that creates a structure "Department" with
fields: dept_id, dept_name, and number_of_employees and
perform following operation
 Input data of 3 departments.
 Display the department names that have more than 50
employees.
ANS //NAME:-KRISHNA ADIDRAVIDA
//ROLLNO:- 1
//DATE:-16/01/2025

#include <stdio.h>
#include <string.h>

struct Department {
int id;
char name[50];
int numEmployees;
};

int main() {
struct Department depts[3];
for (int i = 0; i < 3; i++) {
printf("Enter details for Department %d\n", i + 1);
printf("ID: ");
scanf("%d", &depts[i].id);
getchar();
printf("Name: ");
fgets(depts[i].name, sizeof(depts[i].name), stdin);
depts[i].name[strcspn(depts[i].name, "\n")] = 0;
printf("Number of Employees: ");
scanf("%d", &depts[i].numEmployees);
}

printf("\nDepartments with more than 50 employees:\n");


for (int i = 0; i < 3; i++) {
if (depts[i].numEmployees > 50) {
printf("%s\n", depts[i].name);
}
}

return 0;
}

*/ OUTPUT

1-ADIDRAVIDA KRISHNA 7
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2
Departments with more than 50 employees:
ID: 2, Name: ROHIT, Employees: 65
*/

Q7 Create a C program that defines a structure "Date" with fields:


day, month, and year. Input 2 dates and compare them to check
which one is earlier.

1-ADIDRAVIDA KRISHNA 8
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2
ANS //NAME:-KRISHNA ADIDRAVIDA
//ROLLNO:- 1
//DATE:-16/01/2025

#include<stdio.h>

struct Date {
int day, month, year;
};

int compareDates(struct Date d1, struct Date d2) {


if (d1.year < d2.year)
return -1;
else if (d1.year > d2.year)
return 1;
else {
if (d1.month < d2.month)
return -1;
else if (d1.month > d2.month)
return 1;
else {
if (d1.day < d2.day)
return -1;
else if (d1.day > d2.day)
return 1;
else
return 0;
}
}
}

int main() {
struct Date date1, date2;

printf("Enter first date (dd mm yyyy): ");


scanf("%d %d %d", &date1.day, &date1.month, &date1.year);

printf("Enter second date (dd mm yyyy): ");


scanf("%d %d %d", &date2.day, &date2.month, &date2.year);

int result = compareDates(date1, date2);


if (result < 0)
printf("First date is earlier.\n");
else if (result > 0)
printf("Second date is earlier.\n");
else
printf("Both dates are the same.\n");

return 0;

1-ADIDRAVIDA KRISHNA 9
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2
}

*/ OUTPUT
Enter first date (dd mm yyyy): 17 05 2006
Enter second date (dd mm yyyy):01 02 2009
First date is earlier.

*/

1-ADIDRAVIDA KRISHNA 10
F.Y.B.C.A SEM-2 PROGRAMMING SKILLS DIV-1
JOURNAL-2

1-ADIDRAVIDA KRISHNA 11

You might also like