Some homework problems taken directly from the textbook: Write a single statemen
ID: 3694826 • Letter: S
Question
Some homework problems taken directly from the textbook: Write a single statement to accomplish each of the following. Assume that variables c (which stores a character), x, y, and z are of type int, variables d, e, and f are of type double, variable ptr is of type char * and arrays s1 [100] and s2[100] are of type char. Convert the character stored in variable c to an uppercase letter. Assign the result to variable c. Determine if the value of variable c is a digit. You can use the conditional operator as shown in figure 8.2 from the presentation or you can just use an if then else statement. Read a line of text into array s1 from the keyboard. Do not use scanf. Print a line of text stored in array s1. Do not use printf. Print the value of variable c. Do not use printf. Determine if the value of variable c is a letter. You can use the conditional operator as shown in figure 8.2 from the presentation or you can just use an if then else statement Read a character from the keyboard and store the character in variable c. Copy the string stored in array s2 into array s1. Compare the string s1 with the string s2. Print the result, Append 10 characters from the string s2 to the string s1. Determine the length of string s1. Print the result. What, if anything, prints each of the following C statements is performed? If the statement contains an error, describe the error and indicate how to correct it. Assume the following variable declarations: char s1 [50] = "jack", s2[50] = " jill", s3[50], *sptr; printf ("%c%s", toupper(sl [0]), &sl; [1]); printf ("%s", strcpy (s3, s2)); printf ("%s",strcat(strcat(strcpy(s3,sl), " and "), s2)); printf ("%u", strlen(sl) + strlen(s2)); printf ("%u", strlen(s3)); Find the error in each of the following program segments and explain how to correct it: chars[10]; strncpy (s, "hello", 5); printf ("%s ", s); printf ("%s",'a'); char s[ 12]; strcpy(s,"Welcome Home"); if (strcmp (string 1, string2)) printf ("The strings are equal ");Explanation / Answer
1)
a) c = c - 'a'+'A'
b) if(a>='0' && a<='9')
printf("a is a digit");
else
printf("a is not a digit");
c) fgets (s1,100, stdin);
d) puts(s1)
e) putchar(c);
f) if((c>='a' && c<='z') || (c>='A' && c<='Z'))
printf("c is a letter");
else
printf("c is not a letter");
g) c=getchar();
h) strcpy(s1,s2);
i) if(strcmp(s1,s2)==0)
printf("They are same");
else
printf("They are different");
j) for(i = strlen(s2),j=0;i<strlen(s2)+10;i++,j++)s2[i]=s1[j];
k) for(i = 0;i<100;i++)if(s1[i]=='')break;
printf("The length is %d",i);
2)
a) J ack
b) jill
c) Jack and jill
d) 8
e) 13
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.