Professional Documents
Culture Documents
#include <stdio.h>
#include <conio.h>
#include <string.h>
char str[10];
int n;
strcpy(str,"ABC");
n = strlen(str);
permute(str, 0, n-1);
getch();
return 0;
}
2. Write a program to find the longest palindrome in a string.
#include <stdio.h>
#include <conio.h>
#include <string.h>
// A utility function to print a substring str[low..high]
void printSubStr(char* str, int low, int high)
{ int i;
for(i=low; i<=high; ++i)
printf("%c", str[i]);
}
// This function prints the longest palindrome substring (LPS)
// of str[]. It also returns the length of the longest palindrome
int longestPalSubstr(char *str)
{
int maxLength = 1; // The result (length of LPS)
int start = 0;
int len=strlen(str);
return maxLength;
}
int main()
{
char str[30];
clrscr();
str="Helloabcdedcbahello";
printf("\nLength is: %d", longestPalSubstr(str) );
return 0;
}
3. Write a program to take two array and find which number is
not present in the second array and it is prime.
#include<iostream.h>
#include<conio.h>
// Function for finding
// elements which are there
// in a[] but not in b[].
void findMissing(int a[], int b[],
int n, int m)
{
for (int i = 0; i < n; i++)
{
int j,flag=0;
for (j = 0; j < m; j++)
if (a[i] == b[j])
break;
if (j == m)
{
// Driver code
int main()
{
int a[] = { 1, 2, 6, 3, 4, 5 };
int b[] = { 2, 4, 3, 1, 0 };
int n = sizeof(a) / sizeof(a[0]);
int m = sizeof(b) / sizeof(b[1]);
findMissing(a, b, n, m);
getch();
return 0;
}
4. Rearrange the array with alternative high and low elements.
#include <stdio.h>
#include <conio.h>
rearrangeArray(arr, n);