The purpose of this homework assignment is to confirm (or refute) some of the st
ID: 3846902 • Letter: T
Question
The purpose of this homework assignment is to confirm (or refute) some of the statements made in the lectures about C program behavior. Output the results of your various tests (including before and after results as appropriate)! Note that the questions are written as "confirm" but you may actually demonstrate that what the book says is not what your C compiler does! You may write a single program or separate programs to answer each of the following questions. If you do separate programs, please use file names of the form "csl325a01- nnJDoe" where nn is the question number and JDoe represents your name. If any of the following causes your program to abnormally end, you may get a screenshot of the output and comment out the offending line(s). Submit both the text of your program(s) and a screenshot of the result of executing the program. The format of the filenames should be roughly csl325a01jdoe.c (or .txt) and csl325a01jdoe.png (or .jpg). 1) Confirm that will cause the computer to beep. 2) Output the text "12345678" (without a ), then confirm that will back the cursor up three spaces by overwriting the "678" with "abc" 3) Output the text "1234", then a horizontal tab character, then the text "abc". 4) Output the size (in bytes) of the following data types: char, short int, int, long int, float, double, and long double using the sizeof() function with appropriate descriptive text. 5) Assign the largest possible integer to an int variable. Output the contents of the variable. Add 1 to it. Output. Subtract 1 from it. Output. 6) Create a named constant with value 17.49. Output. 7) Define a literal with value 14. Output. 8) Initialize integer x=7. Write code to the effect that if(x) then print "X is true" and the value of x, else print "X is false" and the value of x Each of the parts above is worth 10 points (80 total). Including comments at the beginning of your program with your name, the class, and the assignment is worth 10 points. Including comments in the body of the program describing what you are doing is worth 10 points.Explanation / Answer
1.
#include <stdio.h>
int main(void)
{
printf(" ");
return 0;
}
2.
#include <stdio.h>
int main(void)
{
printf("12345678abc");
return 0;
}
3.
#include <stdio.h>
int main(void)
{
printf("1234 abc");
return 0;
}
4.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch = 'a';
printf("The size of char is %zu ", sizeof(ch));
short int i = 1;
printf("The size of short integer is %zu ", sizeof(i));
int j = 10;
printf("The size of integer is %zu ", sizeof(j));
long int k = 20;
printf("The size of long integer is %zu ", sizeof(k));
float l = 1.1;
printf("The size of float is %zu ", sizeof(l));
double m = 1.2;
printf("The size of double is %zu ", sizeof(m));
long double n = 1.3;
printf("The size of long double is %zu ", sizeof(n));
}
5.
#include <stdio.h>
#include <limits.h>
int main()
{
int x = INT_MAX;
printf("Max = %d ", x);
x=x+1;
printf("X+1 = %d ", x);
x=x-1;
printf("X-1 = %d ", x);
return 0;
}
6.
#include <stdio.h>
int main()
{
const int a =17;
printf("constant a is %d ", a);
return 0;
}
7.
#include <stdio.h>
#define A 14
int main()
{
printf("Literal A is %d ", A);
return 0;
}
8.
#include <stdio.h>
int main()
{
int x = 7;
if(x)
printf("X is true. %d ", x);
else
printf("X is false. %d ", x);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.