Show the output of the following programs as printed out by the computer. 1) #in
ID: 3697427 • Letter: S
Question
Show the output of the following programs as printed out by the computer.
1) #include
int main (void)
{
int *x,*y,*z, i;
int a[10]={9,8,7,3,4,5,6,7,8,9};
x= y = z =a;
for (i=0;i<8; i +=2)
printf("The value of a = %d ", a[i]);
printf(" case 1, X: %d , X: %d Y: %d Z: %d ", *x+3, *(x+3), *y , *z );
printf(" case 3, value is: %d ", *x+5 );
return 0;
}
#include
#include
int main ( )
{
char s1[20 ]="Have a ";
char s2 [ ] = "Nice day";
char s3 [40] = " ";
printf("s1= %s s2= %s ", s1, s2);
printf( " strcat ( s1, s2) = %s", strcat (s1, s2));
printf(" strncat (s3, s1, 6) = %s", strncat (s3, s1, 6) );
return 0;
}
Complete the following program as specified. This will be an example of pointer arithmetic. For e.g
#include
int main (void)
{
/* Local Definitions */
char *pDays[7];
char **pLast;
char **pWalker;
/* Statements */
pDays[0] = "Sunday";
pDays[1] = "Monday";
…
pDays[6] = "Saturday";
/* Print the elements of above array so that your output would be */
/*
The days of the week
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday */
return 0;
}
Given the code fragments, complete the program as directed in the comments. For e.g.
#include
typedef struct
{
int numerator;
int denominator;
} FRACTION;
int main (void)
{
/*Step 1. Create 3 objects of given structure( Suppose Fr1, Fr2, and Fr3*/
/*Step 2. Write the statement to scan the values from the keyboard for fields of the first two objects- Fr1, and Fr2, */
/*Step 3. Multiply the numerator fields of Fr1 and Fr2 . And store the result in the numerator field of Fr3*/
return 0;
}
Explanation / Answer
1. The output of the first part is:
The value of a = 9
The value of a = 7
The value of a = 4
The value of a = 6
case 1, X: 12 , X: 3 Y: 9 Z: 9
case 3, value is: 14
Here is the second part of the same question:
s1= Have a s2= Nice day
strcat ( s1, s2) = Have a Nice day
strncat (s3, s1, 6) = Have a
Here is the code for weekdays program:
char *pDays[7];
char **pLast;
char **pWalker;
/* Statements */
pDays[0] = "Sunday";
pDays[1] = "Monday";
pDays[2] = "Tuesday";
pDays[3] = "Wednesday";
pDays[4] = "Thursday";
pDays[5] = "Friday";
pDays[6] = "Saturday";
/* Print the elements of above array so that your output would be */
printf("The days of the week ");
for(int i = 0; i < 7; i++)
printf("%s ", *(pDays + i));
And the output for the last program is:
#include <stdio.h>
typedef struct
{
int numerator;
int denominator;
} FRACTION;
int main (void)
{
/*Step 1. Create 3 objects of given structure( Suppose Fr1, Fr2, and Fr3*/
FRACTION Fr1, Fr2, Fr3;
/*Step 2. Write the statement to scan the values from the keyboard for fields of the first two objects- Fr1, and Fr2, */
printf("Enter the numerator for the first fraction: ");
scanf("%i", &Fr1.numerator);
printf("Enter the denominator for the first fraction: ");
scanf("%i", &Fr1.denominator);
printf("Enter the numerator for the second fraction: ");
scanf("%i", &Fr2.numerator);
printf("Enter the denominator for the second fraction: ");
scanf("%i", &Fr2.denominator);
/*Step 3. Multiply the numerator fields of Fr1 and Fr2 . And store the result in the numerator field of Fr3*/
Fr3.numerator = Fr1.numerator * Fr2.numerator;
Fr3.denominator = Fr1.denominator * Fr2.denominator;
printf("The product is: %i/%i ", Fr3.numerator, Fr3.denominator);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.