Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sort the given string, without using string handling functions.

Similar presentations


Presentation on theme: "Sort the given string, without using string handling functions."— Presentation transcript:

1 Sort the given string, without using string handling functions

2 More Questions #include void main() { char s[20],t; int i,j,n; clrscr(); printf("Enter a string "); scanf("%s",s); printf("given string %s",s); for(i=0;s[i]!='\0';i++) { for(j=i+1;s[j]!='\0';j++) { if(s[i]>s[j]) { t=s[i]; s[i]=s[j]; s[j]=t; } printf("\nsorted string %s",s); getch(); }

3 Sort each words in the given paragraph

4 More Questions #include void main() { char s[20],temp[20][20],t; int i,j,n=0,k=0,l=0; clrscr(); printf("Enter a string "); gets(s); printf("given string %s",s); for(i=0;s[i]!='\0';i++){l++;} for(i=0;i<=l;i++) { if(s[i]==' '||s[i]=='\0') { temp[n][k]='\0'; //printf("\n%s",temp[n]); n++;k=0; } else { temp[n][k]=s[i]; k++; }

5 More Questions for(i=0;itemp[i][k]) { t=temp[i][j]; temp[i][j]=temp[i][k]; temp[i][k]=t; } k=0; for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_5.jpg", "name": "More Questions for(i=0;itemp[i][k]) { t=temp[i][j]; temp[i][j]=temp[i][k]; temp[i][k]=t; } k=0; for(i=0;itemp[i][k]) { t=temp[i][j]; temp[i][j]=temp[i][k]; temp[i][k]=t; } k=0; for(i=0;i

6 Compare two strings, the length of each stings will be calculate using function and the function return the length,(without using string handling functions)

7 More Questions #include void main() { int strlength(char *); char s1[20],s2[20]; int i,j,e=0,b=0,s=0; clrscr(); printf("enter two strings :- "); scanf("%s%s",s1,s2); if(strlength(s1)==strlength(s2)) { for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_7.jpg", "name": "More Questions #include void main() { int strlength(char *); char s1[20],s2[20]; int i,j,e=0,b=0,s=0; clrscr(); printf( enter two strings :- ); scanf( %s%s ,s1,s2); if(strlength(s1)==strlength(s2)) { for(i=0;i

8 More Questions if(s1[i]>s2[i]) { b=1; break; } if(e==strlength(s1)){printf("\nTwo strings are Equal");} if(b==1){printf("\nFirst string is Biggest");} if(s==1){printf("\nSecond string is Biggest");} getch(); } int strlength(char *s) { int i,l=0; for(i=0;s[i]!='\0';i++) { l++; } return(l); }

9 Sort N Strings, without using string functions

10 More Questions #include void main() { int strcompare(char *,char *); char s[20][20],t[20]; int i,j,n,k; clrscr(); printf("enter limit "); scanf("%d",&n); printf("Enter strings "); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_10.jpg", "name": "More Questions #include void main() { int strcompare(char *,char *); char s[20][20],t[20]; int i,j,n,k; clrscr(); printf( enter limit ); scanf( %d ,&n); printf( Enter strings ); for(i=0;i

