0% found this document useful (0 votes)
35 views14 pages

PP1 FG

The document contains C code for multiple test cases. The first test case encodes a message by replacing characters with other characters or symbols based on conditions. The second test case calculates wages for two employees based on their name, hours worked and a base wage. The third test case merges and sorts two integer arrays. The last test case checks if a number is a lucky number based on a digit checking algorithm.

Uploaded by

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

PP1 FG

The document contains C code for multiple test cases. The first test case encodes a message by replacing characters with other characters or symbols based on conditions. The second test case calculates wages for two employees based on their name, hours worked and a base wage. The third test case merges and sorts two integer arrays. The last test case checks if a number is a lucky number based on a digit checking algorithm.

Uploaded by

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

Name=Rajas anakkachery

Reg no=21BCE2224
PP-1

CODE
#include <stdio.h>

#include <string.h>

void encodeMessage(char *input);

int main() {

char input[20];

scanf("%s", input);

encodeMessage(input);
return 0;

void encodeMessage(char *input) {

int firstDigit = input[0] - '0';

int lastDigit = input[strlen(input) - 1] - '0';

if (firstDigit % 2 != 0 && lastDigit % 2 != 0) {

printf("X");

else if (firstDigit % 2 == 0 && lastDigit % 2 == 0) {

printf("Y");

for (int i = 1; i < strlen(input)-1; i++) {

switch (input[i]) {

case '0':

printf("Z");

break;

case '1':

printf("@");

break;

case '2':

printf("#");

break;

case '3':

printf("$");
break;

case '4':

printf("%%");

break;

case '5':

printf("^");

break;

case '6':

printf("&");

break;

case '7':

printf("*");

break;

case '8':

printf("(");

break;

case '9':

printf(")");

break;

default:

break;

if (firstDigit % 2 != 0 && lastDigit % 2 != 0) {

printf("X");

else if (firstDigit % 2 == 0 && lastDigit % 2 == 0) {


printf("Y");

printf("\n");

TESTCASE

CODE

#include <stdio.h>

int main() {

char name1[50];

int hoursWorked1;

const int baseWage = 500;


char name2[50];

int hoursWorked2;

int totalWage=0;

scanf("%s", name1);

scanf("%d", &hoursWorked1);

scanf("%s", name2);

scanf("%d", &hoursWorked2);

printf("%s\n",name1);

if (hoursWorked1<5 || hoursWorked1>8){

printf("not applicable\n");

else if(hoursWorked1==5){

printf("%d\n",baseWage);

else if(hoursWorked1==6){

totalWage=550;

printf("%d\n",totalWage);

else if(hoursWorked1==7){

totalWage=600;

printf("%d\n",totalWage);
}

else if(hoursWorked1==8){

totalWage=650;

printf("%d\n",totalWage);

printf("%s\n",name2);

if (hoursWorked2<5 || hoursWorked2>8){

printf("not applicable\n");

else if(hoursWorked2==5){

printf("%d\n",baseWage);

else if(hoursWorked2==6){

totalWage=550;

printf("%d\n",totalWage);

else if(hoursWorked2==7){

totalWage=600;

printf("%d\n",totalWage);

else if(hoursWorked2==8){

totalWage=650;

printf("%d\n",totalWage);

return 0;

}
TESTCASE

CODE

#include <stdio.h>

void mergeArrays(int arr1[], int size1, int arr2[], int size2, int result[]);

void reverseArray(int arr[], int size);

void sortArray(int arr[], int size);

int main() {

int storage1[5] = {43, 56,12,65};

int storage2[5] = {12, 43, 56, 65};

int mergedStorage[10];
mergeArrays(storage1, 5, storage2, 5, mergedStorage);

sortArray(mergedStorage, 10);

printf("Elements After Merging ");

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

printf("%d ", storage1[i]);

printf("\nThe sorted elements are ");

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

printf("%d ", storage2[i]);

return 0;

void mergeArrays(int arr1[], int size1, int arr2[], int size2, int result[]) {

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

result[i] = arr1[i];

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

result[size1 + i] = arr2[size2 - i - 1];

}
void reverseArray(int arr[], int size) {

int start = 0;

int end = size - 1;

while (start < end) {

int temp = arr[start];

arr[start] = arr[end];

arr[end] = temp;

start++;

end--;

void sortArray(int arr[], int size) {

for (int i = 0; i < size - 1; i++) {

for (int j = 0; j < size - i - 1; j++) {

if (arr[j] > arr[j + 1]) {

int temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

}
TESTCASE

CODE

#include <stdio.h>

int main() {
long long dob,originalDob;

scanf("%lld", &dob);

if (dob < 10000000 || dob > 99999999) {

printf("Invalid Input\n");

return 0;

originalDob = dob;

int oddSum = 0, evenSum = 0;

int position = 1;

while (dob > 0) {

int digit = dob % 10;

if (position % 2 == 1) {

oddSum += digit;

} else {

evenSum += digit;

dob /= 10;

position++;

int result = (oddSum * 3) + evenSum;


if (result % 10 == 0) {

printf("Lucky number\n");

} else {

printf("%lld,\n",originalDob);

printf("Not a Lucky Number\n");

return 0;

TESTCASE
CODE

#include <stdio.h>

float calculateSimpleInterest(float principal, int years, char gender, char isSeniorCitizen) {

float rateOfInterest;

if (gender == 'm' && isSeniorCitizen == 'y') {

rateOfInterest = 0.12;

} else if (gender == 'f' && isSeniorCitizen == 'y') {

rateOfInterest = 0.15;

} else {

rateOfInterest = 0.10;

// Calculate and return simple interest

return principal * rateOfInterest * years;

int main() {
float principal;

int years;

char gender, isSeniorCitizen;

scanf("%f", &principal);

scanf("%d", &years);

scanf(" %c", &gender);

scanf(" %c", &isSeniorCitizen);

int interest = (int)calculateSimpleInterest(principal, years, gender, isSeniorCitizen);

printf("%d", interest);

return 0;

TESTCASE

You might also like