Skip to main content

Posts

Showing posts with the label c program to swap

Sample C Program To Convert String To An Integer Using atoi() Function.

#include <stdio.h> #include <conio.h> #include <stdlib.h> int main() { int i; i = atoi (" 100"); printf(" The integer value is: %d ", i); getch(); return 0; } OUTPUT: The integer value is: 100 NOTE: If you liked the post/article or if you think this post/article helped you in any way, then please show your appreciation by filling up at least one form from the options given below:

Sample C Program To Sort A Given Number Of Strings.

C Program To Sort A Given Number Of Strings. #include <stdio.h> #include <conio.h> #include <string.h> main() { char str[4][10]; int i; clrscr(); for( i = 0; i < 4; i++ )   {      printf(“ \n Enter name %d: ”, i+1 );      scanf(“ %s ”, str[i] );   } printf(“\n Original Order \n”); for(i = 0; i < 4; i++ )      printf(“ %s\t ”, str[i] ); for(i = 0; i < 4; i++ )   {     for(j = i + 1; j < 4; j++ )        if( strcmp(str[i], str[j]) > 0 )          {             strcpy( temp, str[i] );             strcpy( temp, str[i], str[j] );             strcpy( str[j], temp );          }   } printf(“\n Sorted Order \n”); for( i = 0; i < 4; i++ )     printf(“ %s\t ”, str[i]); getch(); ...

Sample C Program To Swap Two Strings Using strcpy() Function.

#include <stdio.h> #include <conio.h> #include <string.h> main() { Char s1[10], S2[10], temp[10]; clrscr(); printf(“ Enter first name \n ”); scanf(“ %s ”, s1); printf(“ Enter second name \n ”); scanf(“ %s ”, s2); printf(“ Before swapping \n ”); printf(“ s1 = %s\ts2 = %s\n ”, s1, s2); strcpy(temp, s1); strcpy(s1, s2); strcpy(s2, temp); printf(“ After swapping \n ”); printf(“ s1 = %s\ts2 = %s\n ”, s1,s2); getch(); } OUTPUT: Enter first name Lavanya Enter second name Suchita Before swapping s1 = Lavanya s2 = Suchita After swapping s1 = Suchita s2 = Lavanya ALSO READ: -- Program to accept a string and print it by using the while loop. -- Program to accept a string in upper case and print it in lower case. -- Program to accept a string in any case and print it by another case. -- Program to accept a string and print each word in new line. -- Program to accept a string and count no of capital letters, no. of small letters and ...

Sample C Program To Swap Two Numbers Using & Without Temporary Variables.

#include <stdio.h> #include <conio.h> main() {     int x, y, temp;     printf("Enter the value of x and y ");     scanf("%d %d", & x, & y);     printf("Before Swapping\nx = %d\ny = %d\n",x,y);     temp = x;     x = y;     y = temp;     printf("After Swapping\nx = %d\ny = %d\n",x,y);     getch();     return 0; } OUTPUT: Enter the value of x and y 2 4 Before Swapping x = 2 y = 4 After Swapping x = 4 y = 2 C Program To Swap Two Numbers Without Using Temp Variable. #include <stdio.h> main() {     int a, b;     printf("Enter two numbers to swap ");     scanf("%d %d", & a, & b);     a = a + b;     b = a - b;     a = a - b;     printf("a = %d\nb = %d\n",a,b);     return 0; } OUTPUT: Enter two numbers to swap 2 4 a = 4 b = 2 C ...