#include <stdio.
h>
// Function to print the array
void printArray(const int arr[], int n) {
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}
// Function to multiply each element of the array by 2
void multiplyArray(int arr[], int n) {
for (int i = 0; i < n; i++)
arr[i] *= 2;
}
// Function to reverse the array
void reverseArray(int arr[], int n) {
for (int i = 0; i < n / 2; i++) {
int temp = arr[i];
arr[i] = arr[n - i - 1];
arr[n - i - 1] = temp;
}
}
int main() {
int arr[] = {2, 3, 5, 7, 11};
int n = sizeof(arr) / sizeof(arr[0]);
// Print the original array
printf("Array before: ");
printArray(arr, n);
// Multiply the array by 2 and print the result
multiplyArray(arr, n);
printf("After multiplication by 2: ");
printArray(arr, n);
// Reverse the array and print the result
reverseArray(arr, n);
printf("After reversing: ");
printArray(arr, n);
return 0;
}
#include <stdio.h>
#include <string.h>
#define MAX_LENGTH 100
// Function to combine title and full name
void combineTitleAndName(const char *title, const char *fullName, char *result) {
strcpy(result, title);
strcat(result, " ");
strcat(result, fullName);
}
// Function to extract title and surname
void extractTitleAndSurname(const char *title, const char *fullName, char *result) {
const char *surname = strrchr(fullName, ' '); // Find the last space
if (surname) {
strcpy(result, title);
strcat(result, surname);
} else {
strcpy(result, title); // If no surname, just return the title
}
}
int main() {
char title[MAX_LENGTH], fullName[MAX_LENGTH], combined[MAX_LENGTH],
titleSurname[MAX_LENGTH];
// Input title
printf("Enter title (e.g., Mr., Dr., Prof.): ");
fgets(title, MAX_LENGTH, stdin);
title[strcspn(title, "\n")] = '\0'; // Remove newline character
// Input full name
printf("Enter full name: ");
fgets(fullName, MAX_LENGTH, stdin);
fullName[strcspn(fullName, "\n")] = '\0'; // Remove newline character
// Combine title and full name
combineTitleAndName(title, fullName, combined);
printf("\nCombined Title and Full Name: %s\n", combined);
// Extract title and surname
extractTitleAndSurname(title, fullName, titleSurname);
printf("Title and Surname: %s\n", titleSurname);
return 0;
}