0% found this document useful (0 votes)
21 views6 pages

Ces 33

Lab report

Uploaded by

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

Ces 33

Lab report

Uploaded by

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

Implementa on:

Separate Vowels and Consonants


#include <stdio.h>

#include <string.h>
int main() {
char arr[] = "Hello World";
char vowels[100], consonants[100];
int vi = 0, ci = 0;
for (int i = 0; arr[i] != '\0'; i++) {
if (arr[i] == 'a' || arr[i] == 'e' || arr[i] == 'i' || arr[i] == 'o' ||

arr[i] == 'u' || arr[i] == 'A' || arr[i] == 'E' || arr[i] == 'I' ||

arr[i] == 'O' || arr[i] == 'U') {

vowels[vi++] = arr[i];
}
else if (arr[i] != ' ') {
consonants[ci++] = arr[i];
}
}
vowels[vi] = '\0';
consonants[ci] = '\0';
printf("vowels: %s\n", vowels);
printf("consonants: %s\n", consonants);
return 0;
Output
}
Merging Two Strings Alternately into a New String
#include <stdio.h>

#include <string.h>

int main() {

char arr1[] = "abcde";

char arr2[] = "12345";

char arr3[11];

int j = 0;

printf("string1 = %s\n", arr1);

printf("string2 = %s\n", arr2);

for (int i = 0; i < 5; i++) { Output


arr3[j] = arr1[i];

j++;

arr3[j] = arr2[i];

j++;

arr3[j] = '\0';

printf("output = %s\n", arr3);

return 0;

Reversing a String
Output
#include <stdio.h>
#include <string.h>
int main() {
char input[] = "ABCDE";
int length = strlen(input);
printf("Input: %s\n", input);
printf("Reversed output: ");
for (int i = length - 1; i >= 0; i--) {
printf("%c", input[i]);
}
printf("\n");
return 0;
}
Concatenate Two Strings Without Using strcat()
#include <stdio.h>
int main() {
char string1[10];
char string2[10];
char string3[30];
printf("Enter first string: ");
gets(string1);
printf("Enter second string: ");
gets(string2);
int i = 0, j = 0;
while (string1[i] != '\0') {
string3[i] = string1[i];
i++;
}
while (string2[j] != '\0') {
string3[i + j] = string2[j];
j++;
}
Output
string3[i + j] = '\0';
printf("Output= ");
puts(string3);
return 0;
}
Finding the Highest and Lowest Values in an Array with Their Indices
#include <stdio.h>
int main() {
int arr[5] = {10, 2, 31, 4, 9};
int hi = 0, li = 0;
int hv = arr[0], lv = arr[0];
for (int i = 1; i < 5; i++) {
if (arr[i] > hv) {
hv = arr[i];
hi = i;
}
if (arr[i] < lv) {
lv = arr[i];
li = i;
}
}
printf("Highest: Index = %d, Value = %d\n", hi, hv);
printf("Lowest: Index = %d, Value = %d\n", li, lv);
return 0;
}
Output
Removing Spaces from a String
#include <stdio.h>
int main() {
char arr1[] = "CSE - 272";
char arr2[50];
int i = 0, j = 0;
while (arr1[i] != '\0') {
if (arr1[i] != ' ') {
arr2[j] = arr1[i];
j++;
}
i++;
}
arr2[j] = '\0';
printf("Original String: %s\n", arr1);
printf("String without spaces: %s\n", arr2);
return 0;
}
Output
Separate Capital and Small Letters from a String
#include <stdio.h>
int main() {
char str[] = "AEaeLlMm";
char c[100], s[100];
int i, ci = 0, si = 0;
for(i = 0; str[i] != '\0'; i++) {
if(str[i] >= 'A' && str[i] <= 'Z') {
c[ci++] = str[i];
} else if(str[i] >= 'a' && str[i] <= 'z') {
s[si++] = str[i];
}
}
c[ci] = '\0';
s[si] = '\0';
printf("Capital letters: %s\n", c);
printf("Small letters: %s\n", s);
return 0;
}
Output

You might also like