[go: up one dir, main page]

0% found this document useful (0 votes)
2 views8 pages

CSE Assignment

CSE Assignment

Uploaded by

gman72097
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

CSE Assignment

CSE Assignment

Uploaded by

gman72097
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Answer to Question NO.

#include <stdio.h>
#include <string.h>

int main()
{
char str[100], result[100];
int i, j, k = 0;
int found;

printf("Enter a string: ");


gets(str);

for (i = 0; str[i]!= '\0'; i++)


{
found = 0;
for (j = 0; j < k; j++)
{
if (str[i] == result[j])
{
found = 1;
break;
}
}
if (!found)
{
result[k++] = str[i];
}
}

result[k] = '\0';

printf("String after removing duplicates: %s\n", result);

return 0;
}
Screenshot:
Answer to Question NO. 2

#include <stdio.h>

int main()
{
int size, i;
int arr[100], even[100], odd[100];
int evenCount = 0, oddCount = 0;

printf("Input size of the array: ");


scanf("%d", &size);

printf("Input elements in array: ");


for(i = 0; i < size; i++)
{
scanf("%d", &arr[i]);

if(arr[i] % 2 == 0)
{
even[evenCount++] = arr[i];
}
else
{
odd[oddCount++] = arr[i];
}
}

printf("Even elements in array: ");


for(i = 0; i < evenCount; i++)
{
printf("%d ", even[i]);
}

printf("\n");

printf("Odd elements in array: ");


for(i = 0; i < oddCount; i++)
{
printf("%d ", odd[i]);
}

printf("\n");

return 0;
}

Screenshot:
Answer to Question NO. 3

#include <stdio.h>
#include <string.h>

void search(char arr[], char key)

{
int i, found = 0;

for(i = 0; arr[i] != '\0'; i++)


{
if(arr[i] == key)
{
found = 1;
break;
}
}

if(found)
printf("Found\n");
else
printf("Not found\n");
}

int main()
{
char str[100], key;

printf("Enter String: ");


gets(str);

printf("Search Key: ");


scanf(" %c", &key);

search(str, key);

return 0;
}
Screenshot:
Answer to Question NO. 4

#include <stdio.h>

int countSearchKey(int arr[], int size, int key)

{
int count = 0;
for(int i = 0; i < size; i++)
{
if(arr[i] == key)
{
count++;
}
}
return count;
}

int main()
{
int arr[100], size, key, i, result;

printf("Enter array size: ");


scanf("%d", &size);

printf("Array Elements: \n");


for(i = 0; i < size; i++)
{
scanf("%d", &arr[i]);
}

printf("Search Key: ");


scanf("%d", &key);

result = countSearchKey(arr, size, key);

printf("Search Key appears %d times\n", result);

return 0;
}

Screenshot:

You might also like