- String Palindrome Program In Cobol Tutorial
- Simple Java Palindrome Program
- Cobol Find String In String
- Cobol String Replace
To check if a string is a palindrome or not, a string needs to be compared with the reverse of itself. Consider a palindrome string: lol, -index: 0 1 2. Value: l o l- To compare it with the reverse of itself, the following logic is used: 0th character in the char array, string1 is the same as 2nd character in the same string. In this program, isPalindrome method checks if a string is a palindrome or not. It takes one string and compares each letter with the direct opposite letter. Words is a string array. We have five strings and we are checking for each string if it is palindrome or not. Palindrome program in C. Palindrome number in c: A palindrome number is a number that is same after reverse. For example 121, 34543, 343, 131, 48984 are the palindrome numbers. Palindrome number algorithm. Get the number from user; Hold the number in temporary variable; Reverse the number; Compare the temporary number with reversed number.
C program to check if a string or a number is palindrome or not. A palindrome string is one that reads the same backward as well as forward. It can be of odd or even length.
A palindrome number is a number that is equal to its reverse.
Algorithm to check Palindrome string
- Copy input string into a new string (strcpy function).
- Reverse it (we recommend not to use strrev function as it's not compatible with C99).
- Compare it with the original string (strcmp function).
- If both of them have the same sequence of characters, i.e., they are identical, then the string is a palindrome otherwise not.
C program to check palindrome without using string functions. Some palindrome strings are: 'C', 'CC', 'madam', 'ab121ba', 'C++&&++C'.
Palindrome program in C language
#include#include
int main()
{
char a[100], b[100];
printf('Enter a string to check if it's a palindromen');
gets(a);
strcpy(b, a);// Copying input string
strrev(b);// Reversing the string
if(strcmp(a, b)0)// Comparing input string with the reverse string
printf('The string is a palindrome.n');
else
printf('The string isn't a palindrome.n');
return0;
}
Output of C palindrome program:
Download palindrome program.
C program for palindrome without using string functions
#includeint main()
{
char text[100];
int begin, middle, end, length =0;
![Program Program](https://images.slideplayer.com/15/4805187/slides/slide_7.jpg)
gets(text); Transaction pro importer 7.
while(text[length]!='0')
length++;
String Palindrome Program In Cobol Tutorial
end = length -1;
middle = length/2;
![String handling in cobol String handling in cobol](https://www.journaldev.com/wp-content/uploads/2012/10/longest-palindrome-in-a-string-java.jpg)
for(begin =0; begin < middle; begin++)
{
if(text[begin]!= text[end])
{
printf('Not a palindrome.n');
break;
}
end--;
}
if(begin middle)
printf('Palindrome.n');
return0;
}
Palindrome number in C
#includeint main()
{
int n, r =0, t;
printf('Enter an integer to check if it's palindrome or notn');
scanf('%d',&n);
t = n;
while(t !=0)
{
r = r *10;
r = r + t%10;
t = t/10;
}
if(n r)
printf('%d is a palindrome number.n', n);
else
printf('%d isn't a palindrome number.n', n);
return0;
} Twonky server torrent.
C palindrome program using functions and pointers
int is_palindrome(char*);
void copy_string(char*,char*);
void reverse_string(char*);
int string_length(char*);
int compare_string(char*,char*);
int main()
{
char string[100];
int result;
printf('Input a stringn');
gets(string);
result = is_palindrome(string);
if(result 1)
printf(''%s' is a palindrome string.n', string);
else
printf(''%s' isn't a palindrome string.n', string);
return0;
}
int is_palindrome(char*string)
{
int check, length;
char*reverse;
length = string_length(string);
reverse =(char*)malloc(length+1);
copy_string(reverse, string);
reverse_string(reverse);
check = compare_string(string, reverse);
free(reverse);
if(check 0)
return1;
else
return0;
}
int string_length(char*string)
{
int length =0;
while(*string)
{
length++;
string++;
}
return length;
}
void copy_string(char*target,char*source)
{
while(*source)
{
*target =*source;
source++;
target++;
}
*target ='0';
}
void reverse_string(char*string)
{
int length, c;
char*begin,*end, temp;
length = string_length(string);
begin = string;
end = string;
for(c =0; c <(length -1); c++)
end++;
for(c =0; c < length/2; c++)
{
temp =*end;
*end =*begin;
*begin = temp;
begin++;
end--;
}
}
int compare_string(char*first,char*second)
{
while(*first*second)
{
if(*first '0'||*second '0')
break;
first++;
second++;
}
if(*first '0'&&*second '0')
return0;
else
return-1;
}
You can also write the program without using pointers. A palindrome string can be a single word or a phrase or a sentence.
Simple Java Palindrome Program
The UNSTRING statement used to separate single string to multiple based on the delimiter provided in the UNSTRING. It needs at least two destination identifier or literals. It can only separate alphabetic and alpha-numeric items. END-STRING, DELIMITED BY, TALLYING, WITH POINTER, ON OVERFLOW and NOT ON OVERFLOW clause is optional in UNSTRING usage.
UNSTRING statement Syntax
COUNT IN: COUNT IN clause associated with a particular destination data item. COUNT IN holds the count of no of character passed to the particular destination identifier/data item.
TALLYING:TALLYING clause holds the count of destination strings affected by UNSTRING. TALLYING clause associated with all the destination data items.
Cobol Find String In String
UNSTRING Statement Example
In the Data Division, the user has defined the following input record to be acted upon by the UNSTRING statement:
The next two records are defined as receiving fields for the UNSTRING statement. DISPLAY-REC is to be used for printed output. WORK-REC is to be used for further internal processing.
Cobol String Replace
The user has also defined the following fields for use as control fields in the UNSTRING statement.
In the Procedure Division, the user writes the following UNSTRING statement to move subfields of INV-RCD to the subfields of DISPLAY-REC and WORK-REC:
Before the UNSTRING statement is issued, the user places the value 3 in the CHAR-CT (the pointer item), so as not to work with the two control characters at the beginning of INV-RCD. In DBY-1, a period is placed for use as a delimiter, and in FLDS-FILLED (the tallying item) the value 0 is placed. The following data is then read into INV-RCD
Palindrome program in C language
#include#include
int main()
{
char a[100], b[100];
printf('Enter a string to check if it's a palindromen');
gets(a);
strcpy(b, a);// Copying input string
strrev(b);// Reversing the string
if(strcmp(a, b)0)// Comparing input string with the reverse string
printf('The string is a palindrome.n');
else
printf('The string isn't a palindrome.n');
return0;
}
Output of C palindrome program:
Download palindrome program.
C program for palindrome without using string functions
#includeint main()
{
char text[100];
int begin, middle, end, length =0;
gets(text); Transaction pro importer 7.
while(text[length]!='0')
length++;
String Palindrome Program In Cobol Tutorial
end = length -1;
middle = length/2;
for(begin =0; begin < middle; begin++)
{
if(text[begin]!= text[end])
{
printf('Not a palindrome.n');
break;
}
end--;
}
if(begin middle)
printf('Palindrome.n');
return0;
}
Palindrome number in C
#includeint main()
{
int n, r =0, t;
printf('Enter an integer to check if it's palindrome or notn');
scanf('%d',&n);
t = n;
while(t !=0)
{
r = r *10;
r = r + t%10;
t = t/10;
}
if(n r)
printf('%d is a palindrome number.n', n);
else
printf('%d isn't a palindrome number.n', n);
return0;
} Twonky server torrent.
C palindrome program using functions and pointers
int is_palindrome(char*);
void copy_string(char*,char*);
void reverse_string(char*);
int string_length(char*);
int compare_string(char*,char*);
int main()
{
char string[100];
int result;
printf('Input a stringn');
gets(string);
result = is_palindrome(string);
if(result 1)
printf(''%s' is a palindrome string.n', string);
else
printf(''%s' isn't a palindrome string.n', string);
return0;
}
int is_palindrome(char*string)
{
int check, length;
char*reverse;
length = string_length(string);
reverse =(char*)malloc(length+1);
copy_string(reverse, string);
reverse_string(reverse);
check = compare_string(string, reverse);
free(reverse);
if(check 0)
return1;
else
return0;
}
int string_length(char*string)
{
int length =0;
while(*string)
{
length++;
string++;
}
return length;
}
void copy_string(char*target,char*source)
{
while(*source)
{
*target =*source;
source++;
target++;
}
*target ='0';
}
void reverse_string(char*string)
{
int length, c;
char*begin,*end, temp;
length = string_length(string);
begin = string;
end = string;
for(c =0; c <(length -1); c++)
end++;
for(c =0; c < length/2; c++)
{
temp =*end;
*end =*begin;
*begin = temp;
begin++;
end--;
}
}
int compare_string(char*first,char*second)
{
while(*first*second)
{
if(*first '0'||*second '0')
break;
first++;
second++;
}
if(*first '0'&&*second '0')
return0;
else
return-1;
}
You can also write the program without using pointers. A palindrome string can be a single word or a phrase or a sentence.
Simple Java Palindrome Program
The UNSTRING statement used to separate single string to multiple based on the delimiter provided in the UNSTRING. It needs at least two destination identifier or literals. It can only separate alphabetic and alpha-numeric items. END-STRING, DELIMITED BY, TALLYING, WITH POINTER, ON OVERFLOW and NOT ON OVERFLOW clause is optional in UNSTRING usage.
UNSTRING statement Syntax
COUNT IN: COUNT IN clause associated with a particular destination data item. COUNT IN holds the count of no of character passed to the particular destination identifier/data item.
TALLYING:TALLYING clause holds the count of destination strings affected by UNSTRING. TALLYING clause associated with all the destination data items.
Cobol Find String In String
UNSTRING Statement Example
In the Data Division, the user has defined the following input record to be acted upon by the UNSTRING statement:
The next two records are defined as receiving fields for the UNSTRING statement. DISPLAY-REC is to be used for printed output. WORK-REC is to be used for further internal processing.
Cobol String Replace
The user has also defined the following fields for use as control fields in the UNSTRING statement.
In the Procedure Division, the user writes the following UNSTRING statement to move subfields of INV-RCD to the subfields of DISPLAY-REC and WORK-REC:
Before the UNSTRING statement is issued, the user places the value 3 in the CHAR-CT (the pointer item), so as not to work with the two control characters at the beginning of INV-RCD. In DBY-1, a period is placed for use as a delimiter, and in FLDS-FILLED (the tallying item) the value 0 is placed. The following data is then read into INV-RCD
When the UNSTRING statement is executed, the following actions take place:
- Positions 3 through 18 (FOUR-PENNY-NAILS) of INV-RCD are placed in
ITEM-NAME, left-justified within the area, and the unused character positions are padded with spaces. The value 16 is placed in CTR-1. - Because ALL SPACES is specified as a delimiter, the five contiguous SPACE characters are considered to be one occurrence of the delimiter.
- Positions 24 through 29 (707890) are placed in INV-NO. The delimiter character / is placed in DLTR-1, and the value 6 is placed in CTR-2.
- Positions 31 through 33 are placed in INV-CLASS. The delimiter is a SPACE, but because no field has been defined as a receiving area for delimiters, SPACE is merely bypassed.
- Positions 35 through 40 (475120) are examined and are placed in M-UNITS.
- The delimiter is a SPACE, but because no receiving field has been defined as a receiving area for delimiters, SPACE is bypassed. The value 6 is placed
in CTR-3. - Positions 42 through 46 (00122) are placed in FIELD-A and right-justified within the area. The leftmost character position is filled with a 0 (zero). The delimiter is a SPACE, but because no field has been defined as a receiving area for delimiters, SPACE is bypassed.
- Positions 48 through 53 (000379) are placed in DISPLAY-DOLS. The period delimiter character is placed in DLTR-2, and the value 6 is placed in CTR-4.
- Because all receiving fields have been acted upon and two characters of data in INV-RCD have not been examined, the ON OVERFLOW exit is taken, and execution of the UNSTRING statement is completed.
At the end of execution of the UNSTRING statement, DISPLAY-REC contains the following data:
CHAR-CT (the pointer field) contains the value 55, and FLD-FILLED (the tallying field) contains the value 6.