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.

Slides:



Advertisements
Similar presentations
Recursion Prog #include <stdio.h> #include<conio.h> main()
Advertisements

Pseudocode A way to make programming easier Start with a verbal description of what the program is supposed to do! Slowly transform it into C, defining.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
Sort the given string, without using string handling functions.
Operations on Arrays. Operation on Array Data Structures  Traversal  Selection  Searching  Insertion  Deletion  Sorting.
Multidimensional Arrays. Example Write a program to keep track of all warmup scores for all students. Need a list of a list of scores Student – score.
Strings A special kind of array is an array of characters ending in the null character \0 called string arrays A string is declared as an array of characters.
Arrays Ethan Cerami New York University Today n Array Basics (Review) n Random Number Example n Passing Arrays to Functions n Strings.
PRESENTED BY: ER. SUMANPREET KAUR LECTURER IN CE DEPTT. GPCG ASR.
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?
1 Software John Sum Institute of Technology Management National Chung Hsing University.
Programming Arrays. Example 1 Write a program that reads 3 numbers from the user and print them in reverse order. How many variables do we need to store.
1 1-d Arrays. 2 Array Many applications require multiple data items that have common characteristics  In mathematics, we often express such groups of.
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.
SNPL1 GAUSS ELIMINATION & BACK SUBSTITUTION GAUSS ELIMINATION & BACK SUBSTITUTION Dayun Yu Seungmuk Ji.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
Computer programming Lecture 5. Lecture 5: Outline Arrays [chap 7 – Kochan] –The concept of array –Defining arrays –Initializing arrays –Character arrays.
Write a C program to pass an array containing age of person to a function. This function should find average age and display the average age in main function.
Data structure and c K.S. Prabhu Letterer All Deaf Educational Technology.
Computer Programming for Engineers. Outline Tic-Tac-Toe (O-X Game) Drawing 3x3 grid Receiving the inputs Checking for a winner Taking turns between.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
PRESENTATION ON SEARCHING SEARCHING Searching is the method to find element from the list of the elements. If element is found then it.
CPT: Strings/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to discuss strings and their relationship.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee C Language Part 3.
Struct 1. Definition: Using struct to define a storage containing different types. For example it can contain int, char, float and array at the same time.
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
© Oxford University Press All rights reserved. CHAPTER 6 STRINGS.
Computer programming Outline Arrays [chap 7 – Kochan] –The concept of array –Defining arrays –Initializing arrays –Character.
Structured Programming Approach Module VIII - Additional C Data Types Arrays Prof: Muhammed Salman Shamsi.
CCSA 221 Programming in C CHAPTER 7 WORKING WITH ARRAYS 1.
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.
Rray Programs. Insert and element in the given position of the Array rray.
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
WEEK 8 Class Activities Lecturer’s slides.
Computer Programming for Engineers
Chapter 1 Basic C Programming
C A RRAY Continue one dimensional array 1. Assume we have define this array: int hourlyTemp[ 24 ]; And we need to insert this array as parameter into.
1 Pointers: Parameter Passing and Return. 2 Passing Pointers to a Function Pointers are often passed to a function as arguments  Allows data items within.
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
1 Arrays and Pointers The name of an array is a pointer constant to the first element. Because the array’s name is a pointer constant, its value cannot.
Dr. Sajib Datta Feb 21,  In the last class we discussed: ◦ Bubble sort  How it works  performance.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
UNIT - 3 ARRAYS AND STRINGS. Array An Array is a collection of similar data items, that are stored under a common name. Types –One-Dimensional array –Two-Dimensional.
Arrays Name, Index, Address. Arrays – Declaration and Initialization int x; y[0] y[1] y[2]
Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional Array Explain Arrays.
MAHENDRAN. Session Objectives Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional.
The Repetition control structure using while loop.
MULTI-DIMENSION ARRAY STRING Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Chapter 2 Array and String. Array Definition of Array : An array is a sequence or collection of the related data items that share a common name. Purpose.
1-d Arrays.
WHILE, DO-WHILE AND FOR LOOPS
IS12 - Introduction to Programming Lecture 19: Functions and Arrays
Strings (מחרוזות).
MULTI-DIMENSIONAL ARRAY
Array 9/8/2018.
CHAPTER 7 RECURSIVE FUNCTION
Chapter 5 POINTERs.
Software John Sum Institute of Technology Management
Recursion Prog #include <stdio.h> #include<conio.h> main()
EECE.2160 ECE Application Programming
UNIT - 3 Noornilo Nafees.
Arrays.
Strings in C Array of characters is called a string.
Character Arrays char string1[] = “first”;
Programming Strings.
EECE.2160 ECE Application Programming
컴퓨터 프로그래밍 기초 - 13th : 마지막 수업 -
Introduction to Problem Solving and Programming
Presentation transcript:

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 = 0, flag = 0; fflush(stdin); printf("Enter a string: \n"); gets(string); /* keep going through each character of the string till its end*/ for (i = 0; string[i] != '\0'; i++) { length++; } for (i = length - 1; i >= 0; i--) {

reverse_string[length - i - 1] = string[i]; } /* * Compare the input string and its reverse. If both are equal * then the input string is palindrome. */ for (i = 0; i < length; i++) { if (reverse_string[i] == string[i]) flag = 1; else flag = 0; } if (flag == 1) printf("%s is a palindrome \n", string); else printf("%s is not a palindrome \n", string); } OUTPUT Enter a string : malayalam malayalam is a palindrome

Length of the string #include int main() { char s[1000],i; printf("Enter a string: "); scanf("%s",s); for(i=0; s[i]!='\0'; ++i); printf("Length of string: %d",i); return 0; } OUTPUT: Enter a string: Programiz Length of string: 9

SORTING OF ARRAY ELEMENTS #include main() { int a[25], i, n, j,t; clrscr(); printf(“Enter the number of elements not exceeding 25”); scanf(“%d”, &n); for (i=0;i<n;i++) { printf(“\n Enter the element”); scanf(“%d\n”, &a[i]); }

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

C Program to Concatenate Two Strings Manually #include int main() { char s1[100], s2[100], i, j; printf("Enter first string: "); scanf("%s",s1); printf("Enter second string: "); scanf("%s",s2); for(i=0; s1[i]!='\0'; ++i); /* i contains length of string s1. */ for(j=0; s2[j]!='\0'; ++j, ++i) { s1[i]=s2[j]; } s1[i]='\0'; printf("After concatenation: %s",s1); return 0; }