diff --git a/Srishti 12-05/Q1.cpp b/Srishti 12-05/Q1.cpp new file mode 100644 index 0000000..c93d4d4 --- /dev/null +++ b/Srishti 12-05/Q1.cpp @@ -0,0 +1,44 @@ +#include + +#define MAX_SIZE 100 + +int main() +{ + int arr[MAX_SIZE]; + int size, i, toSearch, found; + + printf("Enter size of array: "); + scanf("%d", &size); + + printf("Enter elements in array: "); + for(i=0; i +#include +void main() +{ + int a[20], i, j, k, n; + clrscr(); + + printf("\nEnter array size: "); + scanf("%d", &n); + + printf("\nEnter %d array element: ", n); + for(i = 0; i < n; i++) + { + scanf("%d", &a[i]); + } + + printf("\nOriginal array is: "); + for(i = 0; i < n; i++) + { + printf(" %d", a[i]); + } + + printf("\nNew array is: "); + for(i = 0; i < n; i++) + { + for(j = i+1; j < n; ) + { + if(a[j] == a[i]) + { + for(k = j; k < n; k++) + { + a[k] = a[k+1]; + } + n--; + } + else + { + j++; + } + } + } + + for(i = 0; i < n; i++) + { + printf("%d ", a[i]); + } + getch(); +} \ No newline at end of file diff --git a/Srishti 12-05/Q3.cpp b/Srishti 12-05/Q3.cpp new file mode 100644 index 0000000..8aac5c5 --- /dev/null +++ b/Srishti 12-05/Q3.cpp @@ -0,0 +1,26 @@ +#include +#include + +long decimalToBinary(int decimalnum) +{ + long binarynum = 0; + int rem, temp = 1; + + while (decimalnum!=0) + { + rem = decimalnum%2; + decimalnum = decimalnum / 2; + binarynum = binarynum + rem*temp; + temp = temp * 10; + } + return binarynum; +} + +int main() +{ + int decimalnum; + printf("Enter a Decimal Number: "); + scanf("%d", &decimalnum); + printf("Equivalent Binary Number is: %ld", decimalToBinary(decimalnum)); + return 0; +} \ No newline at end of file diff --git a/Srishti 12-05/Q4.cpp b/Srishti 12-05/Q4.cpp new file mode 100644 index 0000000..ea8583c --- /dev/null +++ b/Srishti 12-05/Q4.cpp @@ -0,0 +1,22 @@ +#include +#include +{ + int l = 0; + int h = strlen(str) - 1; + while (h > l) + { + if (str[l++] != str[h--]) + { + printf("%s is Not Palindrome", str); + return; + } + } + printf("%s is palindrome", str); +} +int main() +{ + isPalindrome("abba"); + isPalindrome("abbccbba"); + isPalindrome("geeks"); + return 0; +} \ No newline at end of file diff --git a/Srishti 12-05/Q5.cpp b/Srishti 12-05/Q5.cpp new file mode 100644 index 0000000..22f5f58 --- /dev/null +++ b/Srishti 12-05/Q5.cpp @@ -0,0 +1,17 @@ +#include +int main() +{ + char s1[] = "GeeksforGeeks", s2[100], i; + + printf("string s1 : %s\n", s1); + + for (i = 0; s1[i] != '\0'; ++i) { + s2[i] = s1[i]; + } + + s2[i] = '\0'; + + printf("String s2 : %s", s2); + + return 0; +} \ No newline at end of file