2d array
Question:
Write a program to take input of 5 names and surnames in different two dimensional arrays. Then concatenate (join) names with their surname in a third 2D array.
💡 Solutions (1)
Super Admin
AdminFeb 03, 2026 at 11:27
upvotes
#include <stdio.h> #include <string.h> int main() { char name[5][20]; char surname[5][20]; char fullname[5][40]; int i; // Input names printf("Enter 5 Names:\n"); for(i = 0; i < 5; i++) { scanf("%s", name[i]); } // Input surnames printf("\nEnter 5 Surnames:\n"); for(i = 0; i < 5; i++) { scanf("%s", surname[i]); } // Concatenate name and surname for(i = 0; i < 5; i++) { strcpy(fullname[i], name[i]); // copy name strcat(fullname[i], " "); // add space strcat(fullname[i], surname[i]); // add surname } // Display full names printf("\n----- Full Names -----\n"); for(i = 0; i < 5; i++) { printf("%s\n", fullname[i]); } return 0; }
Want to add your solution? Login to contribute!
💬 Comments (0)
Login to post comments
No comments yet
Be the first to comment!