0% found this document useful (0 votes)
64 views4 pages

Surigao State College of Technology: Instructions: Answer The Following Questions As Directed. Total of 100 Points

This document provides 10 questions testing knowledge of C string functions. For each question, it provides the code for a program implementing the relevant string function: 1) strrev to reverse a string, 2) strlwr to convert to lowercase, 3) scanf and printf to print an inputted string, 4) strcat to concatenate two strings, 5) strcpy to copy one string to another, 6) strupr to convert to uppercase, 7) concatenating two strings, 8) determining the length of a string, 9) comparing two strings with strcmp, and 10) merging a first and last name.

Uploaded by

Resty Ybanez
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)
64 views4 pages

Surigao State College of Technology: Instructions: Answer The Following Questions As Directed. Total of 100 Points

This document provides 10 questions testing knowledge of C string functions. For each question, it provides the code for a program implementing the relevant string function: 1) strrev to reverse a string, 2) strlwr to convert to lowercase, 3) scanf and printf to print an inputted string, 4) strcat to concatenate two strings, 5) strcpy to copy one string to another, 6) strupr to convert to uppercase, 7) concatenating two strings, 8) determining the length of a string, 9) comparing two strings with strcmp, and 10) merging a first and last name.

Uploaded by

Resty Ybanez
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/ 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