11 More Questions for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_11.jpg", "name": "More Questions for(i=0;i

12 More Questions printf("\nsorted Strings "); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_12.jpg", "name": "More Questions printf( \nsorted Strings ); for(i=0;i

13 More Questions if(s1[i]>s2[i]) { b=1; break; } if(e==strlength(s1)){return(e);} if(b==1){return(1);} if(s==1){return(-1);} } int strlength(char *s) { int i,l=0; for(i=0;s[i]!='\0';i++) { l++; } return(l); }

14 Write a function which receives 2 integer arrays with limit n, add each element of the 2 arrays and the function return the resultant array

15 More Questions #include void main() { int *array(int [],int [],int); int a[10],b[10],i,n,*p; clrscr(); printf("enter limit "); scanf("%d",&n); printf("enter first array "); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_15.jpg", "name": "More Questions #include void main() { int *array(int [],int [],int); int a[10],b[10],i,n,*p; clrscr(); printf( enter limit ); scanf( %d ,&n); printf( enter first array ); for(i=0;i

16 More Questions printf("resultant array "); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_16.jpg", "name": "More Questions printf( resultant array ); for(i=0;i

17 Write a C program using pointers to find the sum of all elements sorted in an array

18 More Questions #include void main() { int a[10],i,n,j,t,s=0; clrscr(); printf("enter limit "); scanf("%d",&n); printf("enter array "); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_18.jpg", "name": "More Questions #include void main() { int a[10],i,n,j,t,s=0; clrscr(); printf( enter limit ); scanf( %d ,&n); printf( enter array ); for(i=0;i

19 More Questions //sorting for(i=0;i*(a+j)) { t=*(a+i); *(a+i)=*(a+j); *(a+j)=t; } printf("\nsorted array "); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_19.jpg", "name": "More Questions //sorting for(i=0;i*(a+j)) { t=*(a+i); *(a+i)=*(a+j); *(a+j)=t; } printf( \nsorted array ); for(i=0;i*(a+j)) { t=*(a+i); *(a+i)=*(a+j); *(a+j)=t; } printf( \nsorted array ); for(i=0;i

20 Using an array of pointers to store address of n variables and sort the array

21 More Questions #include void main() { int a[10],i,n,*ptr[10],*t,j; clrscr(); printf("Enter limit "); scanf("%d",&n); //sorting address to array of pointers for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_21.jpg", "name": "More Questions #include void main() { int a[10],i,n,*ptr[10],*t,j; clrscr(); printf( Enter limit ); scanf( %d ,&n); //sorting address to array of pointers for(i=0;i

22 More Questions //sorting for(i=0;i*ptr[j]) { t=ptr[i]; ptr[i]=ptr[j]; ptr[j]=t; } printf("\nsorted array "); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_22.jpg", "name": "More Questions //sorting for(i=0;i*ptr[j]) { t=ptr[i]; ptr[i]=ptr[j]; ptr[j]=t; } printf( \nsorted array ); for(i=0;i*ptr[j]) { t=ptr[i]; ptr[i]=ptr[j]; ptr[j]=t; } printf( \nsorted array ); for(i=0;i

23 Write a C program that receives one command line argument, which is a file name. open this file in the main and read an array of all integer values

24 More Questions #include void main(int argc,char *argv[]) { FILE *fp; int a[10],i,n=0; clrscr(); fp=fopen(argv[1],"r"); while((a[n]=getw(fp))!=EOF) { n++; } fclose(fp); printf("\ncontent in the array "); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_24.jpg", "name": "More Questions #include void main(int argc,char *argv[]) { FILE *fp; int a[10],i,n=0; clrscr(); fp=fopen(argv[1], r ); while((a[n]=getw(fp))!=EOF) { n++; } fclose(fp); printf( \ncontent in the array ); for(i=0;i

25 Write a C program that read a 2D array and prints whether it stores a unit matrix or not

26 More Questions #include void main() { int a[10][10],i,j,n,m,f=1; clrscr(); printf("enter order of the matrix"); scanf("%d%d",&n,&m); if(n==m) { printf("enter matrix"); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_26.jpg", "name": "More Questions #include void main() { int a[10][10],i,j,n,m,f=1; clrscr(); printf( enter order of the matrix ); scanf( %d%d ,&n,&m); if(n==m) { printf( enter matrix ); for(i=0;i

27 More Questions printf("\ngiven matrix\n"); for(i=0;i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3408857/slides/slide_27.jpg", "name": "More Questions printf( \ngiven matrix\n ); for(i=0;i

28 More Questions if(f==1) { printf("\ngiven matrix is unit matrix"); } else { printf("\ngiven matrix not unit matrix"); } else { printf("\nNot a square matrix"); } getch(); }

29 Write a program that will receive a filename and a text as command line argument and write the text to the file

30 More Questions #include void main(int argc,char *argv[]) { FILE *fp; char c; fp=fopen(argv[1],"w"); fprintf(fp,"%s",argv[2]); fclose(fp); fp=fopen(argv[1],"r"); printf("\ncontent of the file %s",argv[1]); while((c=getc(fp))!=EOF) { printf("%c",c); } fclose(fp); getch(); }


Download ppt "Sort the given string, without using string handling functions."

Similar presentations


Ads by Google