#include<stdio.h> #include<string.h> main() { char str[50]; int i,j,len,temp; printf("enter the string\n"); gets(str); len=strlen(str); for(i=0,j=len-1;i<=len/2;i++,j--) { temp=str[i]; str[i]=str[j]; str[j]=temp; } printf("reversed string is : %s\n",str); }
New Android apps UniqueKey
Friday, 20 February 2015
Reverse the string without library function
Reverse the string
#include<stdio.h> #include<string.h> main() { char str[50]; printf("enter the string\n"); gets(str); strrev(str); printf("reversed string is : %s\n",str); }
Swapping without temp variable
#include<stdio.h> main() { int num1,num2; printf("Enter number 1 : "); scanf("%d",&num1); printf("Enter number 2 : "); scanf("%d",&num2); printf("Before swapping\n"); printf("number 1 is %d and number 2 is %d\n",num1,num2); num1=num1+num2; num2=num1-num2; num1=num1-num2; printf("After swapping \n"); printf("number 1 is %d and number 2 is %d\n",num1,num2); }
Swapping using temp variable
#include<stdio.h> main() { int num1,num2,temp; printf("Enter number 1 : "); scanf("%d",&num1); printf("Enter number 2 : "); scanf("%d",&num2); printf("Before swapping\n"); printf("number 1 is %d and number 2 is %d\n",num1,num2); temp=num1; num1=num2; num2=temp; printf("After swapping \n"); printf("number 1 is %d and number 2 is %d\n",num1,num2); }
Linear Search
#include<stdio.h> main() { int arr[10],i,n,key,c=0; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements of the array: "); for(i=0;i<=n-1;i++) { scanf("%d",&arr[i]); } printf("Enter the number to be search: "); scanf("%d",&key); for(i=0;i<=n-1;i++) { if(arr[i]==key) { c=1; break; } } if(c==0) printf("The number is not found"); else printf("The number is found"); return 0; }
Subscribe to:
Posts (Atom)