KPIT Yet To Onboard Assignment Week-3
KPIT Yet To Onboard Assignment Week-3
Q1
CODE
#include<stdio.h>
int main()
{
char str1[20];
char str2[20];
char str3[20];
char str4[20];
scanf("%s%s%s%s",&str1,str2,str3,str4);
printf("Str1 = %s\n",str1);
printf("Str2 = %s\n",str2);
printf("Str3 = %s\n",str3);
printf("Str4 = %s\n",str4);
return 0;
}
OUTPUT
Enter the string :
ALICE GIVE HIM SOMETHING
Str1 = ALICE
Str2 = GIVE
Str3 = HIM
Str4 = SOMETHING
Q2
CODE
#include <stdio.h>
#include <string.h>
int main() {
char isbn[11];
int sum = 0;
if (strlen(isbn) != 10) {
printf("Invalid ISBN length. Please enter exactly 10 digits.\
n");
return 1;
}
return 0;
}
OUTPUT
Enter the 10-digit ISBN: 1234567890
The ISBN number is incorrect.
Q3
CODE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int sum = 0;
for (int i = 0; i < 16; i++) {
int digit = ccNumber[i] - '0';
if ((i % 2) == 0) {
digit *= 2;
if (digit > 9) {
digit -= 9;
}
}
sum += digit;
}
int main() {
char ccNumber[17];
if (isValidCreditCard(ccNumber)) {
printf("The credit card number is valid.\n");
} else {
printf("The credit card number is invalid.\n");
}
return 0;
}
OUTPUT
Enter the 16-digit credit card number: 1234567890123456
The credit card number is invalid.
CODE
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char sentence[81];
char result[81];
int j = 0;
return 0;
}
OUTPUT
Enter a sentence (max 80 characters): HELLO MY NAME IS
NISHEETH
Sentence after removing vowels: HLL MY NMS NSHTH
Q2
CODE
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char sentence[1001];
char result[1001];
int i = 0, j = 0, k = 0;
char word[101];
k = 0;
while (isspace(sentence[i])) {
result[j++] = sentence[i++];
}
if (!isTheWord(word)) {
k = 0;
while (word[k] != '\0') {
result[j++] = word[k++];
}
}
}
result[j] = '\0';
return 0;
}
OUTPUT
Enter a sentence (max 1000 characters): JUPITER IS THE LARGST
PLANET
Sentence after removing 'the': JUPITER IS LARGST PLANET
Q3
CODE
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
char str[100];
char word[100] = "";
char result[100] = "";
printf("Enter the string : \n");
fgets(str,80,stdin);
int j=0,a=0;
int length = sizeof(str);
if(ch!=' ')
{
word[j] = ch;
j++;
}
else
{
int len = sizeof(word);
char x = word[0];
x=toupper(x);
result[a++]=x;
result[a++]='.';
j=0;
}
}
strcat(result,word);
return 0;
}
OUTPUT
Enter the string :
Nisheeth Kumar Tripathi
The string is :N.K.Tripathi
Q4
CODE
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
char str[100];
fgets(str,80,stdin);
printf("Enter the string : \n");
int j=0;
int length = sizeof(str);
if(isVowel(str[i])&& isVowel(str[i+1]))
{
j++;
}
}
printf("The number of occureences of successive vowels is %d",j);
return 0;
}
OUTPUT
Enter the string :
Read my application thoroughly
The number of occurrences of successive vowels is 3
Q5
CODE
#include <stdio.h>
#include <string.h>
void convertToWords(int num, char *result);
void numberToWords(int num, char *result);
void appendAnd(char *result);
int main() {
int num;
char result[500] = "";
if (num == 0) {
printf("Zero\n");
return 0;
}
convertToWords(num, result);
printf("%s\n", result);
return 0;
}
if (num > 0) {
if (strlen(result) != 0) {
strcat(result, "and ");
}
numberToWords(num, result);
}
}
OUTPUT
Enter an integer (up to nine digits): 326384
Six Thousand Three Hundred and Eighty Four
Chapter-17: Structures
Q1
CODE
#include <stdio.h>
#include <string.h>
int main() {
students[1].roll_number = 2;
strcpy(students[1].name, "Bob");
strcpy(students[1].department, "Mechanical Engineering");
strcpy(students[1].course, "B.Tech");
students[1].year_of_joining = 2020;
students[2].roll_number = 3;
strcpy(students[2].name, "Charlie");
strcpy(students[2].department, "Electrical Engineering");
strcpy(students[2].course, "B.Tech");
students[2].year_of_joining = 2021;
// Test functions
int year_to_search = 2021;
printf("Students who joined in %d:\n", year_to_search);
printStudentsByYear(students, count, year_to_search);
int roll_number_to_search = 2;
printf("\nDetails of student with roll number %d:\n",
roll_number_to_search);
printStudentByRollNumber(students, count, roll_number_to_search);
return 0;
}
OUTPUT
Students who joined in 2021:
Alice
Charlie
Q2
CODE
#include <stdio.h>
#include <string.h>
struct bank_account
{
int acc_number;
char name[50];
double balance;
};
}
}
return;
}
}
printf("Account number %d not found.\n", trans);
}
int main()
{
struct bank_account customer[200];
int num;
printf("Enter the number of customer : ");
scanf("%d",&num);
for(int i = 0; i<num; i++)
{
printf("\nEnter the details of the customer number : %d ",
i+1 );
if(code == 1)
{
int choice;
printf("\nEnter the Account number : ");
scanf("%d",&trans_acc_number);
printf("\nPress 1 for WITHDRAWL \nPress 2 for DEPOSIT \nEnter
the number : ");
scanf("%d",&choice);
double amount;
printf("\nEnter the amount : ");
scanf("%lf",&amount);
processTransaction(customer,num,trans_acc_number,amount,choice);
}
return 0;
}
OUTPUT
Enter the number of customer : 3
Q3
CODE
#include <stdio.h>
#include <string.h>
struct part {
char serial_number[4];
int year_of_manufacture;
char material[30];
int quantity_manufactured;
};
int main() {
struct part parts[100];
int count = 0;
int choice;
while (1) {
printf("1. Add Part\n");
printf("2. Retrieve Parts with Serial Numbers between BB1 and
CC6\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice == 3) break;
switch (choice) {
case 1:
if (count < 100) {
printf("Enter serial number (e.g., AA0): ");
scanf("%s", parts[count].serial_number);
printf("Enter year of manufacture: ");
scanf("%d", &parts[count].year_of_manufacture);
printf("Enter material: ");
scanf("%s", parts[count].material);
printf("Enter quantity manufactured: ");
scanf("%d", &parts[count].quantity_manufactured);
count++;
} else {
printf("Maximum number of parts reached.\n");
}
break;
case 2:
retrieveParts(parts, count);
break;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}
OUTPUT
1. Add Part
2. Retrieve Parts with Serial Numbers between BB1 and CC6
3. Exit
Enter your choice: 1
Enter serial number (e.g., AA0): BB2
Enter year of manufacture: 2021
Enter material: STEEL
Enter quantity manufactured: 456
1. Add Part
2. Retrieve Parts with Serial Numbers between BB1 and CC6
3. Exit
Enter your choice: 2
Parts with Serial Numbers between BB1 and CC6:
Serial Number: BB2, Year of Manufacture: 2021, Material: STEEL,
Quantity Manufactured: 456
1. Add Part
2. Retrieve Parts with Serial Numbers between BB1 and CC6
3. Exit
Enter your choice: 3
Q4
CODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct cricketer {
char name[50];
int age;
int test_matches;
float average_runs;
};
int main() {
int num;
printf("Enter the number of cricketer : \n");
scanf(" %d",&num);
struct cricketer cricketers[num];
int i;
return 0;
}
OUTPUT
Enter the number of cricketer :
3
Enter details for cricketer 1
Name: NISHEETH
Age: 22
Number of test matches: 78
Average runs: 65.78
Enter details for cricketer 2
Name: SHIKHAR
Age: 23
Number of test matches: 67
Average runs: 45.90
Enter details for cricketer 3
Name: VISHU
Age: 23
Number of test matches: 77
Average runs: 66.78
Q5
CODE
#include <stdio.h>
#include <string.h>
struct date {
int day;
int month;
int year;
};
struct employee {
int code;
char name[50];
struct date joining_date;
};
int main() {
int n, i;
struct date current_date;
return 0;
}
OUTPUT
Enter the number of employees: 3
Enter details for employee 1
Code: 567
Name: NISHETH
Joining Date (dd mm yyyy): 12 12 2012
Enter details for employee 2
Code: 728
Name: SHIKHAR
Joining Date (dd mm yyyy): 23 12 2022
Enter details for employee 3
Code: 672
Name: VISHU
Joining Date (dd mm yyyy): 23 10 2010
Enter the current date (dd mm yyyy): 05 06 2024
Employees with tenure >= 3 years:
Name: NISHETH
Name: VISHU
Q6
CODE
#include <stdio.h>
#include <string.h>
struct library {
int accession_number;
char title[100];
char author[100];
float price;
int is_issued;
};
displayBooks(books, count);
}
int main() {
struct library books[MAX_BOOKS];
int count = 0;
int choice;
while (1) {
printf("\nLibrary Menu:\n");
printf("1. Add book information\n");
printf("2. Display book information\n");
printf("3. List all books of given author\n");
printf("4. List the title of book specified by accession
number\n");
printf("5. List the count of books in the library\n");
printf("6. List the books in the order of accession number\n");
printf("7. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addBook(books, &count);
break;
case 2:
displayBooks(books, count);
break;
case 3: {
char author[100];
printf("Enter author name: ");
scanf(" %[^\n]s", author);
listBooksByAuthor(books, count, author);
break;
}
case 4: {
int accession_number;
printf("Enter accession number: ");
scanf("%d", &accession_number);
listTitleByAccessionNumber(books, count,
accession_number);
break;
}
case 5:
printf("Total number of books: %d\n", countBooks(books,
count));
break;
case 6:
listBooksByAccessionOrder(books, count);
break;
case 7:
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}
OUTPUT
Library Menu:
1. Add book information
2. Display book information
3. List all books of given author
4. List the title of book specified by accession number
5. List the count of books in the library
6. List the books in the order of accession number
7. Exit
Enter your choice: 1
Enter accession number: 87394
Enter title: HOROR STOTY OF MAYA
Enter author: NISHEETH
Enter price: 3455.4534
Library Menu:
1. Add book information
2. Display book information
3. List all books of given author
4. List the title of book specified by accession number
5. List the count of books in the library
6. List the books in the order of accession number
7. Exit
Enter your choice: 1
Enter accession number: 79303
Enter title: TWISTY TALES
Enter author: ALICE
Enter price: 4239.4332
Library Menu:
1. Add book information
2. Display book information
3. List all books of given author
4. List the title of book specified by accession number
5. List the count of books in the library
6. List the books in the order of accession number
7. Exit
Enter your choice: 2
Accession Number: 87394
Title: HOROR STOTY OF MAYA
Author: NISHEETH
Price: 3455.45
Issued: No
Library Menu:
1. Add book information
2. Display book information
3. List all books of given author
4. List the title of book specified by accession number
5. List the count of books in the library
6. List the books in the order of accession number
7. Exit
Enter your choice: 3
Enter author name: NISHEETH
Title: HOROR STOTY OF MAYA
Library Menu:
1. Add book information
2. Display book information
3. List all books of given author
4. List the title of book specified by accession number
5. List the count of books in the library
6. List the books in the order of accession number
7. Exit
Enter your choice: 4
Enter accession number: 79303
Title: TWISTY TALES
Library Menu:
1. Add book information
2. Display book information
3. List all books of given author
4. List the title of book specified by accession number
5. List the count of books in the library
6. List the books in the order of accession number
7. Exit
Enter your choice: 5
Total number of books: 2
Library Menu:
1. Add book information
2. Display book information
3. List all books of given author
4. List the title of book specified by accession number
5. List the count of books in the library
6. List the books in the order of accession number
7. Exit
Enter your choice: 6
Accession Number: 79303
Title: TWISTY TALES
Author: ALICE
Price: 4239.43
Issued: No
Library Menu:
1. Add book information
2. Display book information
3. List all books of given author
4. List the title of book specified by accession number
5. List the count of books in the library
6. List the books in the order of accession number
7. Exit
Enter your choice: 7
Q7
CODE
#include <stdio.h>
struct date {
int day;
int month;
int year;
};
int main() {
struct date date1, date2;
if (compareDates(date1, date2) == 0) {
printf("The dates are equal.\n");
} else {
printf("The dates are not equal.\n");
}
return 0;
}
OUTPUT
Enter first date (dd mm yyyy): 10 10 2010
Enter second date (dd mm yyyy): 10 10 2010
The dates are equal.
Q1
CODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
char name[NAME_LENGTH];
int age;
};
int main() {
FILE *file;
struct student students[MAX_STUDENTS];
int count = 0;
fclose(file);
return 0;
}
OUTPUT
Name: Nisheeth, Age: 20
Name: Shikhar, Age: 22
Name: Vishwajeet, Age: 19
Q2
CODE
#include <stdio.h>
#include <ctype.h>
int main() {
FILE *sourceFile, *targetFile;
char ch;
return 0;
}
OUTPUT
Q3
CODE
#include <stdio.h>
int main() {
FILE *file1, *file2, *outputFile;
char line1[100], line2[100];
fclose(file1);
fclose(file2);
fclose(outputFile);
return 0;
}
OUTPUT
Merged lines from both files successfully!
Q6
CODE
#include <stdio.h>
#include <string.h>
struct date {
int d, m, y;
};
struct employee {
int empcode[6];
char empname[20];
struct date join_date;
float salary;
};
int main() {
FILE *inputFile, *outputFile;
struct employee records[10];
int numRecords;
numRecords = 0;
while (fscanf(inputFile, "%d %s %d %d %d %f",
&records[numRecords].empcode[0],
records[numRecords].empname,
&records[numRecords].join_date.d,
&records[numRecords].join_date.m,
&records[numRecords].join_date.y,
&records[numRecords].salary) == 6) {
++numRecords;
}
fclose(inputFile);
sort_by_join_date(records, numRecords);
fclose(outputFile);
return 0;
}
OUTPUT
Employee records sorted and written to sorted_employee_records.txt.
Q7
CODE
#include <stdio.h>
struct BloodDonor {
char name[20];
char address[40];
int age;
int bloodType;
};
int main() {
FILE *file;
struct BloodDonor donor;
fclose(file);
return 0;
}
OUTPUT
The output I was getting was incorrect
Q8
CODE
#include <stdio.h>
#include <stdlib.h>
int main() {
char studentNames[MAX_STUDENTS][50];
int numStudents, n;
fclose(file);
printf("Student names saved to student_names.txt.\n");
printf("Enter the value of n (1 to %d): ", numStudents);
scanf("%d", &n);
return 0;
}
OUTPUT
Enter the number of students: 4
Enter the names of 4 students:
Nisheeth
Shikhar
Vishu
Sani
Student names saved to student_names.txt.
Enter the value of n (1 to 4): 4
The 4th student name is: Sani
Q9
CODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
int rollNumber;
char name[50];
};
int main() {
FILE *masterFile, *transactionFile, *updatedFile;
struct Student students[100];
int numStudents = 0;
char operation;
int rollNumber;
char name[50];
fclose(masterFile);
fclose(transactionFile);
fclose(updatedFile);
printf("Updated student records saved to updated_students.txt.\n");
return 0;
}
OUTPUT
Q10
CODE
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
FILE *inputFile, *outputFile;
char word[100];
fclose(inputFile);
fclose(outputFile);
return 0;
}
OUTPUT
Q1
CODE
#include <stdio.h>
int main() {
unsigned short int num;
printf("Enter an unsigned 16-bit integer: ");
scanf("%hu", &num);
return 0;
}
OUTPUT
Enter an unsigned 16-bit integer: 564
Original number: 564
Swapped number: 13314
Q2
CODE
#include <stdio.h>
int main() {
unsigned char num;
printf("Enter an 8-bit number: ");
scanf("%hhu", &num);
return 0;
}
OUTPUT
Enter an 8-bit number: 65
Original number: 65
Swapped number: 20
Q3
CODE
#include <stdio.h>
int main() {
unsigned char num;
printf("Enter an 8-bit number: ");
scanf("%hhu", &num);
num |= 0xAA;
return 0;
}
OUTPUT
Enter an 8-bit number: 34
Modified number: 170
Q4
CODE
#include <stdio.h>
int main() {
unsigned char num;
printf("Enter an 8-bit number: ");
scanf("%hhu", &num);
return 0;
}
OUTPUT
Enter an 8-bit number: 533
Modified number: 1