Posts

Showing posts from April, 2017

Bubble Sort

Image
Program to sort the list of names in alphabetic order using Bubble sort. #include<stdio.h> #include<stdlib.h> #include<string.h> #define max 25 void sort(char *(a)[max],int n) {   int i,j;   char temp[max];   for(i=0;i<n;i++)     for(j=n-1;j>=i+1;j--)     if(strcasecmp(a[j],a[j-1])<0)     {       strcpy(temp,a[j-1]);       strcpy(a[j-1],a[j]);       strcpy(a[j],temp);     } } void main() {   int i,n;   char *(str)[max];   printf("Enter no of names to enter:" );   scanf("%d",&n );   printf("Enter the names:\n" );   for(i=0;i<n;i++)   {     str[i]=malloc(max);     scanf("%s",str[i] );   }   sort(str,n);   printf("Names after the sort \n" );   for(i=0;i<n;i++)   printf("%s\n",str[i] ); } OUTPUT

Replace a substring in a string.

Image
Program to replace the given sub string from a string. #include<stdio.h> int main() {   int ls,i,j,k,flag=0,olt,pos,lt;   char st[20],sub[20];   printf("Enter the string:");   scanf("%[^\n]",st );   printf("Enter the substring:");   scanf("%s",sub );   for(i=0;st[i]!='\0';i++);//to find the length of string   ls=i;   for(i=0;sub[i]!='\0';i++);//to find the length of string   olt=i;   if(olt<1||olt>ls)   {     printf("Not possible to replace\n" );     return 0;   }   for(i=0;i<ls;)   {     j=0;     while(st[i++]==sub[j++])     {       if(j==olt)       {         flag=1;         pos=i-olt;         break;       }     }   }   if(flag==1)   {     printf("Enter new substring:" );     scanf("%s",sub );     for(i=0;sub[i]!='\0';i++);     lt=i;     for(i=pos,j=0;j<lt;j++,i++)     {       if(j<olt)       st[i]=sub[j];       else       {         for(k=ls+1;k>i;k--)         st[

Program which reads a line of characters & store it in a data file in the opposite case.

Image
#include <stdio.h> #include <ctype.h> void main () { char a[ 50 ]; int i; printf ( "Enter the line of text:" ); scanf ( " % [^\n]" ,a); printf ( "%s" ,a); FILE *fp= fopen ( "text.dat" , "w" ); for (i= 0 ;a[i]!= '\0' ;i++) { if ( islower (a[i])) a[i]= toupper (a[i]); else a[i]= tolower (a[i]); fprintf (fp, "%c" ,a[i]); } fclose (fp); }        

Upgrade your bash on Ubuntu on Windows

Image
With new Creators update,we can upgrade our Bash on Ubuntu on Windows to Ubuntu 16.04 terminal by following the steps (This is most recommended method to upgrade your bash officially form Microsoft). Step1:open your bash and check its current version         Step 2:type sudo do-release-upgrade.            write your password and hit enter. it will check for any updated releases and download it. Step 3:it will ask permission for installing it hit y wait a while,until all the updates are downloaded and installed. Step 4: it will ask whether to restart services automatically hit yes. after all set restart your PC