2.1 Fill the blanks in each of the following
a) every C program begins execution at the function -----.
main
b) Every functions's body begins with ----- and ends with -----.
{ , }
c) Every statement ends with an -----
semicolon (;)
d) The ----- standard library functions displays information on the screen.
printf
e) The escape sequence \n represents the ----- character, which causes the cursor to position to the beginning of the next line on the screen.
newline
f) The ----- Standard Library function is used to obtain data from the keyboard.
scanf
g) The conversion specifier ----- is used in a scanf format control string to indicate that an integer will be input and in a printf format control string to indicate that an integer will be output.
%d
h) Whenever a new value is placed in a memory location, that value overrides the previous value in that locatoin. this process is said to be -----.
overriding destructive
i) When a value is read from a memory location, the value in that location is preserved; this process is said to be -----
? nondescturctive
j) The ----- statement is used to make decisions.
if
2.2 State whether each of the following is true or false. If false, explains why.
a) F (not beginning with the new line)
b) F (not display on the screen)
c) T
d) T
e) T
f) F (not identical. C is case sensitive language)
g) T
h) F (not printf. but scanf.)
i) F (not only integer but also anything (e.g float, char etc.))
T ->'remainder operator(%)' can be use only with integer operands.
틀린이유 ) 형식지정자 %로 봄. 나머지 연산자는 오직 정수 연산항들에만 사용할 수 있음.
j) F (not have same level of precedence, first is *, / , % and the next is + and -)
k) F (not must contain three printf. It can be seperate by using a newline(\n))
2.3 Write a single C statement to accomplish each of the following.
a)
int c, thisVariable, q76354, number;
b)
printf("Enter a integer : \n");
c)
int a;
scanf("%d", &a);
d)
if(num != 7)
printf("The variable number is not equal to 7\n");
e)
printf("this is a C program");
f) so that the first line ends with c.
printf("This is a C\n");
printf("program.");
g)
printf("This\nis\na\nC\nprogram.");
h)
printf("This\tis\ta\tC\tprogram.");
2.4 Write a statement (or comment) to accomplish each of the following :
// a : program will calculate the product of three inteers.
printf("Enter three integers : "); // b
int x,y,z; // c
scanf("%d %d %d", &x, &y, &z); // d
int result = x*y*z; // e
printf("The product is : %d", result); // f
2.5 Using the statements you wrote in Ex 2.4, write a complete program that calculates the product of three integers.
#include <stdio.h>
int main(void){
// a : program will calculate the product of three inteers.
printf("Enter three integers : "); // b
int x,y,z; // c
scanf("%d %d %d", &x, &y, &z); // d
int result = x*y*z; // e
printf("The product is : %d", result); // f
}
2.6 Identify and correct the errors in each of the following statements:
a)
printf("The value is %d\n", number);
b)
scanf("%d %d", &number1, &number2);
c)
if(c < 7){
printf("C is less than 7\n");
}
d)
if(c >= 7){
printf("C is greater than or equal to 7\n");
}
'Programming Language > C' 카테고리의 다른 글
[C] chapter 02 : Exercises (0) | 2022.07.20 |
---|---|
[C] Week 4 : 연산자, if문 (0) | 2022.07.06 |
[C] Week 2 : C프로그램 구성 요소 (0) | 2022.07.05 |
[C] Week 1 : 프로그래밍의 개념, 프로그램 작성 과정 (0) | 2022.07.04 |
[C] 따옴표(' ")와 퍼센트(%) 출력 방법 (0) | 2022.02.06 |