Sort the given string, without using string handling functions.

Slides:



Advertisements
Similar presentations
#include void main() { float x = 1.66, y = 1.75; printf(%f%f,ceil(x), floor(y)); }
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
For(int i = 1; i
Recursion Prog #include <stdio.h> #include<conio.h> main()
Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Fundamental of C programming
Lecture 9: Character and String
 A string is an array of characters.  Strings must have a 0 or null character after the last character to show where the string ends.  The null character.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 16P. 1Winter Quarter Strings Lecture 16.
Call By Address Parameters (Pointers) Chapter 5. Functions that “return” more than a single value What if we need more than one value to be returned from.
Buffer Overflow Prabhaker Mateti Wright State University.
What is shape function ? shape function is a function that will give the displacements inside an element if its displacement at all the node locations.
void count_down (int count) { for(i=count; i>1; i--) printf(" %d\t", count); } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n",
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
C Intro.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Arrays Ethan Cerami New York University Today n Array Basics (Review) n Random Number Example n Passing Arrays to Functions n Strings.
Selection Sort
C Programming Strings. Array of characters – most common type of array in C  Let’s make them easier for use Denote the end of array using a special character.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
More Questions 1) Write a C program to read a matrix A of size nXn and two arrays X and Y of size n and calculate XA-Y?
Advance Use of Structures CHAPTER 5. C.10 1 Using Structures with Functions » A function can return only one value back. » Some of the processes may yield.
MAHENDRAN CHAPTER 6. Session Objectives Explain Type of Functions Discuss category of Functions Declaration & Prototypes Explain User Defined Functions.
Reading the data from the input devices and displaying the results on the screen are the two main tasks of any program. To perform these tasks user friendly.
 An instruction or group of instructions.  Computer executes program repeatedly for specified number of times. Or until some terminating conditions are.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
Advanced Data types and Sorting
Nested LOOPS.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
The switch Statement.  Occasionally, an algorithm will contain a series of decisions in which a variable or expression is tested separately for each.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
Selection Sort
EXERCISE Arrays, structs and file processing. Question You own a pet store. You want to keep an inventory of all the pets that you have. Pets available.
Computer Programming Control Structure
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
BY ILTAF MEHDI (MCS, MCSE, CCNA)1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI (MCS, MCSE, CCNA)2 Chapter No: 04 “Loops”
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
C language--Introduction. History 1970: B by Ken Thompson at AT&T Bell Lab 1972: C by Dennis Ritchie and Ken Tompson at At&T Bell Lab for UNIX 1978: “The.
REEM ALAMER REVISION FOR C LANGUAGE COURSE. OUTPUTS int main (void) { int C1, C2; int *p1, *p2; C1 = 8; p1 = &C1; C2 = *p1 / 2 + 5; p2 = &C2; printf ("C1.
char first[10]="monkey"; char second[10]="fish"; char* keep;
C Interview Questions Prepared By:.
Advance Use of Structures
Decisions Chapter 4.
Operator Overloading.
Condition Statements.
By: Syed Shahrukh Haider
Tejalal Choudhary “C Programming from Scratch” Pointers
Visit for more Learning Resources
Tejalal Choudhary “C Programming from Scratch” Function & its types
توابع ورودي-خروجي.
כתיבת מאקרו הפקודה assert מצביעים לפונקציות
Preprocessor.
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
UNIT - 3 Noornilo Nafees.
Introduction to C.
10 лекция Сөз тіркестерін өңдеу.
Character Arrays char string1[] = “first”;
Computer Security Password Policy.
Structures in c By Anand George.
Course Outcomes of Programming In C (PIC) (17212, C203):
Lecture 24.
Range check 範圍檢查: int age; int score; int month; 1-12
Presentation transcript:

Sort the given string, without using string handling functions

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(); }

Sort each words in the given paragraph

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++; }

More Questions for(i=0;i<n;i++) { for(j=0;temp[i][j]!='\0';j++) { for(k=j+1;temp[i][k]!='\0';k++) { if(temp[i][j]>temp[i][k]) { t=temp[i][j]; temp[i][j]=temp[i][k]; temp[i][k]=t; } k=0; for(i=0;i<n;i++) { for(j=0;temp[i][j]!='\0';j++) { s[k]=temp[i][j]; k++; } s[k]=' ';k++; } s[k]='\0'; printf("\nfinal string : %s",s); getch(); }

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

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<strlength(s1);i++) { if(s1[i]==s2[i]) { e++; } if(s1[i]<s2[i]) { s=1; break; }

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); }

Sort N Strings, without using string functions

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<n;i++) { scanf("%s",s[i]); } printf("Given Strings "); for(i=0;i<n;i++) { printf("\n%s",s[i]); }

More Questions for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(strcompare(s[i],s[j])==1) { for(k=0;s[i][k]!='\0';k++) { t[k]=s[i][k]; } t[k]='\0'; for(k=0;s[j][k]!='\0';k++) { s[i][k]=s[j][k]; } s[i][k]='\0'; for(k=0;t[k]!='\0';k++) { s[j][k]=t[k]; } s[j][k]='\0'; }

More Questions printf("\nsorted Strings "); for(i=0;i<n;i++) { printf("\n%s",s[i]); } getch(); } int strcompare(char *s1,char *s2) { int strlength(char *); int i,e=0,b=0,s=0; for(i=0;i<strlength(s1);i++) { if(s1[i]==s2[i]) { e++; } if(s1[i]<s2[i]) { s=1; break; }

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); }

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

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<n;i++) { scanf("%d",&a[i]); } printf("enter second array "); for(i=0;i<n;i++) { scanf("%d",&b[i]); }

More Questions printf("resultant array "); for(i=0;i<n;i++) { printf("%d ",*p);p++; } getch(); } int *array(int a[10],int b[10],int n) { int i; for(i=0;i<n;i++) { a[i]=a[i]+b[i]; } return(a); }

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

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<n;i++) { scanf("%d",(a+i)); } printf("given array "); for(i=0;i<n;i++) { printf("%d ",*(a+i)); }

More Questions //sorting for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(*(a+i)>*(a+j)) { t=*(a+i); *(a+i)=*(a+j); *(a+j)=t; } printf("\nsorted array "); for(i=0;i<n;i++) { printf("%d ",*(a+i)); s=s+*(a+i); } printf("\nsum= %d",s); getch(); }

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

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<n;i++){ptr[i]=&a[i];} printf("Enter array "); for(i=0;i<n;i++) { scanf("%d",ptr[i]); } printf("\ngiven array "); for(i=0;i<n;i++) { printf("%d ",*ptr[i]); }

More Questions //sorting for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(*ptr[i]>*ptr[j]) { t=ptr[i]; ptr[i]=ptr[j]; ptr[j]=t; } printf("\nsorted array "); for(i=0;i<n;i++) { printf("%d ",*ptr[i]); } getch(); }

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

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<n;i++) { printf("%d ",a[i]); } getch(); }

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

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<n;i++) { for(j=0;j<m;j++) { scanf("%d",&a[i][j]); }

More Questions printf("\ngiven matrix\n"); for(i=0;i<n;i++) { for(j=0;j<m;j++) { printf("%d ",a[i][j]); if(i==j) { if(a[i][j]!=1) { f=0; } else { if(a[i][j]!=0) { f=0; } printf("\n"); }

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(); }

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

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(); }