Code: #include<iostream>#include<string>usingnamespacestd;intmain(){string str1;string str2;//input string 1cin>>str1;//input string 2cin>>str2;str1.swap(str2);//swap contents of str1 and str2cout<<str1<<"\n";cout<<str2;return0; ...
Following is the C program to swap two strings by using strcpy() function − Live Demo #include<stdio.h> #include<string.h> main(){ char s1[10],s2[10],s3[10]; printf("Enter String 1"); gets(s1); printf("Enter String 2"); gets(s2); printf("Before Swapping"); printf("Strin...
Swap Numbers Using Temporary Variable #include<stdio.h> int main() { double first, second, temp; printf("Enter first number: "); scanf("%lf", &first); printf("Enter second number: "); scanf("%lf", &second); // value of first is assigned to temp temp = first; // value of ...
C program to eliminate all vowels from a string C program to swap adjacent characters of a string C program to read time in string format and extract hours, minutes and second also check time validity Creating string buffer (character pointer), allocating memory at run time in C memcpy() fu...
Scala code to swap two number using third variable objectmyObject{defmain(args:Array[String]):Unit={vara=10varb=20println("Values before swapping:\t a= "+a+", b= "+b)// swappingvartemp=a a=b b=temp println("Values after swapping:\t a= "+a+", b= "+b)}} ...
usingnamespacestd; main(){ charstr1[50],str2[50]; intstr_cmp(char*,char*); cout<<“Enterfirststring:”; gets(str1); cout<<“Entersecondstring:”; gets(str2); if(str_cmp(str1,str2)) cout<<“nStrings are equal”;else
A string is a one-dimensional character array, which is terminated by a null character. Here, the Concatenation of two strings is the joining of them to form a new string<. Example String 1: Mangoes are String 2: tasty Concatenation of 2 strings: Mangoes are tasty Advertisement - ...
In this C Programming example, we will discuss how to swap two numbers using the pointers in C and also discuss the execution and pseudocode in detail.
Example Program to Swap Two Numbers Program – swap_two_numbers.go </> Copy package main import "fmt" func main() { // Declare variables to hold two numbers var num1, num2 int // Prompt the user to enter two numbers fmt.Print("Enter two integers separated by space: ") ...
/* C program to swap two integers using bitwise operators */#include <stdio.h>intmain(){intn1=5,n2=7;printf("Before swap: n1: %d\tn2: %d\n",n1,n2);n1=n1^n2;n2=n1^n2;n1=n1^n2;printf("After swap: n1: %d\tn2: %d\n",n1,n2);return0;}OUTPUT===Before swap:n1:5n2:7Aft...