write a C code to add two polynomials having n number of unknown variables
3. Using the online compiler:-
• Enter the code from the file bitwise_demo.c
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
byte_t result;
byte_t second_byte;
byte_t first_byte;
int shift;
// Reading the first byte. Integer is entered then cast to byte_t.
printf("Enter the value of the first_byte (0-255): ");
scanf("%d", &i);
first_byte = (byte_t)i;
// Reading the second byte. Integer is entered then cast to byte_t.
printf("Enter the value of the second_byte (0-255): ");
scanf("%d", &i);
second_byte = (byte_t)i;
printf("\n\n");
// The results will be printed out in hexadecimal.
// The %X placeholder is for hexadecimal output.
// This can be extended to %02X, i.e. a hexadecimal
// character, 2 characters wide, with leading blanks
// filled-in as zeros.
// Bitwise inversion
result = ~first_byte;
printf("The value of ~(%02X) is %02X\n", first_byte, result);
result = ~second_byte;
printf("The value of ~(%02X) is %02X\n\n\n", second_byte, result);
// Bitwise AND, OR, XOR
result = first_byte & second_byte;
printf("The value of (%02X) & (%02X) is %02X\n",
first_byte, second_byte, result);
result = first_byte | second_byte;
printf("The value of (%02X) | (%02X) is %02X\n",
first_byte, second_byte, result);
result = first_byte ^ second_byte;
printf("The value of (%02X) ^ (%02X) is %02X\n",
first_byte, second_byte, result);
system("pause");
return 0;
}• Add this source code to your logbook.
• Run the program. You will be prompted to enter two values between 0 and 255. Initially enter 234 and 37.
• Add the output of this program to your logbook.
• Repeat this with other values of your choice.
• Write a short reflective account of the code concentrating on its functionality and comparing the outputs against the source code.
2. Using the online compiler
• Enter the code from the file bit_shift_demo.c
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
byte_t first_byte = 128;
byte_t second_byte = 1;
int shift;
printf("Enter the number of left/right shifts: ");
scanf("%d", &shift);
printf("\n\n");
// Right-shift first_byte
first_byte = first_byte >> shift;
// Left-shift second byte
// This is the equivalent of second_byte = second_byte << shift;
second_byte <<= shift;
// Display the results
printf("128 >> %d = %d\n", shift, first_byte);
printf("1 << %d = %d\n", shift, second_byte);
system("pause");
return 0;
}Run the program. You will be prompted to enter a value for the number of shifts. Initially enter the value of zero
• Add the output of this program to your logbook.
• Repeat the previous two steps with values of 1, 2, 3, 4, 5, 6, 7, and 8.
• Write a short reflective account of the code concentrating on its functionality and comparing the outputs against the source code.
1. Using the online compiler (or Dev C++):-
• Enter the code from the file operators.c https://vle.dmu.ac.uk/bbcswebdav/pid-5463722-dt-content-rid-10886002_1/courses/ENGD1025_2122_520/operators%281%29.c
• Add this source code to your logbook.
• Run the program. You will be prompted to enter integer values for a and b. Enter 4 for a, and 5 for b.
• Add the output of this program to your logbook
• Write a short reflective account of the code concentrating on its functionality and comparing the outputs against the source code.
3. Write a C program using an online C compiler that implements the following:-
• Declare a string; upon initialization populate the string with a phrase of your choice.
• Declare a second-string; upon initialization populate that string with a different phrase of your choice.
• Display both strings using a single printf() function call.
2. Write a C program using an online C compiler (or Dev C++) that implements the following:-
• Declare a 10-element floating-point array; give the array a suitable name.
• Declare an integer variable (of type int); call it i
• Upon declaration, populate the array with 10 floating-point numbers of your choice.
• Prompt the user to enter a value between 0 and 9
• Read a number from the keyboard into i
• Display the ith element of the array
1. Write a C program using an online C compiler that implements the following:-
• Declare a floating-point variable (of type float)
• Declare an integer variable (of type int)
• Prompt the user to enter a floating-point number.
• Read a number from the keyboard into your floating-point variable
• Using casting, write the contents of your floating-point variable into your integer variable • Display the value of your integer variable.
1. In the following program, what would be the final output? Explain in
detail.
void copyarr( char ∗p1 , char p2 [ ] ) {
memcpy ( p2 , p1 , size of ( p1 ) ) ;
memcpy ( p2 , ‘ ‘ABCD’ ’ , 4 ) ;
}
int main ( ) {
char arr1 [ 100 ] ;
char arr2 [ 100 ] ;
printf( ‘ ‘ Enter a string : ’ ’ ) ;
scanf ( ‘ ‘%[ ˆ\n ] s ’ ’ , arr1 ) ;
copyarr ( arr1 , arr2 ) ;
printf ( ‘ ‘ \ n %s ’ ’ , arr2 ) ;
return 0 ;
}
Write a program to enter the numbers till the user wants and at the end it should display the
count of even, odd and prime numbers entered.
write a C code to add two polynomials having n number of unknown variables