diff --git a/charvi mathur assignment 2/Q1. search element in array.txt b/charvi mathur assignment 2/Q1. search element in array.txt new file mode 100644 index 0000000..61d3a8c --- /dev/null +++ b/charvi mathur assignment 2/Q1. search element in array.txt @@ -0,0 +1,37 @@ +#include +int main() +{ + int arr[100]; + int size, i, toSearch, found; + printf("************ Search A Given Value ! ************\n"); + printf("Enter size of array: "); + scanf("%d", &size); + printf("Enter elements in array: "); + + for(i=0; i +void main() +{ + int a[20], i, j, k, n; + + printf("Enter array size: "); + scanf("%d", &n); + printf("Enter %d array element: ", n); + + for(i = 0; i < n; i++) + { + scanf("%d", &a[i]); + } + + printf("After Duplicate element remove : "); + 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]); + } + +} \ No newline at end of file diff --git a/charvi mathur assignment 2/Q2_OUTPUT.PNG b/charvi mathur assignment 2/Q2_OUTPUT.PNG new file mode 100644 index 0000000..cf7e484 Binary files /dev/null and b/charvi mathur assignment 2/Q2_OUTPUT.PNG differ diff --git a/charvi mathur assignment 2/Q3. Number to binary convert.txt b/charvi mathur assignment 2/Q3. Number to binary convert.txt new file mode 100644 index 0000000..5f2e505 --- /dev/null +++ b/charvi mathur assignment 2/Q3. Number to binary convert.txt @@ -0,0 +1,22 @@ +#include +int main() +{ + int n =10; + int binaryNum[32]; + int i = 0; + int result; + printf("Number is : %d",n); + printf("\nNumber to Binary Convert : "); + while (n > 0) + { + binaryNum[i] = n % 2; + n = n / 2; + i++; + } + for (int j = i - 1; j >= 0; j--) + { + result = binaryNum[j]; + printf("%d ",result); + } + return 0; +} diff --git a/charvi mathur assignment 2/Q3_OUTPUT.PNG b/charvi mathur assignment 2/Q3_OUTPUT.PNG new file mode 100644 index 0000000..d752642 Binary files /dev/null and b/charvi mathur assignment 2/Q3_OUTPUT.PNG differ diff --git a/charvi mathur assignment 2/Q4. String is Palindrome or not.txt b/charvi mathur assignment 2/Q4. String is Palindrome or not.txt new file mode 100644 index 0000000..896e12c --- /dev/null +++ b/charvi mathur assignment 2/Q4. String is Palindrome or not.txt @@ -0,0 +1,26 @@ +#include +#include + +int main(){ + char string1[20]; + int i, length; + int flag = 0; + + printf("Enter a string:"); + scanf("%s", string1); + length = strlen(string1); + + for(i=0;i < length ;i++){ + if(string1[i] != string1[length-i-1]){ + flag = 1; + break; + } +} + if (flag) { + printf("%s is not a palindrome", string1); + } + else { + printf("%s is a palindrome", string1); + } + return 0; +} \ No newline at end of file diff --git a/charvi mathur assignment 2/Q4_OUTPUT.PNG b/charvi mathur assignment 2/Q4_OUTPUT.PNG new file mode 100644 index 0000000..2a0a218 Binary files /dev/null and b/charvi mathur assignment 2/Q4_OUTPUT.PNG differ diff --git a/charvi mathur assignment 2/Q5. String copy other String without strcpy().txt b/charvi mathur assignment 2/Q5. String copy other String without strcpy().txt new file mode 100644 index 0000000..f9c4053 --- /dev/null +++ b/charvi mathur assignment 2/Q5. String copy other String without strcpy().txt @@ -0,0 +1,16 @@ +#include +int main() +{ + char s1[]="HELLO!", 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 s1 Copy to String s2 : %s", s2); + + return 0; +} \ No newline at end of file diff --git a/charvi mathur assignment 2/Q5_OUTPUT.PNG b/charvi mathur assignment 2/Q5_OUTPUT.PNG new file mode 100644 index 0000000..2ccb60d Binary files /dev/null and b/charvi mathur assignment 2/Q5_OUTPUT.PNG differ