0% found this document useful (0 votes)
26 views

Lab 3

C programming

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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Lab 3

C programming

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 DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#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';

puts(vowels);

puts(consonants);

return 0;

---------------------------------------------------

#include <stdio.h>

#include <string.h>

int main() {

char arr1[] = "abcde";

char arr2[] = "12345";

char arr3[11];

int j=0;

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

arr3[j] = arr1[i];

j++;
arr3[j] = arr2[i];

j++;

arr3[j] = '\0';

puts(arr3);

return 0;

----------------------------------------

#include <stdio.h>

#include <string.h>

int main() {

char input[] = "ABCDE";

int length = strlen(input);

printf("Reversed: ");

for (int i = length - 1; i >= 0; i--) {

printf("%c", input[i]);

return 0;

----------------------------------------------------

#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++;

string3[i + j] = '\0';

printf("Output= ");

puts(string3);

return 0;

----------------------------------------------------

#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;

---------------------------------
#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;

---------------------------------------------

#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;

You might also like