0% found this document useful (0 votes)
12 views5 pages

Strings Lab Questions

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)
12 views5 pages

Strings Lab Questions

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/ 5

1. Write a C program to print the characters of a string in reverse.

Example:
Input:
Enter a string:Test*String67!

Output:
Reverse:!76gnirtS*tseT

Template

#include <stdio.h>
/* Include any headers here */

int main() {

/* Put your declarations here */

char str[100];

printf("Enter a string:");

/* --- Start your solution here --- */

printf("Reverse:");

/* --- End of the solution --- */


Return 0;

}
2. Write a C program to count number of Alphabets, Digits and Special Characters in a
string

Example
Input:

Enter a string:uyuy$%^78iu e

Output:

Alphabets:7
Digits:2
Special Characters:6

Template

#include <stdio.h>
/* Include any headers here */

int main() {

/* Put your declarations here */

char str[100];
int alphabets = 0, digits = 0, special = 0;

printf("Enter a string:");

/* --- Start your solution here --- */

printf("Alphabets:%d\n", alphabets);
printf("Digits:%d\n", digits);
printf("Special Characters:%d\n", special);

/* --- End of the solution --- */


Return 0;
}
3. Write a C program to count the total number of words in a given string

Example
Input:

Enter a string: This is just a long test string

Output:

Total Words: 7

Template

#include <stdio.h>
/* Include any headers here */

int main() {

/* Put your declarations here */

char str[100];
int word_count = 0;

printf("Enter a string:");

/* --- Start your solution here --- */

printf("Total Words:%d\n", word_count);

/* --- End of the solution --- */


Return 0;
}
4. Write a C program to sort characters in a given string in ascending order

Example
Input:
Enter a string:trytosortthis
Output:
Sorted:hioorrsstttty
Example2 Input:
Enter a string:this is a test to sort
Output
Sorted: aehiioorssssttttt

Template

#include <stdio.h>
/* Include any headers here */

int main() {

/* Put your declarations here */

char str[100];
int word_count = 0;

printf("Enter a string:");

/* --- Start your solution here --- */

printf("Sorted:%s", str);

/* --- End of the solution --- */


Return 0;
}
5. Write a C program to concatenate two strings

Example
Input:
String1:this is a
String2:test

Output:
Result:this is atest

Template

#include <stdio.h>
/* Include any headers here */

int main() {

/* Put your declarations here */

char str1[100], str2[50];

printf("String1:");

/* -- logic to input string -- */

printf("String2:");

/* -- logic to input string -- */


/* --- Start your solution here --- */

printf("Result:%s", str1);

/* --- End of the solution --- */


Return 0;

You might also like