From 2e62fc01e43719e2670e9c3b3a89c33257bb1375 Mon Sep 17 00:00:00 2001 From: anishhh238 <115490102+anishhh238@users.noreply.github.com> Date: Tue, 25 Oct 2022 16:11:27 +0530 Subject: [PATCH] Added Swap two strings --- C++ program/swap_two_string.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 C++ program/swap_two_string.cpp diff --git a/C++ program/swap_two_string.cpp b/C++ program/swap_two_string.cpp new file mode 100644 index 0000000..7d184ca --- /dev/null +++ b/C++ program/swap_two_string.cpp @@ -0,0 +1,23 @@ +#include + +#include //string library + +using namespace std; + +int main() { + int n; //length of string + cin>>n; + char s1[n]; + char s2[n]; + char s3[n]; //temporary string + //Input String 1 + cin>>s1; + //Input String 2 + cin>>s2; + strcpy(s3,s1); //copy contents of s1 in s3 + strcpy(s1,s2); // similar to s1=s2 + strcpy(s2,s3); + cout<