0% found this document useful (0 votes)
23 views

6 Introduction To C Programming

Uploaded by

Nanda Thakare
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
23 views

6 Introduction To C Programming

Uploaded by

Nanda Thakare
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
“EXERCISES” Q.1. Fill in the blanks : (1) C is a High level language. (2) A€ program must be compile before it can be executed. (3) Anamed area in memory that stores a character or numeric value is © called Variable. (4) In C, a number containing a decimal point of type float. 2 (5) The memory size of a floating 2 point number is usually 4 bytes. (6) The equality checking operator in > Cis. 2 (7) *%C” is the standard function to read a single character from keyboard. 2 Q.2. State whether the following statements are true or false. (1) Cis a interpreted language. Ans : False (2) In C, an user must define the 2 meaning of keyword used. (3) The type of variable determines what kind of values it may take on. Ans : True (4) A variable name can be begin with underscore, Ans : False (5) A variable declaration tells the name and type ofa variable. Ans : False (6) “34.5” is a numeric constant, Ans; False (7) The keyword int is used to declare © a constant. Ans : False (8) The expression 4+5*6 will evaluate to 54. Ans : False (9) The expression 4 * 2 to find the square of 4 is valid in C, Ans : False (10) The standard C functions are grouped into header files. Ans : True (11) The standard C function to find the absolute value of anumber x ¢ is abs(x). Ans : False (12) The format specifier for an integer in a printf statement in Cis \n, & Ans : False (13) Explanatory comments in C are given with the REM keyword. Ans : False Q.3. Give the purpose of each of the following in a C program, (1) float: float is a data type to store a © floating point number. E. 14 (2) char : char is a data type to store \4 a character. E.g. : ‘a” 2 (3) getchar() ; The function input a simple character from the keyboard. (4) scanf : The function performs formatted input. E.g. scanf(“%d”, & a); 3 (5) stdio.h : stdio.h is a header file which predefined standard input and $ output function. 2 (6) math.h : math.h is a header file which predefined mathematical function (7) \t = It is am escape sequence which is used in print. Q.4, Answer the following questions in e one or two sentences each : (1) What are the primary data types in$ G2. Ans : int (integer), char (Character), float (floating point number) and c double are the primary data type in C. © (2) What is a numeric constant? Ans : Numeric constant is a number. E.g. 2,3.142. > (3) What does the modulus operator do inc. Ans : Modulus operator returns the mode of a division. E.g. 4 % 3 = 1. 2 (4) What is the deference between the operators = and ==? is a assignment operator eg. s evaluating 2 numbers to find out the big one. (5) What is a header file? Ans : Header file is a predefined function which can be used in our program. (6) State the parts of a C program? Ans : Heading, inclusion, function main() with statements and optional user defined functions. (7) What is the purpose of the inclusion statements in a C program?? ¢ Ans : To include predefined user function to user program. Q.5. Write the C expression for. (1) raising 2 to the power 5: pow(2,5)s © (2) a= 7b +1 : pow(a,3)- (7*b)+1 (3) (5(f-32))/9 : (5 * (-32)/9 Q.6. Identify the valid variable name’ in C: m, N, 7N,-avg, Yod. 3 Ans: m,N. Q.7. The following statement block in C is supposed to calculate (at+b)’, but there are errors. Find out the errors and rewrite the statement block. int a ==5, b=6,ans ans=(at+b)*3; printf(The answer is, ans); 2 Ans : int a=5,b=6,ans; ans=(a+b) * 3; > printf(“The answer is %d “, ans); ==> Q.8. Answer the following in brief : (1) State the limitations of naming the variable in C. Ans : (i) Every variable name must start with a letter 0 an underscore. (ii) C recognizes upper and lowercase characters as being different. (iii) You cannot use nay of C's keywords (the words such as main, while, switch, ete. which are part of the syntax of the language) as variable © names, (2) Write short note on relational operators. Ans : These operators are used to make comparison and control the > flow of logic in a program using the if 2 and switch statements. 2 (3) Write short note on program > structure in C. Ans ; The program starts with a series 3 of comments indicating its purpose, as well as its author. This is called 3 heading, It is considered good programming style to identify and 3 document your work. Explanatory 3 comments can be written anywhere in the code ; all characters between /* 2 and */ are ignored by the compiler and 2 can be used to make the code easier to understand, Q.9. Write C programs for the following : (1) Input a value for the radius of a circle and display the area of the circle. Ans: #include main() { float areayr; float PI=3.14; printf("enter radius\n"); seanf("%f",&r); area=PI*r*rz printf("area of circle is %f",area); 2 (2) Input the value for the side of a 2 square and display its perimeter and 5 #include 2 #include 2 int main(){ float side, area; printf(""Enter length of side of 2 square\n"); scanf("%f", &side); /* Area of Square = Side X Side */ area = pow(side, 2); printf("Area of square : %0.4f\n", > area); perimeter = 4*side: printf("Perimeter of Square : %0.4f\n", perimeter); getch(); return 0; (3) Input two numbers and display the square of their sum. Ans: #include #include int main() { int num1, num2, sqrl, sqr2, sum; printf("Enter any two numbe ds seanf("%d%d", &num1, &num2); sqrl = num1*num1; sqr2 = num2*num2; sum = sqrl + sqr2; printf("Sum of their square = %d", sum); getch(); return 0; } Q.10. Write C programs for the following problems from your mathematics textbook : (1) The radius of the base of a cone is § cm and its slant height is 13 cm. Find. the volume of the cone. Ans: #include int main() { const float PI = 3.14; float r, h, volume; r=5; h=13; volume =(PI* r*r* h)/3.0; printf("Volume of Cone is %f\n", volume)3} (2) The base area of a cone is 10.5. square units and its slant height is 10 cm, What is the curved surface area of $ the cone? Ans: #include #include #define PI 3.14159 int main(){ float radius, height, surfaceArea; radius = 10.5; height = 10; surfaceArea = PI*radius*(radius + sqrt(height*height + radius*radius)); printf("Total surface area of Cone ; %0.4f\n", surfaceArea); return 0; —————————

You might also like