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

C programming 14 nov (1)

C programming basic programs

Uploaded by

jonadany2390
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)
8 views

C programming 14 nov (1)

C programming basic programs

Uploaded by

jonadany2390
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/ 6

9

Program 1 to change from upper case to lower case

Reverse of a string

Vowels and consonants

Alphabet digit vs character

Sort the string in ascending order


Program 1

#include <stdio.h>

void main() {

char str[100];

printf("Enter a string in uppercase: ");

scanf("%s", str);

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

if (str[i] >= 'A' && str[i] <= 'Z') {

str[i] = str[i] + ('a' - 'A');

printf("Lowercase string: %s\n", str);

}
Program 2

#include <stdio.h>

#include <string.h>

void main() {

char str[100];

int l;

printf("Enter a string: ");

scanf("%[^\n]s", str);

l = strlen(str);

printf("Reversed string: ");

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

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

printf("\n");

}
Program 3

#include <stdio.h>

void main()

char str[100];

int v = 0, c = 0;

printf("Enter a string: ");

scanf("%s", str);

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

char a = str[i];

if (a == 'A' || a == 'E' || a == 'I' || a == 'O' || a == 'U' ||

a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') {

v++;

} else if ((a >= 'A' && a <= 'Z') || (a >= 'a' && a <= 'z')) {

c++;

printf("Vowels: %d\n", v);

printf("Consonants: %d\n", c);

}
Program 4

#include <stdio.h>

int main()

char str[2];

printf("Enter a string: ");

scanf("%s", str);

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

if ((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z'))

printf(" '%c' is an alphabet.\n", str[i]);

} else if (str[i] >= '0' && str[i] <= '9')

printf(" '%c' is a digit.\n", str[i]);

} else {

printf(" '%c' is a special character.\n", str[i]);

return 0;

}
Program 5

#include <stdio.h>

#include <string.h>

int main() {

char str[100];

int temp;

printf("Enter a string: ");

scanf("%[^\n]s", str);

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

for (int j = i + 1; str[j] != '\0'; j++) {

if (str[i] > str[j]) {

temp = str[i];

str[i] = str[j];

str[j] = temp;

printf("New string: %s\n", str);

return 0;

You might also like