In: Computer Science
PART A
Write a C program that takes the names and surnames of the students and then displays the initial and last name of the name on the screen. For instance, if Onur Uslu is entered as input, the output of our program must be O. Uslu.
PART B
Write a C program that asks the user to enter a string and then sends it to a function that does the following job and shows the response from the function on the screen. The function must return all words in the string from the program by converting the initial letters into their large form.
Example Output
Type of a string:Hello world
New sentence:Hello World
PART A:
CODE:
#include <stdio.h>
int main() {
int testcases;
char name[100];
char surname[100];
printf("Enter total number of testcases ::
");
scanf("%d",&testcases);
while(testcases--) {
printf("Enter SurName ::
");
scanf("%s",surname);
printf("Enter Name ::
");
scanf("%s",name);
printf("%c.
%s\n",surname[0],name);
}
return 0;
}
OUTPUT SCREEN:
PART B:
CODE:
#include <stdio.h>
int main() {
int testcases;
char string[200];
printf("Enter string :: ");
scanf("%[^\n]s",string);
int i;
for(i = 0; string[i] != '\0'; i++) {
if(i == 0 &&
string[i] >= 'a' && string[i] <= 'z') {
string[i] = string[i] - 32;
}
if(string[i] == ' '
&& string[i+1] >= 'a' && string[i+1] <= 'z')
{
i++;
string[i] = string[i] - 32;
}
}
printf("%s",string);
return 0;
}
OUTPUT SCREENS: