Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore Digital Book Class-10 2nd edition

Digital Book Class-10 2nd edition

Published by Memorica Graphics, 2023-03-19 00:00:01

Description: Digital Book Class-10 2nd edition

Search

Read the Text Version

["Smart Computer Science Book-10 Gupta for the above mentioned cases. 5. \t Ram Janam Chaudhary is a class teacher of class X, he wants to keep the marks detail of his students in the computerized system. For this purpose, he needs the following programs initially. a. \tRam Janam needs a main data file MARKS.DAT and store Student's ID, name, marks obtained in each subject. The program should terminate in the user's choice. b. \tHe needs to display complete records with total and percentage marks. c. \tHe needs a program to add more records in the main file, when a new student is admitted. d. \tSometimes students may leave the school, in such a case he needs to delete records from the main file. e. \tSometimes he needs to list the records of only those students who are passed or failed. The percentage is 40 for pass marks. This is the current criteria. f. \t He needs to copy records in the new separate data file as llike: \t Percentage\t file name \t<40\t\t GROUP1.DAT \t<60\t\t GROUP2.DAT \t<80\t\t GROUP3.DAT \t<100\t\t GROUP4.DAT g. \tSometimes, it is necessary to add or subtract the marks of specified subject due to common error. For example, mathematics marks would be increased by 5 marks for every student. Project Work 1.\t Write a menu control program using the modular programming technique in the any one case of Jogindar Yadav or Shivani Gupta or Ram Janam Chaudhary. The program should include the following topics: a. \t Cover page b. \t Background of project c. \t Table of contents d. \t Algorithm or Flowchart e. \t Codes f. \t Output Screen g. \t Conclusion Approved by Curriculum Development Center (CDC) 301","Basic of C Programming CHAPTER Basic of C Programming 16 Chapter Includes \u2022\t Introduction to C language \u2022\t Concept of structured programming \u2022\t Basic elements of C Language \u2022\t Common I\/O Function in C \u2022\t Decision Making \u2022\t Loops in C INTRODUCTION TO C LANGUAGE C is a structured procedural programming language. It was initially developed by Dennis Ritchie in the year 1972 at the Bell Telephone Laboratories. It was mainly developed as a system programming language to write an operating system. It was used first time to develop the UNIX operating system. C is the most widely used computer high level language. It is also called middle level language because it stands between high level language and low level language; means, it has a combination features of assembly language and high level language. Why to learn C Language 'C' is a base language for many programming languages. So, learning 'C' as the main language will play an important role while studying other programming languages. It shares the same concepts such as data types, operators, control statements and many more. 'C' can be used widely in various applications. It is technically simple language and it provides faster execution. Features of C Language \u2022\t It has rich and powerful set of operators. \u2022\t It is easy to learn \u2022\t It is a case sensitive language \u2022\t It is structured language \u2022\t It has very less number of reserved words. \u2022\t It can handle low-level activities \u2022\t It allows manipulation of internal processor's registers. \u2022\t It can be compiled on a variety of computer platforms CONCEPT OF STRUCTURED PROGRAMMING The structured program consists of well structured and separated modules. But the entry and exit in a structured program are a single-time event. It means that the program uses single-entry and single-exit points. Therefore a structured program is well maintained, neat and clean. This is the reason why the structured programming approach is well accepted in the programming world. 302 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 The structured program mainly consists of three types of control structures: No Yes i) Sequential Structure ii) Selection Structure iii) Loop Structure 'C' language is called a structured programming language because it is devised to solve a large problem. It divides the problem into smaller modules called functions or procedures each of which handles a particular responsibility. The program which solves the entire problem is a collection of such functions. ADVANTAGES OF STRUCTURED PROGRAMMING \u2022\t Easier to read and understand \u2022\t Divides the problem in small manageable functional block \u2022\t User friendly \u2022\t Easier to maintain \u2022\t Development is easier as it requires less effort and time \u2022\t Easier to debug \u2022\t Modules can be reused LIMITATION OF C \u2022\t It does not support object oriented programming technique \u2022\t C compilers can only identify errors and are incapable of handling exceptions (run-time errors). \u2022\t C provides no data protection. \u2022\t It also doesn't feature reusability of source code extensively. \u2022\t It does not provide strict data type checking (for example an integer value can be passed for floating data type). APPLICATION OF C LANGUAGE C language was developed for the system development work. It was mainly Approved by Curriculum Development Center (CDC) 303","Basic of C Programming developed as a system programming language such as operating system. First time, it was used to write the UNIX operating system. It is more popular and used to develop the system programs such as: a) Operating System software\t b) Interpreters, compilers and assemblers c) Text editors\t\t\t\td) Linkers e) Loaders\t\t\t\t f) Utilities software g) Network devices software\t h) Database Management system Comparison between QBASIC and C Language QBASIC C Language It is high level language. It is high level language with some features of low level language. It uses the interpreter. It uses the compiler. It is a structured programing language. It is also a structured programming language. It has more key words around 159. It has less keywords, only 32 keywords. It is used to design application software. It is used to design application software as well as sys- tem software. It supports SUB and FUNCTION proce- It supports only FUNCTION procedure. dures. It supports both local and global variables. It also supports both local and global variables. BASIC ELEMENTS OF C LANGUAGE Every programming language has basic element and grammatical rules. Similarly the C language has some elements and rules for building a program which has some meaning. These elements are the valid character set, identifiers, keywords, basic data types and their representation, constants and variables. Character Set There are certain character sets in the C language which are used during the programming in C and supported by the C compiler. The following table shows the valid character sets: Types Character Set Alphabet A, B, C................ X, Y, Z a , b, c........................x, y, z Special characters ~ ! @ # $ \u2018 % ^ & * () _ - + = \\\\ | { } [ ] : ; \u201c < > , . ? \/ \u201d \u2019 Number 0-9 Blank spaces, Horizontal tab, Vertical tab, Carriage return, New line, White spaces Form feed. 304 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 C keywords Keywords are reserved words, which are reserved by the compiler. Keywords cannot be used as variable names. C has only 32 keywords. The following are the list of C keywords: auto\t\tbreak\t\tcase\t\tchar \t\tconst\t\tcontinue default\t\tdo\t\tdouble\t\telse\t\tenum\t\textreme float\t\t far\t\t for\t\t goto\t\t if\t\t int long\t\tnear\t\tregister\t\treturn\t\tshort\t\tsigned\t\t static\t\tstruct\t\tswitch\t\ttype \t\tdef \t\tunion\t\t unsigned\tvoid Data Types in C In C programming, data types are declarations for variables. This determines the type and size of data associated with variables. C supports two types of data: i) Basic data types \t\t ii) Derived data types Basic data types: Basic data types are the fundamental data types which are in commonly used. The following table shows the basic types of data types: \t Data Type Description Byte Range char Character 1 0-255 int Integer 2 -32768 to 32767 float Single precision 4 1.2E-38 to 3.4E+38 6 decimal place double Double precession 8 2.3E-308 to 1.7E+308 15 decimal place Void null data types Data Types Modifiers Data modifiers change the meaning of the basic data type to fit the various situations. The data types modifiers are short, unsigned, and long. Some examples of data modifiers are: Modifiers Description Byte Range short Short integer 2 \u221232,768 to 32,767 long Long integer 2 -2,147,483,648 to 2,147,483,647 signed Signed short integer 4 \u221232,768 to 32,767 unsigned Unsigned short integer 4 0 to 65,535 Signed long integer 4 -2,147,483,648 to 2,147,483,647 Unsigned long integer 4 0 to 4,294,967,295 Long double 10 3.4E-4932 to 1.1E+4932 19 decimal places Signed char 1 \u2212128 to 127 Unsigned char 1 0 to 255 Approved by Curriculum Development Center (CDC) 305","Basic of C Programming Derived Data Type: Data types that are derived from fundamental data types are called derived types. For example: arrays, pointers, function types, structures, etc. We will learn about these derived data types in higher classes. Identifiers C identifiers represent the name in the C program, for example, variables, functions, arrays, structures, unions, labels, etc. float x=10.5\t\t int sum = 10+20;\t int xyz() \u2022\tHere, x, sum and xyz are the identifiers Rules for constructing C identifiers \u2022\t An Identifier can only have alphanumeric characters (a-z , A-Z , 0-9) and underscore(_). \u2022\t The first character of an identifier can only contain alphabets (a-z , A-Z) or underscore (_). \u2022\t Identifiers are also case sensitive in C. name and Name are two different identifiers in C. \u2022\t Keywords are not allowed to be used as identifiers. \u2022\t No special characters, such as a semicolon, period, white spaces, slash or comma is permitted to be used in or as an identifier. Tokens in C TOKEN is the smallest unit in a 'C' program. It is each and every word and punctuation that comes across in your C program. The compiler breaks a program into the smallest possible units or the block is known as token. A token is divided into six different types: \t i) Keywords (int, char, if, do) \t\t\t ii) Operators\t (+, -, < )\t\t \t iii)Strings (\\\"Nepal\\\", \\\"Sum=\\\")\t\t\tiv) Constants (10, 20, \\\"Ram\\\") \t v) Special characters (, ; ! { })\t\t\t vi)Identifiers (main, total, a, b) For example, let's consider the following code. There are five tokens: \t\t printf(\\\"Hello, World! \\\\n\\\"); Let's break down in the individual tokens are: printf ( \\\"Hello, World! \\\\n\\\" ) ; Constants in C A constant is a value that can't be changed in the program code. Following are the types of constants. 306 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Types Character Set Integer constant 10, 20 Character constant 'A' , 'b', 'x' Real constant 3.55 String constant \\\"c programming\\\" Literals Literals are the constant values assigned to the constant variables. The literals represent the fixed values that cannot be modified. For example, const int a=10; is a constant integer expression in which 10 is an integer literal. Void Void is an empty data type that has no value. We use void data type in functions when we don\u2019t want to return any value to the calling function. \t\tvoid main() \/\/This main () function doesn't return anything. Format Specifier The format specifiers are used in C for input and output purposes. The Format Specifier tells the compiler what type of data is stored in a variable during taking input using the scanf() function and printing using printf() function. Here is a list of format specifiers. Format \t Specifier Type Format \t Specifier Type %c\t\tCharacter %lu\t\tUnsigned int or unsigned long %d\t\tSigned integer %lli or %lld\t\tLong long %e or %E\t\tScientific notation of floats %llu\t\tUnsigned long long %f\t\tFloat values %o\t\tOctal representation %g or %G\t\tSimilar as %e or %E %p\t\tPointer %hi\t\tSigned integer (short) %s\t\tString %hu\t\tUnsigned Integer (short) %u\t\tUnsigned int %i\t\tUnsigned integer %x or %X\t Hexadecimal representation %l or %ld or %li\t\tLong %n\t\tPrints nothing %lf\t\tDouble %%\t\tPrints % character %Lf\t\tLong double Comments in C Comments in C language are used to provide information about lines of code. It is widely used for documenting code. There are 2 types of comments in the C language. Comment is non-executable. Single Line Comments: Single line comments are represented by double slash \/\/. Let's see an example of a single line comment in C. \t\t int main(){ \t \/\/printing information Approved by Curriculum Development Center (CDC) 307","Basic of C Programming \t printf(\\\"Hello C\\\"); \t\treturn 0; \t\t} Multi-Line Comments: Multi-Line comments are represented by slash asterisk \/* ... *\/. It can occupy many lines of code, but it can't be nested. Let's see an example of a multi-Line comment in C. \t\t\/* \t\tcode \t\t to be commented \t\t*\/ Variables in C A variable is a name of the memory location. It is used to store data and information. Its value can be changed and it can be reused many times. Variable declaration is a way to represent the memory location through symbol so that it can be easily identified. The example of declaring the variable is given below: \t int a; \t float b; \tchar c; \t int x=10; \tchar y=\\\"A\\\" Here, a, b, c, x and y are variables. Rules for defining variables \u2022\t A variable can have alphabets, digits and underscore. \u2022\t A variable name can start with the alphabet and underscore only. It can't start with a digit. \u2022\t No whitespace is allowed within the variable name. \u2022\t A variable name must not be any reserved word or keyword, e.g. int, float, etc. Header Files A header file is a file with extension .h which contains C function declarations and macro definitions which are shared between several source files. There are two types of header files: one is the programmer writes itself and another comes with your compiler. You can use a header file with the C preprocessing directive #include. The following are the common header files that come with C compilers. Header Files Description Header Files Description #include<stdio.h> Standard input-output header #include<assert.h> Assertion header #include<string.h> String header #include<locale.h> Localization header #include<conio.h> Console input-output header #include<signal.h> Signal header #include<ctype.h> Character type header #include<setjmp.h> Jump header #include<stdlib.h> Standard library header #include<stdarg.h> Argument header #include<math.h> Math header #include<errno.h> Error handling header #include<time.h> Time header #include<graphics.h> Graphics function 308 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Escape Sequence An escape sequence is a sequence of characters followed by back slash \\\\ used for formatting the output and are not displayed while printing text onto the screen, each having its own specific function. Some of the escape sequences are: Escape Sequence Description \\\\n To shift the cursor control to the new line. \\\\t We use it to shift the cursor to a couple of spaces to the right in the same line. \\\\r We use it to position the cursor to the beginning of the current line. \\\\\\\\ We use it to display the backslash character. \\\\\u2019 We use it to display the single-quotation mark. \\\\\u201d We use it to display the double-quotation mark. \\\\0 We use it to represent the termination of the string. \\\\? We use it to display the question mark. (?) \\\\b Backspace C Operators An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. The C language is rich in operators and provides the following types of operators: i) Arithmetic Operators\t\t ii) Relational Operators\t\t iii) Logical Operators iv) Assignment Operators\t\t v) Bitwise Operators \t\t vi) Miscellaneous Operators i) Arithmetic Operators: An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division, etc. on numerical values (constants and variables). The following table shows all the arithmetic operators supported by the C language. Assume variable A holds 10 and variable B holds 20, then: Operator Description Example + Adds two operands. A + B = 30 \u2212 Subtracts second operand from the first. A \u2212 B = -10 * Multiplies both operands. A * B = 200 \/ Divides numerator by de-numerator. B\/A=2 % Modulus and return remainder of an integer division. B%A=0 ++ Increment operator increases the integer value by one. A++ = 11 -- Decrement operator decreases the integer value by one. A-- = 9 Approved by Curriculum Development Center (CDC) 309","Basic of C Programming ii) Relational Operators: A relational operator checks the relationship between two operands. If the relation is true, it returns vlaue1; if the relation is false, it returns value 0. Relational operators are used in decision making and loops. The following table shows all the relational operators supported by C. Assume variable A holds 10 and variable B holds 20 then: Operator Description Example == Checks the values of two operands are equal or not. If yes, then (A == B) is not true the condition becomes true. != Checks the values of two operands are equal or not. If the values (A != B) is true are not equal, then the condition becomes true. > Checks the value of left operand is greater than the value of the (A > B) is not true right operand. If yes, then the condition becomes true. < Checks the value of left operand is less than the value of the right (A < B) is true operand. If yes, then the condition becomes true. >= Checks the value of left operand is greater than or equal to the (A >= B) is not true value of the right operand. If yes, then the condition becomes true. <= Checks the value of left operand is less than or equal to the value (A <= B) is true of the right operand. If yes, then the condition becomes true. -- Decrement operator decreases the integer value by one. A-- = 9 iii) Logical Operators: These operators are used to combine two or more expressions. An expression containing logical operator returns either 1 or 0 depending upon whether expression results true or false. Logical operators are commonly used in decision making to combine relational expressions in C programming. The following table shows all the logical operators supported by C language. Assume variable A holds 1 and variable B holds 0, then: Operator Description Example && Called logical AND operator. If both the operands are non-zero, (A && B) is false then the condition becomes true. || Called logical OR operator. If any of the two operands is non- (A || B) is true zero, then the condition becomes true. Called logical NOT operator. It is used to reverse the logical ! state of its operand. If a condition is true, then Logical NOT !(A && B) is true operator will make it false. iv) Assignment Operators: An assignment operator is used for assigning a value to a variable. The most common assignment operator is =. Some of the assignment 310 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 operators formed by sign = are: Operator Description Example = Simple assignment operator. Assigns values C = A + B will assign the value of from right side operands to the left side operand. A + B to C Add and assignment operator. It adds the right += operand to the left operand and assigns the C += A is equivalent to C = C + A result to the left operand. Subtract and assignment operator. It subtracts -= the right operand from the left operand and C -= A is equivalent to C = C - A assigns the result to the left operand. Multiply and assignment operator. It multiplies *= the right operand with the left operand and C *= A is equivalent to C = C * A assigns the result to the left operand. Divide and assignment operator. It divides the \/= left operand with the right operand and assigns C \/= A is equivalent to C = C \/ A the result to the left operand. Modulus and assignment operator. It takes %= modulus using two operands and assigns the C %= A is equivalent to C = C % A result to the left operand. v) Miscellaneous Operators: Besides the operators discussed above, there are a few other important operators including size of and ? : supported by the C Language. Operator Description Example sizeof() Returns the size of a variable. sizeof(a), where a is integer, will return 4. & Returns the address of a variable. &a; returns the actual address of the variable. * Pointer to a variable. *a; it points address of variable. ? : Conditional expression. If condition is true ? then value X : otherwise value Y , Comma operators are used to link int a, c = 5, d; related expressions together. ; The semicolon tells that the current int a, b, c; statement has been terminated. The Bitwise Operators will be studied in the higher classes. C Expressions An expression is a formula in which operands are linked to each other by the use Approved by Curriculum Development Center (CDC) 311","Basic of C Programming of operators to compute a value. An operand can be a constant, variable or an array element or expression. a-b; In the above expression, minus character (-) is an operator and a and b are the two operands. There are four types of expressions that exist in C: i) Arithmetic expressions : Arithmetic operators are used in arithmetic expression. x-y; 10+20; ii) Relational expressions: Relational operators are used in the relational expression. a<b; 20>10 iii) Logical expressions: Logical operators are used in the logical expression. ( x > 4 ) && ( x < 6 ) iv) Conditional expressions: conditional operator is used in the conditional expression. status = (age>22) ? 'M': 'U'; BASIC PROGRAMMING STEPS IN C Phase 1: \t Creating a Program : Write the program on the basis of problem using the editor. It is known as the source code, after writing the program save the source code with the extension .C. It is an editable file. Phase 2 : \tPre-processing\/ Compiling: In this step, we give the compiling command. If any error exists, we can correct them and recompile. The error free source code will be changed into object code and create a .OBJ extension file. Phase 3: \t Linking: In this phase, it collects all the user defined function, built in functions and functional header files and create .EXE extension file. Once .EXE is created, it is not edited. Phase 4: \t Loading : In this phase, the executable file will be loaded in the computer memory, RAM, and start to execute the program with the help of the CPU. In this stage you can test your program. Phase 5: Execution : This is the final stage, by clicking on .EXE file, you can run your program. RULES FOR WRITING C PROGRAM \u2022\tAt the top of the program, include the header file with preprocessor directive #. \u2022\tC is a case sensitive language, so all the C instructions must be written in lower case letter. \u2022\tAll the C statements must end with a semicolon. \u2022\tThe C program starts to execute from main () program. So, at least one function must be there. 312 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 \u2022\tC is a structured programming language, so a set of statements must be written in between the curly brackets. COMMON STRUCTURE OF C PROGRAM \u2022\t Write a program to ask two numbers and find their sum. #include<stdio.h> #include<conio.h> Preprocessor directives section. Header files are declared here int sum(); Global int a,b; Declaration section. User defined functions void main() and global variables are declared here. { Main int s; Function is declared. This is the clrscr(); entry point of the program printf(\\\"Enter first number:\\\"); scanf(\\\"%d\\\",&a); printf(\\\"Entr second number:\\\"); scanf(\\\"%d\\\", &b); s=sum(); User defined function calling printf(\\\"Sum=%d\\\",s); getch(); } int sum() User defined { function int z=a+b; \u2022\tUser defined function, calling function and global return z; declaration section may not present in every } program. COMMON I\/O FUNCTION IN C The functions which are used to perform the input or output operation are called Input\/output functions. I\/O functions are the parts of standard header files, so we must include the header files. We study some of the common I\/O functions here: scanf() Function Function\t: \tIt is a formatted input function which is used to input data stored in \\\"stdio.h\\\" header file. Syntax\t :\t scanf(\\\"format specifier\\\", argument list......) \u2022\targument list is known as the variable list like v1, v2.... which receives data. Example\t:\t scanf(\\\"%d\\\",&a); \u2022\t%d is a format specifier for int data type. \u2022\t&a : & is an address operator and a is a variable. ; is a termination of instruction. Approved by Curriculum Development Center (CDC) 313","Basic of C Programming printf() Function Function\t: \tIt is a formatted output function which is used to print the information on the screen. It is a part of \\\"stdio.h\\\" header file. Syntax\t :\t printf(\\\"format string\\\", argument list......) \u2022\tformat string is included escape sequence, string constant or format identifier. \u2022\targument list is known as the variable list like v1, v2.... Example\t:\t printf(\\\"\\\\n Sum=%d\\\",s); \u2022\t\\\\n is escape sequence, it prints the information from next line of current position. \u2022\t%d is a format specifier for int data type. \u2022\tS is a variable. \u2022\t; is a termination of instruction. getch() Function Function\t: \tIt is an input function which is used to ask a character from the keyboard. It is a part of \\\"conio.h\\\" header file. Basically, it is placed in the end of main program to wait the execution. If it is not used, execution goes to the source code editor screen. Syntax\t :\t getch(); Example\t:\t getch(); clrscr() Function Function\t: \tIt is an output function which is used to clear the screen. It is a part of \\\"conio.h\\\" header file. It works as like a CLS command of QBASIC. Syntax\t :\t clrscr(); Example\t:\t clrscr(); Sample Programs \u2022\t Write a program to ask two numbers and find their sum, product and difference. #include<stdio.h> #include<conio.h> void main() { int a,b,s,p,d; clrscr(); printf(\\\"Enter first number:\\\"); scanf(\\\"%d\\\",&a); printf(\\\"Enter second number:\\\"); scanf(\\\"%d\\\", &b); s=a+b; 314 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 p=a*b; d=a-b; printf(\\\"\\\\n sum=%d\\\",s); printf(\\\"\\\\n difference=%d\\\",d); printf(\\\"\\\\n product=%d\\\",p); getch(); } \u2022\t Write a program to ask principal amount, time and interest rate. The program should find out simple interest and total amount. #include<stdio.h> #include<conio.h> void main() { float p, t, r,si; clrscr(); printf (\\\"Enter principal amount:\\\"); scanf(\\\"%f\\\",&p); printf(\\\"Enter time:\\\"); scanf(\\\"%f\\\", &t); printf(\\\"Enter Rate:\\\"); scanf(\\\"%f\\\",&r); si=(p*t*r)\/100; printf(\\\"Simple interest=%f\\\",si); getch(); } Skill TEST-1 1. \t Write a program to ask quantity and rate per unit of pen and find out total amount. 2. \t Write a program to ask 5 subject marks and find out total marks. 3.\t Write a program to ask quantity and rate per unit of pen, copy and pencil; and, find out total amount. 4.\t Write a program to enter the sides of the triangle and find out the area of the triangle. Area of the triangle = s*(s-a)*(s-b)*(s-c). Where s=(a+b+c)\/2. 5. \t The length and breadth of a rectangle should be input through the keyboard. Write a program to calculate the area and perimeter of the rectangle. AR=L*B, PR=2*(A+B) 6. \t Write a program to find the area of a square. A=L^2. Approved by Curriculum Development Center (CDC) 315","Basic of C Programming \u2022\t Write a program to ask your name and print. #include<stdio.h> \u2022\tThis program allows us to input first name only because #include<conio.h> %s specifier does not allow to read string with a white void main() blank space. { char n[10]; \u2022\tAddress operator is not required with charter type of clrscr(); data because memory address is allocated during the printf(\\\"Enter your name:\\\"); declaration of variable. scanf(\\\"%s\\\",n); printf(\\\"%s\\\",n); getch(); } #include<stdio.h> #include<conio.h> void main() { \u2022\tThis program allows us to input your name in sentence char n[20]; case because \\\"%[^\\\\n]\\\" this specifier allows to read a clrscr(); string until a new line character is entered. printf(\\\"Enter your name:\\\"); scanf(\\\"%[^\\\\n]\\\",n); printf(\\\"%s\\\",n); getch(); } SKILL TEST-2 1. \t Write a program to ask your name, name of subjects and obtained marks in the first terminal examination. The program should display your name, subject's name and obtained marks along with the total. 2. \t Write a program to ask 5 students name, gender and age then display the output. 3. Write a program to ask name of item, quantity and rate. The program should calculate the total amount and display output. DECISION MAKING Sometimes, there may come situations in real life when we need to make some decisions and based on these decisions, we decide what we should do next. Similar situations arise in programming also where we need to make some decisions and based on these decisions we will execute the next block of code. 316 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 C supports strong decision making logic. Here we study simple and common techniques of decision making with if..else statement. if statement in C Function : \tif statement is the simplest decision making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is true then a block of statement is executed otherwise not. Syntax\t:\t if(condition) \u2022\tIf the expression returns true, then the \t\t { statement-inside will be executed, otherwise statement-inside is skipped and only the \t\t statement inside; statement-outside is executed. \t\t } \t\t statement outside; Example \t: \t#include <stdio.h> \t\t#include<conio.h>\t\t \t void main( ) \t\t{ \t\t\tint x, y; \t \tx = 15; \t\t\ty = 13; \t\t\t if (x > y ) \t\t\t{ \t printf(\\\"Greater number %d\\\\n\\\",x); \t\t\t} \t\t\t getch(); \t\t} SKILL TEST-3 1. \tWrite a program to ask marks obtained in computer science and check the marks, if marks is above 50, display message, you are passed ........... congratulation. 2. \t Write a program to ask age of a person and test, if age is above 18, give him congratulation mes- sage being eligible to vote in the national election and get citizenship. 3.\t Write a program to ask the age and check if age is below 10, display message 'You are a child.' if - else statement in C Function : if statement alone tells us that if a condition is true, it will execute a block of statements and if the condition is false it won\u2019t. But what if we want to do something else if the condition is false. Here comes the C else statement. We can use the else statement with if statement to execute a block of code when the condition is false. Approved by Curriculum Development Center (CDC) 317","Basic of C Programming Syntax\t:\t if(expression) \u2022\tIf the expression is true, the statement-block1 \t\t { is executed, otherwise statement-block1 is skipped and statement-block2 is executed. \t\t statement block1; \t\t }\t \t\t else \t\t { \t\t statement block2; \t\t } Example\t: #include <stdio.h> \t#include<conio.h>\t \t void main( ) \t{ \t\t int x=15, y=18; \t\t if (x > y ) \t\t { \t\tprintf(\\\"Greater number=%d\\\\n\\\",x); \t\t } \t\t else \t\t { \t\t\tprintf(\\\"Greater number=%d\\\\n\\\",y\\\"); \t\t } \t\tgetch(); \t} SKILL TEST-4 1. \t Write a program to ask your computer marks and find out whether you are eligible or not to study computer. If computer marks is above 80, you are eligible otherwise you are not eligible. 2. \t Write a program to ask any two numbers and find out smaller number. 3.\t Write a program to ask marks in maths and computer, then find out whether you can study computer or not. If any one subject marks is above 80, you can study otherwise you can not study. Nested if - else statement Function : \tA nested if in C is an if statement that is the target of another if statement. Nested if statement means an if statement inside another if statement. Syntax\t:\t if( expression ) \u2022\tIf expression is false, then statement-block3 will be \t\t{ executed, otherwise the execution continues and enters in the first if to perform the check for the next if \t\t if( expression1 ) block, where if expression 1 is true the statement-block1 \t\t { is executed otherwise statement-block2 is executed. \t\t statement block1; \t\t } 318 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 \t\t else \t\t { \t\t statement block2; \t\t } \t} \t\telse \t\t { \t\t statement block3; \t\t } Example: #include <stdio.h> #include<conio.h> void main( ) { \t int a, b, c; \t printf(\\\"Enter 3 numbers...\\\"); \t scanf(\\\"%d%d%d\\\",&a, &b, &c); \t if(a > b) \t{ \t \t if(a > c) \t\t\t\t\t{ \t\t } printf(\\\"Value of a is the greatest %d\\\",a); \t\t else \t\t { \t\t\t\t\t} \t} printf(\\\"Value of c is the greatest %d\\\",c); \telse \t{\t \t\t if(b > c) \t\t\t\t\t{ printf(\\\"Value of \t\t } b is the greatest %d\\\",b); \t\t else \t\t { \t\t\t\t\t} \t} printf(\\\"Value of c is the greatest %d\\\",c); \tgetch(); \t } SKILL TEST-5 1. \t Write a program to ask three numbers and find out smallest number. 2. \t Write a program to ask three numbers and print the middle number. 3. \t Write a program to ask value for gender [1 to 3] and find out gender. 1 is male, 2 is female and 3 is third gender. Approved by Curriculum Development Center (CDC) 319","Basic of C Programming if-else-if ladder Function : \tIts function is to take decision among multiple options. In this technique, If statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the else-if ladder is bypassed. If none of the conditions are true, then the final else statement will be executed. Syntax\t:\tif(expression1) \t\t{ \t\t statement block1; \t\t} \t\t else if(expression2) \t\t{ \t\t statement block2; \t\t} \t\t else if(expression3 ) \t\t{ \t\t statement block3; \t\t} \t\telse \t\t default statement; \t\t Example\t: #include <stdio.h> #include<conio.h> void main( ) { int a; printf(\\\"Enter a number...\\\"); scanf(\\\"%d\\\", &a); if(a%5 == 0 && a%8 == 0) { printf(\\\"Divisible by both 5 and 8\\\"); } else if(a%8 == 0) { printf(\\\"Divisible by 8\\\"); } else if(a%5 == 0) { printf(\\\"Divisible by 5\\\"); } 320 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 else { printf(\\\"Divisible by none\\\"); } \tgetch(); } SKILL TEST-6 1. \t Write a program to enter a day of the week in number [1 to 7] and display a message, if input is 1, then 'SUNDAY', if input is 2, then 'MONDAY' respectively. 2. \t Write a program to ask 5 subject marks and find out total and percentage marks and find out your grade on the basis of following conditions. Percentage\t\t Grade >=90\t\t A+ >=80\t\t A >60\t\t\tB+ >=50\t\t B >=40\t\t C+ >=30\t\t C <30\t\t\tGrade less Use float data types for all the number data. Logic Gate! 1. In if statement, a single statement can be included without enclosing it within curly braces { ... } int a = 5; if(a > 4) printf(\\\"success\\\"); No curly braces are required in the above case, but if we have more than one statement inside if condition, then we must enclose them inside curly braces. 2. == must be used for comparison in the expression of if condition, if you use = the expression will always return true, because it performs assignment not comparison. 3. Other than 0(zero), all other values are considered as true. if(27) printf(\\\"hello\\\"); \u2022\t In above example, 'hello' will be printed. Approved by Curriculum Development Center (CDC) 321","Basic of C Programming LOOPS IN C Loops in programming come into use when we need to repeatedly execute a block of statements. Loops are used to execute a set of statements repeatedly as long as specified condition is satisfied. Consider the following diagram, how Loop works. \u2022\tAs per the given diagram, if the Test Condition is true, then the loop is executed, and if it is false then the execution breaks out of the loop. Once the Loop Body is successfully executed, the execution again starts from the Loop entry and again checks for the Test Condi- tion, and this keeps on repeating. \u2022\tThe sequence of statements to be executed is kept inside the curly braces { } known as the Loop Body. After every execution of the loop body, the condition is verified, and if it is found true the loop body is executed again. When the Test Condition returns false, the Loop Body is not executed, and execution breaks out of the loop. C supports the following Looping Statements: i) while loop ii) for loop\t iii) do while loop While Loop statement Function\t: 'While loop' is an entry control loop. It is completed in 3 steps. \u2022\tVariable initialization.(e.g int x = 0;) \u2022\tCondition(e.g while(x <= 10)) \u2022\tVariable increment or decrement ( x++ or x-- or x = x + 2 ) Syntax \t : variable initialization; False \t while(condition) \t{ \t\t Statements; \t\t Variable increment or decrement; \t} Example\t: Program to print first 10 natural numbers. True \t #include<stdio.h> \t#include<conio.h> \t void main( ) \t{ \t int x=1; \t while(x <= 10) \t{ \tprintf(\\\"%d\\\\t\\\", x); \tx++; \t} \tgetch(); \t} 322 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Test Your Skill-7 1. \t Write a program to ask your name and print 10 times. 2. \t Write a program to print first 10 natural numbers in reverse form. 3. \t Write program to find the sum of 10 natural numbers. 4. \t Write a program to display multiples of 2 up to 10th terms. for Loop statement Function\t:\tThis loop executes a set of statements repeatedly as long as specified condition is satisfied. We can say, it is an open ended loop. It is controlled by the certain variable. Syntax \t : \tfor(initialization; condition; increment\/decrement) \t\t{ \t\t statement-block; \t\t} \u2022\tIn the for loop, we must have exactly two semicolons, one is after initialization and second is after the condition. The for loop is executed as follows: Step-1\t:\tEvaluates the initialization code. Step-2\t:\tChecks the condition expression. Step-3\t:\tIf it is true, it executes the for-loop \t \t\tbody. Step-4\t:\tEvaluates the increment\/decrement \t \t\t condition and again follows from \t \t\tstep2. Step-5\t:\tWhen the condition becomes false, it \t \t\t exits the loop. Example\t:\tProgram to print first 10 natural numbers. \t #include<stdio.h> \t #include<conio.h> \t void main( ) \t{ \t int x; \t for(x = 1; x <= 10; x++) \t{ \tprintf(\\\"%d\\\\t\\\", x); \t} \tgetch(); \t} Approved by Curriculum Development Center (CDC) 323","Basic of C Programming Test Your Skill-8 1. \t Write a program to print the string \\\"SAGARMATHA\\\" 10 times. 2. \t Write a program to display odd numbers from 1 to 100 horizontally. 3. \t Write a program to find the sum of even numbers from 1 to 10. 4. \t Write a program to ask a number and display multiples up to 10th term. do ..... while loop Function\t: In some of the situations, it is necessary to execute the body of the loop before testing the condition. Such situations can be handled with the help of do-while loop. do statement starts the body of the loop first and at the end, the condition is checked using while statement. It means that the body of the loop will be executed at least once, even though the starting condition inside while is initialized to be false. Syntax \t : \tdo \t\t{ \t\t statement block\t\t \t\t} \t\twhile(condition) Example\t: \tProgram to print first 10 multiples of 5. \t #include<stdio.h> \t #include<conio.h> \t void main() \t{ \t\t int a, i; \t\t a = 5; \t\t i = 1; \t do \t{ printf(\\\"%d\\\\t\\\", a*i); i++; \t} \t while(i <= 10); \t\tgetch(); \t} Test Your Skill-9 b. 1 1 2 3 5 8 13 21.......... up to 10th term. d. 1 4 9 16............. up to 10th term. 1. \t Write programs to display the following: f. 11111 1111 111 11 1 a. \t 5 55 555 5555 55555\t\t\t c. \t 50 45 40 ................5\t\t\t e.\t 20 10 0 -10..............up to 10th term\t\t 324 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Points to Know \u2022\t C is a structured procedural programming language. It was initially developed by Dennis Ritchie in the year 1972. \u2022\t The structured program consists of well structured and separated modules. \u2022\t These elements are the valid character set, identifiers, keywords, basic data types and their representation, constants and variables. \u2022\t Keywords are reserved words which are reserved by the compiler. \u2022\t The data type is the determination of the type and size of data associated with variables. \u2022\t Data modifiers are the elements which change the meaning of the basic data type to fit the various situations. \u2022\t C identifiers represent the name in the C program. For example, variables, functions, arrays, etc. \u2022\t TOKEN is the smallest unit in a 'C' program. It is each and every word and punctuation that comes across in your C program. \u2022\t A constant is a value that can't be changed in the program code. \u2022\t Literals are the constant values assigned to the constant variables. \u2022\t Void is an empty data type that has no value. \u2022\t The Format Specifiers are the elements that tell the compiler what type of data are stored in a variable during taking input using the scanf() function and printing using printf() function. \u2022\t A variable is a name of the memory location. It is used to store data. \u2022\t A header file is a file with extension .h which contains C function declarations and macro definitions which are shared between several source files. \u2022\t An escape sequence is a sequence of characters followed by back slash \\\\ used for formatting. \u2022\t An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. \u2022\t An expression is a formula in which operands are linked to each other by the use of operators to compute a value. Terms to Know Programming\t : \tActivities of writing computer programs Execution flow\t : \tAct or process of executing Condition\t : \tA logical clause or phrase that a conditional statement uses Keywords\t:\t A significant word, or a word used to find information Operators\t:\t A character or characters that determine the action that is to be performed Loop\t:\t A programming structure that repeats a sequence of instructions as long as a specific condition is satisfied Statement block\t :\t A sequence with more statements enclosed in braces Approved by Curriculum Development Center (CDC) 325","Basic of C Programming Worksheet Objective Questions 1. Fill in the blanks: a. \t C is also called ........................... level language. b. \t C has ................................ keywords. c. \t ................................ is a reserve word. d. \t ............................. represents the name in the C program. e.\t ................................ is the smallest unit in C. f.\t A ........................... is a value that can't be changed in the program code. g.\t ................................ is an empty data type. h.\t Format specifiers are used in C for ..................... and .................... purpose. i.\t A ....................... is a name of the memory location. j.\t Header file has the extension ................. k.\t Preprocessors directive begins with the character ......................... l.\t Escape sequence is followed by ................... character. m.\t ........................... operators are used in decision making. 2. Write 'T' for true and 'F' for false statements: a. \tUNIX operating system was developed in C programming language. b. \tC is a non structured language. c.\t C language uses the compiler to compile the program. d.\t Structured program uses the single entry or exit point. e. \tC creates both function and sub procedures. f.\t C supports the object oriented programming technique. g.\t Keywords are not allowed to be used as Identifiers. h.\t Literals are the variables where constant values are stored. i.\t Comment is no executable. 326 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 j.\t .EXE file is an editable file. k. \tmain() function is the entry point of program execution. l.\t At least one function is a must to be in a C program. 3. \tMark for the correct option: a. \t C was developed in the year: i) 1972\t\t\t\t\t\tii) 1872\t\t iii) 1970\t\t\t\t\t\tiv) 1974 b. \t Application of C : \t i) Operating System\t\t\t\t ii) Utility software\t \t iii) DBMS\t\t\t\t\tiv) All of these c. \t Basic elements of C language: \ti) Character set\t\t\t\t\t ii) Data types\t \t iii) Keywords\t\t\t\t\tiv) All of these d. \t Which is not derived type: \ti) Structure\t\t\t\t\tii) Function\t\t iii) Array\t\t\t\t\t\tiv) Char e. \t Which one is the input function? \ti) scanf()\t\t\t\t\t\tii) printf()\t\t iii) clrscr()\t\t\t\t\tiv) main() f. \t Multiline comment is represnted by: ii) \/* .............*\/ \t \t \ti) \/*.....\/*\t\t\t\t\t\t iv) *\/ .............\/* iii) \\\\* ............ *\/\t\t\t\t\t g. \t Single line comment is reported by \ti) \/\t\t\t\t\t\tii) \\\\\\\\ \t\t iii) \/\/\t\t\t\t\t\t\tiv) \/\/ ...... \/\/ h. \t A variable can have: \ti) Alphabets\t\t\t\t\tii) Digits\t\t iii) Underscore\t\t\t\t\tiv) All of these i. \t A variable can start with: \ti) Alphabets\t\t\t\t\tii) Underscore \t iii) Both i) & ii)\t\t\t\t\t iv) Number Approved by Curriculum Development Center (CDC) 327","Basic of C Programming j. \t Which one is the appropriate variable? i) xyz\t\t\t\t\t\tii) int\t\t iii) char\t\t\t\t\t\t iv) float k. \t Mathematical operator : \t i) +\t\t\t\t\t\tii) %\t\t iii) ++\t\t\t\t\t\tiv) All of these l. \t Which operator returns the remainder? \ti) --\t\t\t\t\t\tii) \/\t\t iii) %\t\t\t\t\t\t\tiv) \\\\ m. \t Which operator checks whether the two values are equal or not? \ti) =\t\t\t\t\t\tii) ==\t\t iii)>=\t\t\t\t\t\t\tiv) All n. \t Logical operator: \ti) &&\t\t\t\t\t\t ii) ||\t \t iii) !\t\t\t\t\t\t\tiv) All of these o. \t Valid assignment operator: \ti) =\t\t\t\t\t\tii) ==\t\t iii) %\t\t\t\t\t\t\tiv) =++ p. \t Which one is the logical expression? \ti) a<b\t\t\t\t\t\tii) 10+20\t\t iii) (x>4)&&(x>6)\t\t\t\t\t iv) None of these q. \t Extension of source file: \ti) .EXE\t\t\t\t\t\tii) .C\t\t iii) .obj\t\t\t\t\t\tiv) .jpg r. \t Escape sequence used to return in new line: \ti) \\\\n\t\t\t\t\t\tii) \\\\t\t\t iii) \\\\s\t\t\t\t\t\t\tiv) \\\\c s. \t & sign is a : ii) Address pointer\t \t \ti) Format specifier\t\t\t\t\t iv) Logical operator iii) Escape sequence\t\t\t\t 328 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Objective Questions 4. Match the following: a. \tOutput function Pretest b. conio.h Post test c. \t getch() ! d.\t while loop || e.\t do... while loop && f.\t not operator input() g.\t or operator clrscr() h. AND operator\t printf() Descriptive Questions 1. Write very short answer of the following questions: a.\t What is C language? b. \t What are C tokens? c.\t Write the advantages of C language. d. \t What is format specifier? e.\t What is looping? f.\t Write the basic structure of C program. 2. Write short answer of the following questions: a.\t Why is C language called a structured procedural language? b.\t Why is C language called a middle level language? c.\t What is an identifier? Write the rules for constructing the identifier. d.\t Write the limitations of C language? e.\t Write the features of C language. f. \t What is structured programming? Write the features of structured programming. g.\t Differentiate between while and do while loop. 3. Write the use and syntax of the following statements: a. clrscr() \t\t b. scanf()\t\t c. printf()\t\t d. getch () e. if \t\t\t f. if...else\t\t g. if .. else if \t\t h. for loop i. while\t\t\t j. do ...while Approved by Curriculum Development Center (CDC) 329","Basic of C Programming Output Output Case Study and Application-based Questions Output 1. Study the following programs and write the output: a.#include <stdio.h> \t #include<conio.h> \t void main() \t{ int product, count = 1; while (count <= 10) \t{ product = 2 * count; printf(\\\"2 x %d = %d\\\\n\\\", count, product); count++; \t} \t\t printf(\\\"End of code\\\\n\\\"); \tgetch(); \t} b. #include <stdio.h> \t #include<conio.h> \t void main() \t{ int a = 9, b = 4; int x = a % b; printf(\\\"%d\\\\n\\\", x); \tgetch(); } c.\t#include <stdio.h> \t#include<conio.h> \t void main() \t{ \t int r, c, count; \t for (r = 1, count = 1; r <= 3; r++) \t\t{ for (c = 1; c <= 3; c++, count++) \t\t { printf(\\\"%d \\\", count); \t} 330 Approved by Curriculum Development Center (CDC)","printf(\\\"\\\\n\\\"); Smart Computer Science Book-10 \t} getch(); Output \t} Output d. #include <stdio.h> 331 \t#include<conio.h> \t void main() \t{ int r, c; for (r = 1; r <= 6; r++) \t{ for (c = 1; c <= r; c++) \t\t { printf(\\\"* \\\"); \t} printf(\\\"\\\\n\\\"); \t} \tgetch(); \t} e. #include<stdio.h> \t#include<conio.h> \t void main() \t{ int n, remainder, sum = 0; while(n != 0) { remainder = n % 10; sum += remainder; n = n \/ 10; } printf(\\\"%d\\\", sum); getch(); \t} f.\t#include<stdio.h> \t#include<conio.h> \t int main() \t{ int num=155, r = 0;rem; Approved by Curriculum Development Center (CDC)","Basic of C Programming Output Output while(num != 0) Output { rem = num % 10; r = r * 10 + rem; num = num \/ 10; } printf(\\\"%d\\\", r); \t\tgetch(); \t} g.\t#include<stdio.h> #include<conio.h> void main(); { ch = 'A'; for(int i = 1; i <= 5; i++) { for(int j = 1; j <= i; j++) { printf(\\\" %c\\\", ch); } ch++; printf(\\\"\\\\n\\\"); } getch; } h.\t#include <stdio.h> #include <conio.h> void main() { int a=8, b=6, t, g, while (b != 0) \t{ t = b; b = a % b; a = t; \t} g = a; printf(\\\"%d\\\\n\\\", g); getch(); } 332 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 2. Study the following programs and b. #include <stdio.h> \t#include<conio.h> answer the asked questions: \t void main() \t{ a. #include <stdio.h> \t\t int i, t1 = 0, t2 = 1, nt; #include<conio.h> for (i = 1; i <10; ++i) \t int main(void) \t\t{ \t{ printf(\\\"%d, \\\", t1); \t int count = 1; nt = t1 + t2; \t while (count < 0) t1 = t2; \t\t{ t2 = nt; } printf(\\\"Hello World\\\\n\\\"); \tgetch(); count++; } \t} getch(); } i) \t How many times does loop repeat? i) \t How many times does loop repeat? Ans: ....................................................... Ans: ....................................................... ii) \t Write the output of this program. ii) \t Write the output of this program. Ans: ....................................................... Ans: ....................................................... iii) \tConvert this program into DO .... WHILE c.\t #include <stdio.h> LOOP and write the output. #include<conio.h> Void main() Ans: ........................................................ { ................................................................ int n=5, i; fact = 0; ................................................................ for (i = 1; i <= 5; ++i) ................................................................ { ................................................................ fact *= i; ................................................................ } ................................................................ printf(\\\"%d\\\", fact); ................................................................ \tgetch(); ................................................................ } ................................................................ ................................................................ i) \t How many times does loop repeat? Ans: ....................................................... ii) \t Write the output of this program. Ans: ....................................................... Approved by Curriculum Development Center (CDC) 333","Basic of C Programming iii) \tIf you change fact=1, what will be the else output? { \tprintf(\\\"%d is odd\\\", n); Ans: ....................................................... } d.\t #include<stdio.h> getch(); #include<conio.h> } moid main() { i) \t List out the bugs? int x=2, y=3, z = 1; Ans: ........................................................ int i = 1; ................................................................ \t\t clrscr(); ii)\tRewrite the programs after correcting the while(i <= y) { bugs. z *= x; Ans: ....................................................... i++; ................................................................ } ................................................................ printf(\\\"%d \\\",^ z); ................................................................ getch(); ................................................................ } ................................................................ ................................................................ i) \t How many times does loop repeat? ................................................................ Ans: ....................................................... ................................................................ ii) \t Write the output of this program. ................................................................ Ans: ....................................................... iii) \tWhat is the purpose of this program? Ans: ....................................................... e. #include<stdio.h> ................................................................ #include<conio.h> ................................................................ void main ............................................................... { ................................................................ int n; ............................................................... printf(\\\"Enter a number: \\\"); ................................................................ scanf(\\\"%d\\\", n); ................................................................ if(n % 2 = 0); { printf(\\\"%d is even\\\", n); } 334 Approved by Curriculum Development Center (CDC)","Lab Activities-1 Smart Computer Science Book-10 1.\t Type and test all the programs g\t iven in this chapter:\t i) Example programs\t ii) Test skill programs iii) Programs given in application based questions. 2. \t Ragupati Chaudhary wants to ask age of 100 people of his village and find out the total number of people in the following age group. \t\t Below 10 \t\t 10 to 20 \t\t 21 to 30 \t\t 31 to 40 \t\t above 40 \t Write a program to solve this case of Ragupati Chaudhary. 3. \t Janbi Moktan heard about Armstrong number which is a number equal to the sum of the cubes of its digits. For example 13+53+33= 153. So, 153 is Armstrong number. She wants such programs: \t\ti) To ask a number and find out whether it is Armstrong or not. \t\t ii) To display all the Armstrong numbers from 1 to 500. \t Write programs for Janbi, test and make .exe file. 4. \t Uttim Lal Mandal is a mathematics teacher, he wants some programs to test the followings: \t\ti) To ask a number and find out it is a prime number or not \t\t ii) To ask a number and display in reverse form. \t Write programs for Uttim Lal to solve these cases. 5. \t Jogindar Mahato is a class X student, he has to write some programs to solve the following problems: \t i) To ask a number and find out whether it is same from both sides or not, like 151, 55 are same from both sides. \t ii) To ask two numbers and find out their HCF and LCM. \t How would Jogindar write programs to solve these problems? 6. \t Jitini Rai saw the given patterns in a computer book, she wants programs to display same patterns, but she doesn't have any idea, how would you help her? a. \t1 2 3 4 5 b.\t * * * * * c.\t1 d.\t * e.\t5 \t 1234 \t **** \t 12 \t ** \t 44 \t 123 \t *** \t 123 \t *** \t 333 \t 12 \t ** \t 1234 \t **** \t 4444 \t1 \t* \t 12345 \t * * * * * \t 55555 f. \t 1 2 3 4 5 g.\t1 h.\t5 i.\t1 j. \t 5 4 3 2 1 \t 2345 \t 22 \t 45 \t 21 \t 4321 \t 345 \t 333 \t 345 \t 321 \t 321 \t 45 \t 4445 \t 2345 \t 4321 \t 21 \t5 \t 55555 \t 12345 \t 54321 \t1 Approved by Curriculum Development Center (CDC) 335","Basic of C Programming Lab Activities-2 1. Write programs for the follow\ting problems in C Language. a) \t To ask length & breadth of a room and calculate its area and perimeter. b) \t To ask any two numbers and display the smaller one. c) \t To check whether the supplied number is divisible by 5 or not. d) \t To ask your marks in Computer Science and checks whether you are passed or failed, if the pass mark is above 40, passed otherwise failed. e) \t To display following series: i) \t 5 10 15 \u2026.. 50 ii) \t 1 2 4 8 16 \u2026. up to 10th term iii)\t 1000 729 512......... up to 10th term iii) \t1 2 3 5 8 13 21, \u2026. up to 10th term v)\t 2 8 18 32 ...... up to 10th term vi)\t 999 72 511 \u2026. up to 10th term vii)\t-25 -20 15 -10 0 up to 10th term f) \t To ask any one integer and calculate the sum of its individual digits. g) \t To ask any one integer and display its reverse. h) \t To ask any one integer and checks whether it is a palindrome number or not. The number which can read same from both side, it is called palindrome number. i) \t To ask any one integer and calculates its factorial. j) \t To ask an integer and display its factors. k) \t To check whether the supplied number is prime or composite. l)\t To display square values of first 10 natural number. m)\t To display greatest number out of three input number. n)\t To print greatest number out of 10 input numbers. o)\t To display first 10 natural numbers in reverse form 10 to 1. p)\t To ask a number and display its multiplication table. q)\t To ask three numbers and print middle number. r)\t To ask science and computer science marks and find out whether you can study computer or not. If any one subject marks is above 80, you can study otherwise you can not study. s) \t To ask your gender and find out whether your male, female or third gender. t)\t To display only prime numbers from 1 to 100. u)\t To display multiples up to 10th term from 1 to 10.\t 336 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Project Work Complete the given project works and prepare a project report as per the given guideline below. The report should include the following sections: a) Title page b) Acknowledgement c) Table of content d) Problem statement (issues or requirement of problem) e) Problem analysis f) Flowcharts g) Program Code h) Output (Screen-shots) i) Limitation of the program j) Conclusion Project 1: Develop a menu-based application in QBASIC for the Library Management System with the following features: Sample Main Menu: 1. Display Report 2. Insert new Book title 3. Issue Books 4. Delete records 5. Update Records 6. Exit Enter Your Choice (1\/2\/3\/4\/5\/6): Approved by Curriculum Development Center (CDC) 337","Project Work Project 2: Develop a simple \\\"Stock Management System\\\" in QBASIC with the following features: 1. Sales System 2. Purchase System 3. Add new product title 4. Delete items 4. Display Report 5. Update Records 6. Exit Enter Your Choice (1\/2\/3\/4\/5\/6): Project 3: Develop a simple \\\"Quiz Mania System\\\" in QBASIC with the following features: Sample Menu: 1. \tPlay Quiz 2.\t Display the reports 3. \tAdd more questions 4. \tUpdate a record 5.\t Delete records 6. \tExit Enter Your Choice (1\/2\/3\/4\/5\/6): 338 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Abbreviation TV \t : \t Television ARP \t : \t Address Resolution Protocol USB \t : \t Universal Serial Bus POP \t : \t Post Office Protocol bps \t : \t bits per second PPP \t : \t Point-to-Point Protocol mbps \t : \t megabits per second CDP \t : \t Point-to-Point Protocol STP \t : \t Shielded Twisted Pair VOIP \t : \t Voice over Internet Protocol UTP \t :\t Unshielded Twisted Pair Net BEUI \t : \t NetBIOS Extended User Interface CAT-6 \t : \t Category 6 DHCP\t: \t Dynamic Host Configuration Protocol RJ-45 \t : \t Registered Jack-45 DNS \t : \t Domain Name System BNC \t : \t Bayonet Neil-Concelman DSL \t : \t Digital Subscriber Line ST \t : \t Straight Tip Connector SoNET \t : \t Synchronous optical networking FC \t : \t Ferrule Connector ATM \t : \t Asynchronous Transfer Mode LC \t : \t Lucent Connector ISP \t : \t Internet Service Provider SC \t : \t Subscriber Connector P2P \t : \tPeer-to-Peer RF \t : \t Radio Frequency NTC \t : \t Nepal Telecom GHz \t : \t Gigahertz ADSL \t : \t Asymmetric Digital Subscriber Line IR \t : \t Infrared ISDN \t : \t Integrated Services Digital Network Wi-Fi \t : \t Wireless Fidelity PSTN \t : \t Public Switched Telephone Network FTP\t: \t File Transfer Protocol DTH \t : \t Direct-to-Home MAC \t : \t Media Access Control VoIP \t : \t Voice over Internet Protocol LAN \t : \t Local Area Network Usenet \t : \t User's Network OSI \t : \t Open Systems Interconnection E-mail \t : \t Electronic mail Modem \t : \tModulator-Demodulator E-commerce : \t Electronic commerce IP \t : \t Internet Protocol IRC \t : \t Internet Relay Chat MAN \t : \t Metropolitan Area Network FTP \t : \t File Transfer Protocol WAN \t : \t Wide Area Network URL \t : \t Uniform Resource Locator CPU \t : \t Central Processing Unit www \t : \t World Wide Web ALU \t : \t Arithmetic Logic Unit HTTP \t : \t Hypertext Transfer Protocol NIC \t : \t Network Interface Card HTML\t: \t HyperText Markup Language TCP \t : \t Transmission Control Protocol Telenet \t : \t TELecommunication NETwork IP \t : \t Internet Protocol G2G \t : \t Government to Government SMTP \t : \t Simple Mail Transfer Protocol IP \t : \t Internet Protocol HTTP \t : \t HyperText Transfer Protocol GDP \t : \t Gross Domestic Product Approved by Curriculum Development Center (CDC) 339","Abbreviation PC \t : \t Personal Computer NLP \t : \t Natural Language Processing CCTV \t : \t Closed-Circuit Television\t AWS \t : \t Amazon Web Services UPS \t : \t Uninterruptible Power Supply PaaS \t : \t Platform as a Service DDoS \t : \t Distributed Denial of Service iOS \t : \t iPhone Operating System SQL \t : \t Structured Query Language GPRS \t : \t General Packet Radio Service DoS \t : \t Denial of Service CDMA \t : \t Code-Division Multiple Access B2B \t : \t Business to Business PDA \t : \t Personal Digital assistant B2C \t : \t Business to Consumer VR \t : \t Virtual Reality C2C \t : \t Customer to Customer CSPs \t :\t Cloud Service Provider C2B \t : \t Consumer to Business SaaS \t : \t Software as a Service WAP \t : \t Wireless Application Protocol IaaS \t : \t Infrastructure as a Service IT \t : \t Information Technology MCN \t : \t Mobile Communication Network G2C \t : \t Government to Citizen UMTS \t : \t Universal Mobile Telephone System G2B \t : \t Government to Business LTE \t : \t Long-Term Evolution, G2E \t : \t Government to Employees GPS \t : \t Global Positioning System IoT \t : \t Internet of Things GCE \t : \t Google Computing Engine AIoT \t : \t Artificial Intelligence of Things Bits \t : \t Binary digit AI \t : \t Artificial Intelligence BCD\t: \t Binary Coded Decimal MT-RJ \t : \t Media Termination Recommended Jack IPX\/SPX \t : \t Internetwork Packet Exchange\/Sequenced Packet Exchange. TCP\/IP \t : \t Transmission Control Protocol\/Internet Protocol ARPANET \t : \t Advanced Research Projects Agency Network ICT \t : \t Information Communications Technology HSDPA \t : \t High Speed Downlink Packet Access GSM \t : \t Global System for Mobile Communications ASCII \t : \t American Standard Code For Information Interchange EBCDIC \t : \t Extended Binary-Coded Decimal Interchange Code 340 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Computer Science - Grade 10(SEE) SEE Theory Question Pattern (50 Marks) Time 1 hr. 30 Minutes (6*1=6) Group \\\"A\\\" [10 MArks] (2*1=2) (2*1=2) 1) \tAnswer the following questions in one sentence:\t (9*2=18) a)\t Computer Fundamentals b)\t Computer fundamentals (1*2=2) c) \tDatabase (1*2=2) d) \tDatabase (1*2=2) e) \tQbasic Programming f) \t C programming 2) \tTechnical Terms\t a) \tComputer fundamentals b) \tComputer Fundamentals 3) \tFull forms \t a) \tComputer fundamentals b) \tComputer fundamentals Group \\\"B\\\" [24 Marks] 4) \tAnswer the following questions: \t a) \tComputer Fundamentals b) \tComputer Fundamentals c) \tComputer Fundamentals d) \tComputer Fundamentals e) \tComputer fundamentals f) \t Database g) \tDatabase h) \tDatabase i) \t Database 5)\t QBASIC- finding output\t 6) \tQBASIC- program correction (Debugging) \t 7) \tQBASIC- analytical questions\t Approved by Curriculum Development Center (CDC) 341","SEE Theory Question Pattern (4*1=4) (1*4=4) Group \\\"C\\\" [16 MArks] (1*4=4) 8) Number System (Conversion\/Calculation) \t (1*4=4) 9) \t(a) \tSub and Function procedure in QBASIC \t (b) \tFile handling in QBASIC \t\t\t\t\t\t 10)\tC Programming (IF Statement or Loop statement) \t THE END Marks Distribution for each Unit Full Forms \u2022\t VSAQ-Very short Answer Questions \u2022\t SAQ-Short Answer Questions \u2022\t LAQ-Long Answer Questions Unit Name(Marks) VSAQ SAQ LAQ (1 Marks) (2 Marks) (4 Marks) 1) Computer Fundamental (20 Marks) 6 5 1 2) Database (10 Marks) 2 4 - 3) QBASIC Programming (15 Marks) 1 3 2 4) C Programming (5 Marks) 1 - 1 (50 Marks) 10*1=10 12*2=24 4*4=16 Total 342 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 SEE Theory Model Question agfj6 ? structure? Approved by Curriculum Development Center (CDC) 343","SEE Theory Model Question r. 344 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Approved by Curriculum Development Center (CDC) 345","SEE Theory Model Question 346 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 Approved by Curriculum Development Center (CDC) 347","SEE Theory Model Question F.M. 50 SEE Model Question Computer Science (Optional) Time 1 hr. 30 Minutes\t\t\t\t\t\t Group 'A' (10 Marks) (6*1=6) 1. \t Answer the flowing questions in one sentence: \t\t\t a.\t What is data communication? b. \tWhat is computer virus? c. \t What is database? d. \tWhat is modular programming? e. \tWhy is 'c' language called a structured programming language? f. \t What is form? 2. \t Write the appropriate technical terms: \t\t\t\t (2*1=2) a. \tAn organization that provides services for accessing the Internet. b. \tA destructive computer code or web script designed to create system vulnerabilities 3. \t Write the full forms of : \t\t\t\t\t\t\t (2*1=2) a) \tMAN\t\t\t b) CCTV Group 'B' (24 Marks) 4. \t Answer the following questions:\t\t\t\t\t (9*2=18) a. \tWhat is computer network? Write two advantages of the computer network. b. \tWhat is e-governance? Write the modes of e-governance. c. \t What is contemporary technology? Write the name of common contemporary technology in the field of IT. d. \tWhat is the relational database management system? Write the two features of relational database management system. e. \tWhat is primary key? Write two features of primary key. f. \t What is data sorting? Write two importances of data sorting. g. \tDefine the password policy. Write the characteristics of strong password. h. \tWhat is digital citizen? Write the good qualities of a digital citizen? i. \t What is query? Write the types of query. 348 Approved by Curriculum Development Center (CDC)","Smart Computer Science Book-10 5. \t Write the output of the given program (Show with dry run in table) (2) declare sub xyz() CALL XYZ END SUB XYZ N=5 FOR I = 1 TO 10 STEP 2 PRINT N * I NEXT I END SUB 6. \t Rewrite the given program after correcting the bugs: \t\t (2) REM To reverse the string DECLARE SUB REV$(N$) CLS INPUT \u201cEnter String:::\u201d;S$ CALL REV(N$) END SUB REV(N$) \t FOR K = LEN$(N$) TO 1 STEP -1 \t\t\t PRINT MID$(N$,K,1); \t\tNEXT K END SUB 7. \t Study the following program and answer the given questions: \t (2*1=2) OPEN \u201cDETAIL.DAT\u201d FOR INPUT AS #1 OPEN \u201cTEMP.DAT\u201d FOR OUTPUT AS #2 INPUT \u201cName of the student:\u201d;NM$ FOR I= 1 TO 10 \t INPUT #1, N$,C,A \t IF NM$<> N$ THEN \t\t\t WRITE #2, N$,C,A \t\tEND IF NEXT I CLOSE #1,#2 Approved by Curriculum Development Center (CDC) 349","SEE Theory Model Question KILL \u201cDETAIL.DAT\u201d NAME \u201cTEMP.DAT\u201d AS \u201cDETAIL.DAT\u201d END i) \t What is the objective of the above program? ii) \t If the data file \u201cDETAIL.DAT\u201d contains only 8 records, what will be the error message after running the program? Group 'B' (16 Marks) 8. \t Convert\/calculate as per the indication: \t\t\t\t (4*1=4) i) (2AC)16 = (?)8\t\t\t\t\t ii) (48)10 = (?)2 iii) (1101)2 \u00d7(110)2 - (1010)2\t\t\tiv) (101011)2 \u00f7 (110)2 9. \t a) \t Write a program to ask any two numbers and create a function procedure SUM (A,B) to find the sum of these numbers and create function procedure DIFF(X, Y) to find the difference. \t\t\t\t\t (4) \t b)\t Write a program to add more records as you like in the data file \\\"ITEM DAT\\\" which contains name of item, quantity and rate. \t \t (4) 10. \tWrite a program to ask a number and find out whether it is even or odd. (4) \t\t\t\t\t\tor \t Write a program in 'C' language to display the square value of the first 10 natural numbers. 350 Approved by Curriculum Development Center (CDC)"]


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook