You are on page 1of 4

LEA

LEARNING MODULE NO. 5 – POST TEST


POST Instructions: Answer the following questions as directed. Total of 100 points.
TEST
1. Write a program using string function that reverses the string.

#include <stdio.h>
#include <string.h>
int main()
{
   char s[100];

   printf("Enter a string to reverse\n");


   gets(s);

   strrev(s);

   printf("Reverse of the string: %s\n", s);

   return 0;
}

2. Create a program using string functions to convert a character from


uppercase to lowercase.
LEARNING MODULE SURIGAO STATE COLLEGE OF TECHNOLOGY
#include <stdio.h>
#include <string.h>
int main()
{
   char string[1000];
  
   printf("Input a string to convert to lower case\n");
   gets(string);
    
   printf("The string in lower case: %s\n", strlwr(string));
    
   return  0;
}

3. Create a program using string functions to print the inputted string.

#include <stdio.h>
int main()
{
char name[20];
printf("Enter name: ");
scanf("%s", Resty);
printf("Your name is %s .", Resty);
return 0;
}

CpE 143 - COMPUTER PROGRAMMING (DR. ANALYN S. MORITE) 1


LEA

4. Create a program to concatenate two strings using strcat function.


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

int main()
{
char a[100], b[100];

printf("Enter the first string\n");


gets(a);

printf("Enter the second string\n");


gets(b);

strcat(a,b);

printf("String obtained on concatenation is %s\n",a);

return 0;

}
LEARNING MODULE SURIGAO STATE COLLEGE OF TECHNOLOGY
5. Create a program to copy one string to another using strcpy function.

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

main()
{
char source[] = "C Program";
char destination[50];
strcpy(destination, source);
printf("Source string: %s\n", source);
printf("Destination string: %s\n", destination);
return 0;
}

CpE 143 - COMPUTER PROGRAMMING (DR. ANALYN S. MORITE) 2


LEA

6. Create a program using string function to convert a character from


lowercase to uppercase.

#include <stdio.h>
#include <string.h>
int main()
{
   char string[1000];
  
   printf("Input a string to convert to upper case\n");
   gets(string);
    
   printf("The string in upper case: %s\n", strlwr(string));
    
   return  0;
}

7. Create a program using string function that would join strings.

#include<stdio.h>
#include<string.h>
void concat(char[], char[]); 
int main() {
char s1[50], s2[30];

SURIGAO
printf("\nEnter String
LEARNING MODULE 1 :"); STATE COLLEGE OF TECHNOLOGY
gets(s1);
printf("\nEnter String 2 :");
gets(s2);
concat(s1, s2);
printf("nConcated string is :%s", s1);

return (0);
}

8. Create a program using string function that would display the length of
the string.
#include <iostream>
usingname space std;

int main() {
string str = C++ programming";

count <<, "String Length = " << str.lenght()

return 0;
}

CpE 143 - COMPUTER PROGRAMMING (DR. ANALYN S. MORITE) 3


LEA

9. Create a program using string function that would display if the two
strings are equal/similar or not.

#include <stdio.h>
#include <string.h>
int main()
{
   char a[100], b[100];

   printf("Enter a string\n");
   gets(a);

   printf("Enter a string\n");
   gets(b);

   if (strcmp(a,b) == 0)
      printf("The strings are equal.\n");
   else
      printf("The strings are not equal.\n");

   return 0;
}

10. Create a program using string function that would merge your first
LEARNING MODULE SURIGAO STATE COLLEGE OF TECHNOLOGY
name to your family name.

CpE 143 - COMPUTER PROGRAMMING (DR. ANALYN S. MORITE) 4

You might also like