Vidyalankar. F.E. Sem. II Structured Programming Approach Prelim Question Paper Solution

Size: px
Start display at page:

Download "Vidyalankar. F.E. Sem. II Structured Programming Approach Prelim Question Paper Solution"

Transcription

1 1. (a) 1. (b) 1. (c) F.E. Sem. II Structured Programming Approach C provides a variety of stroage class specifiers that can be used to declare explicitly the scope and lifetime of variables. The concepts of scope and lifetime are important only in multifunction and multiple file programs and therefore the storage classes are considered in detail later when functions are discussed. For now, remember that there are four storage class specifiers (auto, register, static, and extern) whose meanings are given in Table. The storage class is another qualifier (like long or unsigned) that can be added to a variable declaration as shon below: auto int count; register char ch; static int x; extern long total; Static and external (extern) variables are automatically initialized to zero, Automatic (auto) variables contain undefined values (known as garbage ) unless they are initialized explicitly. Table : Storage Classes and Their Meaning Storage class Meaning auto Local variable known only to the function in which it is declared. default is auto. static Local variable which exists and retains its value even after the control is transferred to the calling function. Extern Global variable known to all functions in the file. register Local variable which is stored in the register. (i) Y = Garbage Value, z = Garbage value, x = Garbage value (ii) Step1:- start Step2:- print Enter the length of 3 sides of a Triangle Step3:- Input A, B, C Step4:- If A+B>C and B+C>A and A+C>b Then print Triangle can be drawn Else Print Triangle cannot be drawn : Go to 8 Step5:- If A=B and B=C Then Print Equilateral Triangle : Go to 8 36

2 Step6:- If A= B or B=C or C= A then Print Isosceles Triangle : Go to 8 Step7:- Print Scalene triangle Step8:- Stop 2. (a) RECURSION When a called function in turn calls another function a process of chaining occurs. Recursion is a special case of this process, where a function calls itself. A very simple example of recursion is presented below: main( ) printf( This is an example of recursion\n ) main( ); When executed, this program will produce an output something like this : This is an example of recursion This is an example of recursion This is an example of recursion This is an ex Execution is terminated abruptly; otherwise the execution will continue indefinitely. Another useful example of recursion is the evaluation of factorials of a given number, Then factorial of a number n is expressed as a series of repetitive multiplications as shown below: factorial of n = n(n 1)(n 2).1. For example, factorial of 4 = = 24 A function to evaluate factorial of n is as follows: factorial (int n) int fact; if (n= =1) return(1); else fact = n*factorial (n 1); return (fact); Let us see how the recursion works. Assume n = 3. Since the value of n is not 1, the statement fact = n * factorial (n 1); will be executed with n = 3. That is, fact = 3 * factorial (2); will be evaluated. The expression on the right hand side includes a call to factorial with n = 2. This call will return the following value: 2 * factorial(1) 37

3 : F.E. SPA 2. (b) Once again, factorial is called with n = 1. This time, the function returns 1. The sequence of operations can be summarized as follows: fact = 3 * factorial(2) = 3 * 2 * factorial(1) = 3 * 2 * 1 = 6 Recursive functions can be effectively used to solve problem where solution is expressed in terms of successively applying the same solution to subsets of the problem. When we write recursive functions, we must have an if statement somewhere to force the funcion to return withut the recursive call being executed. Otherwise, the function will never return. Typecasting is a way to convert a variable from one data type to another data type. For example if you want to store a long value into a simple integer then you can type cast long to int. You can convert values from one type to another explicitly using the cast operator as follows: (type_name) expression Consider the following example where the cast operator causes the division of one integer variable by another to be performed as a floating-point operation: #include <stdio.h> main() int sum = 17, count = 5; double mean; mean = (double) sum / count; printf("value of mean : %f\n", mean ); When the above code is compiled and executed, it produces the following result: Value of mean : It should be noted here that the cast operator has precedence over division, so the value of sum is first converted to type double and finally it gets divided by count yielding a double value. Type conversions can be implicit which is performed by the compiler automatically, or it can be specified explicitly through the use of the cast operator. It is considered good programming practice to use the cast operator whenever type conversions are necessary. Integer Promotion Integer promotion is the process by which values of integer type "smaller" than int or unsigned int are converted either to int or unsigned int. Consider an example of adding a character in an int: #include <stdio.h> main() 38

4 int i = 17; char c = 'c'; /* ascii value is 99 */ int sum; sum = i + c; printf("value of sum : %d\n", sum ); When the above code is compiled and executed, it produces the following result: Value of sum : 116 Here value of sum is coming as 116 because compiler is doing integer promotion and converting the value of 'c' to ascii before performing actual addition operation. Usual Arithmetic Conversion The usual arithmetic conversions are implicitly performed to cast their values in a common type. Compiler first performs integer promotion, if operands still have different types then they are converted to the type that appears highest in the following hierarchy: The usual arithmetic conversions are not performed for the assignment operators, nor for the logical operators && and. Let us take following example to understand the concept: #include <stdio.h> main() int i = 17; char c = 'c'; /* ascii value is 99 */ float sum; sum = i + c; printf("value of sum : %f\n", sum ); When the above code is compiled and executed, it produces the following result: Value of sum : Here it is simple to understand that first c gets converted to integer but because final value is double, so usual arithmetic conversion applies and compiler convert i and c into float and add them yielding a float result. Generic Bitwise Operations Bitwise operators only work on a limited number of types: int and char. This seems restrictive--and it is restrictive, but it turns out we can gain some flexibility by doing some C "tricks". 3. (a) 39

5 : F.E. SPA It turns out there's more than one kind of int. In particular, there's unsigned int, there's short int, there's long int, and then unsigned versions of those ints. The "C" language does not specify the difference between a short int, an int and a long int, except to state that: sizeof( short int ) <= sizeof( int ) <= sizeof( long ) You will find that these sizes vary from ISA to ISA, and possibly even compiler to compiler. The sizes do not have to be distinct. That means all three sizes could be the same, or two of three could be the same, provided that the above restrictions are held. Bitwise operators fall into two categories: binary bitwise operators and unary bitwise operators. Binary operators take two arguments, while unary operators only take one. We're going to discuss binary operators first, and we'll do in the context of a fake binary operator Thus, we write y to perform on x and y. Bitwise operators, like arithmetic operators, do not change the value of the arguments. Instead, a temporary value is created. This can then be assigned to a variable. For example, when you write x + y, neither x nor y have their value changed. Let's assume that we are doing on two unsigned int variables. Let's assume that unsigned ints use 32 bits of memory. We define two variables X and Y where X = x 31 x 30 x 0 Y = y 31 y 30 y 0 We want to be able to refer to each bit of X and Y, which we do so by writing out the bits by writing the variable name in lowercase and adding the appropriate subscript for the bit number. The subscripts follow the convention we've used so far. The least significant bit has a subscript of 0, and is the rightmost bit. The most significant bit has a subscript of N-1 (for N bits), and is the leftmost bit. In this case N = 32 so the MSb has a subscript of 31. Let's 1 to be operation performed on two individual is performed on all 32 bits simultaneously. Further more, let's call the temporary value created, T. Normally, this temporary value does not have a name. It is generated while the program is running, and used in other computations. Thus, when you write c = a + b, a temporary value is created for the sum a + b, and this temporary value then gets copied into c. Of course, for efficiency, the temporary value might not be generated, and the value written directly to c. For more complex statements, such as c = (a + b) - d, temporary values are often created to store intermediate results. These temporary values are created by the runtime system, and are not given variable names. We define Z = Y as: z i = x 1 y i, for 0 <= i <= N 1 40

6 In words, to compute the i th bit of Z, you should perform the operation on the i th bit of X and i th bit of Y. i) Bitwise AND This makes more sense if we apply this to a specific operator. In C/C++/Java, the & operator is bitwise AND. The following is a chart that defines & 1, defining AND on individual bits. x i y i x i & 1 y i We can do an example of bitwise &. It's easiest to do this on 4 bit numbers, however. Variable b 3 b 2 b 1 b 0 x y z = x & y ii) Bitwise OR The operator is bitwise OR (it's a single vertical bar). The following is a chart that defines 1, defining OR on individual bits. x i y i x i 1 y i We can do an example of bitwise. It's easiest to do this on 4 bit numbers, however. Variable b 3 b 2 b 1 b 0 x y z = x y iii) Bitwise XOR The ^ operator is bitwise XOR. The usual bitwise OR operator is inclusive OR. XOR is true only if exactly one of the two bits is true. The XOR operation is quite interesting, but we defer talking about the interesting things you can do with XOR until the next set of notes. The following is a chart that defines ^1, defining XOR on individual bits. x i y i x i ^1 y i

7 : F.E. SPA 3. (b) We can do an example of bitwise ^. It's easiest to do this on 4 bit numbers, however. Variable b 3 b 2 b 1 b 0 x y z = x ^ y iv) Bitwise NOT There's only one unary bitwise operator, and that's bitwise NOT. Bitwise NOT flips all of the bits. There's not that much to say about it, other than it's not the same operation as unary minus. The following is a chart that defines ~ 1, defining NOT on an individual bit. x i ~ 1 x i We can do an example of bitwise ~. It's easiest to do this on 4 bit numbers (although only 2 bits are necessary to show the concept). Variable b 3 b 2 b 1 b 0 x z = ~x Uses of Bitwise Operations Occasionally, you may want to implement a large number of Boolean variables, without using a lot of space. A 32-bit int can be used to stored 32 Boolean variables. Normally, the minimum size for one Boolean variable is one byte. All types in C must have sizes that are multiples of bytes. However, only one bit is necessary to represent a Boolean value. You can also use bits to represent elements of a (small) set. If a bit is 1, then element i is in the set, otherwise it's not. You can use bitwise AND to implement set intersection, bitwise OR to implement set union. In upcoming notes, you'll learn how to find the value of individual bits of a char or int. Relational Operators We often compare two quantities and depending on their relation, take certain decisions. For example, we may compare the age of two persons, or the price of two items, and so on. These comparisons can be done with the help of relational operators. We have already used the symbol <, meaning less than. An expression such as a < b or 1 < 20 containing a relational operator is termed as a relational expression. The value of a relational expression is either one or zero. It is one if the specified relation is true and zero if the relation is false. For example 10 < 20 is true but 20 < 10 is false 42

8 C supports six relational operators in all. These operators and their meanings are shown in Table 1. Table 1 : Relational Operators. Operator Meaning < is less than <= is less than or equal to > Is greater than >= is greater than or equal to == is equal to!= is not equal to A simple relational expression contains only one relational operator and takes the following form: ae-1 relational operator ae-2 ae-1 and ae-2 are arithmetic expressions, which may be simple constants, variables or combination of them. Given below are some examples of simple relational expressions and their values: 4.5 <= 10 TRUE 4.5 < 10 FALSE 35 >= 0 FALSE 10 < 7+5 TRUE a+b = c+d TRUE only if the sum of values of a and b is equal to the sum of values of c and d. When arithmetic expressions are used on either side of a relational operator, the arithmetic expressions will be evaluated first and then the results compared. That is arithmetic operators have a higher priority over relational operaors. Relational expressions are used in decision statements such as if and while to decide the course of action of a running program. Logical Operators In addtion to the relational operators, C has the following three logical operators. && meaning logical AND meaning logical OR! meaning logical NOT The logical operators && and are used when we want to test more than one condition and make decisions. An example is: a > b && x == 10 Table 2 : Truth Table op 1 op 2 Value of the expression op-1 && op-2 op-1 op-2 Non zero Non zero 1 1 Non zero Non zero

9 : F.E. SPA 4. (a) Call by Value If data is passed by value, the data is copied from the variable used in for example main( ) to a variable used by the function. So if the data passed (that is stored in the function variable) is modified inside the function, the value is only changed in the variable used inside the function. Let s take a look at a call by value example: #include <stdio.h> void call_by_value(int x) printf("inside call_by_value x = %d before adding 10.\n", x); x += 10; printf("inside call_by_value x = %d after adding 10.\n", x); int main( ) int a=10; printf("a = %d before function call_by_value.\n", a); call_by_value(a); printf("a = %d after function call_by_value.\n", a); return 0; The output of this call by value code example will look like this: a = 10 before function call_by_value. Inside call_by_value x = 10 before adding 10. Inside call_by_value x = 20 after adding 10. a = 10 after function call_by_value. In the main( ) we create a integer that has the value of 10. We print some information at every stage, beginning by printing our variable a. Then function call_by_value is called and we input the variable a. This variable (a) is then copied to the function variable x. In the function we add 10 to x (and also call some print statements). Then when the next statement is called in main( ) the value of variable a is printed. We can see that the value of variable a isn t changed by the call of the function call_by_value( ). Call by Reference If data is passed by reference, a pointer to the data is copied instead of the actual variable as is done in a call by value. Because a pointer is copied, if the value at that pointers address is changed in the function, the value is also changed in main( ). Let s take a look at a code example: #include <stdio.h> void call_by_reference(int *y) printf("inside call_by_reference y = %d before adding 10.\n", *y); (*y) += 10; printf("inside call_by_reference y = %d after adding 10.\n", *y); int main( ) int b=10; 44

10 4. (b) printf("b = %d before function call_by_reference.\n", b); call_by_reference(&b); printf("b = %d after function call_by_reference.\n", b); return 0; The output of this call by reference source code example will look like this: b = 10 before function call_by_reference. Inside call_by_reference y = 10 before adding 10. Inside call_by_reference y = 20 after adding 10. b = 20 after function call_by_reference. We start with an integer b that has the value 10. The function call_by_reference( ) is called and the address of the variable b is passed to this function. Inside the function there is some before and after print statement done and there is 10 added to the value at the memory pointed by y. Therefore at the end of the function the value is 20. Then in main( ) we again print the variable b and as you can see the value is changed (as expected) to 20. POINTERS A pointer is a derived data type in C. It is built from one of the fundamental data types available in C. Pointers contain memory addresses as their values. Since these memory addresses are the locations in the computer memory where program instructions and data are stored, pointers can be used to access and manipulate data stored in the memory. Pointers are undoubtedly one of the most distinct and exciting features of C language. It has added power and flexibility to the language. Although they appear little confusing and difficult to understand for a beginner, they are a powerful tool and handy to use once they are mastered. Pointers are used frequently in C, as they offer a number of benefits to the programmers. They include: Pointers are more efficient in handling arrays and data tables. Pointers can be used to return multiple values from a function via function arguments. Pointers permit references to functions and thereby facilitating passing of functions as arguments to other functions. The use of pointer arrays to character strings results in saving of data storage space in memory. Pointers allow C to support dynamic memory management. Pointers provide an efficient tool for manipulating dynamic data structures such as structures, linked lists, queues, stacks and trees. Pointers reduce length and complexity of programs. They increase the execution speed and thus reduce the program execution time. 45

11 : F.E. SPA 5. (a) Example : #include<stdio.h> #include<conio.h> #include<string.h> void swap (int * d1. int * d2) int temp; temp=*d1; *d1=*d2; *d2=temp; void main() int a,b; clrscr(); printf("enter number a:"); scanf("%d", &a); printf("\nenter number b:"); scanf("%d", &b); swap(&a,&b); printf("\na contain %d",a); printf("\nb contain %d",b); getch(); #include<stdio.h> #include<conio.h> #include<string.h> struct cricket char nm[20],team[20]; int avg; ; #define total 20 int main() struct cricket player[total],temp; int i,j; clrscr(); for(i=0;i<total;i++) printf("for player %d\n",i+1); printf("enter the name of player : "); fflush(stdin); gets(player[i].nm); printf("enter the team : "); fflush(stdin); gets(player[i].team); 46

12 printf("enter the batting average : "); fflush(stdin); scanf("%d",&player[i].avg); printf("\nteam Name Average\n"); printf(" \n"); for(i=0;i<total;i++) printf("%-10s %-10s %7d\n",player[i].team,player[i].nm,player[i].avg); getch(); return 0; Output: For player 1 Enter the name of player : Diz Enter the team : India Enter the batting average : 100 For player 2 Enter the name of player : Tiwari Enter the team : Pakistan Enter the batting average : 5 For player 3 Enter the name of player : Tendulkar Enter the team : India Enter the batting average : 45 For player 4 Enter the name of player : Dhoni Enter the team : India Enter the batting average : 48 For player 5 Enter the name of player : Yuvi Enter the team : India Enter the batting average : 39 Team Name Average India Diz 100 Pakistan Tiwari 5 India Tendulkar 45 India Dhoni 48 India Yuvi 39 such 20 records #include<conio.h> #include<ctype.h> 5. (b) int main( ) char str[30]; 47

13 : F.E. SPA 6. (a) int i,c,c1,j,m; c=0; clrscr( ); printf("\n\n\t Pl. enter string > "); gets(str); i=0; while(str[i]!='\0') c++; i++; i = c-1; while(i>=0) if(str[i]== ' ') str[i+1] = toupper(str[i+1]); i--; i=0; str[i] = toupper(str[i]); printf("\n\n\t string > %s", str); getch( ); return 0; Using getchar and gets Functions We have discussed, as to how to read a single character from the terminal, using the function getchar. We can use this function repeatedly to read successive single characters from the input and place them into a character array. Thus, an entire line of text can be read and stored in an array. The reading is terminated when the newline character ( \n ) is entered and the null character is then inserted at the end of the string. The getchar function call takes the form: char ch; ch = getchar( ); Note that the getchar function has no parameters. Every time a character is read, it is assigned to its location in the string line and then tested for newline character. When the newline character is read (signaling the end of line), the reading loop is terminated and the newline character is replaced by the null character to indicate the end of character string. When the loop is exited, the value of the index c is one number higher than the last character position in the string (since it has been incremented after assigning the new character to the string). Therefore the index value c-1 gives the position where the null character is to be stored. 48

14 Another and more convenient method of reading a string of text containing whitespaces is to use library function gets available in the <stdio.h> header file. This is a simple function with one string parameter and called as under: gets (str); str is a string variable declared properly. It reads characters into str from the keyboard until a new line character is encountered and then appends a null character to the string. Unlike scanf, it does not skip whitespaces. For example the code segment char line [80]; gets (line) ; printf ( %s, line); reads a line of text from the keyboard and displays it on the screen. The last two statements may be combined as follows: printf( %s, gets(line)) ; Using Putchar and Puts Functions Like getchar, C supports another character handling function putchar to output the values of character variables. It take the following form: char ch = A ; purchar (ch); The function putchar requires one parameter. This statement is equivalent to: printf( %c, ch); We have used putchar function to write characters to the screen. We can use this function repeatedly to output a string of characters stored in an array using a loop. Example: char name[6] = PARIS for (i=0, i<5; i++) putchar(name[i]; putchar( \n ) ; Another and more convenient way of printing string values is to use the function puts declared in the header file <stdio.h>. This is a one parameter function and invoked as under: puts ( str ); where str is a string variable containing a string value. This prints the value of the string variable str and then moves the cursor to the beginning of the next line on the screen. For example, the program segment char line [80] ; gets (line) ; puts (line) ; reads a line of text from the keyboard and displays it on the screen. Note that the syntax is very simple compared to using the scanf and printf statements. 49

15 : F.E. SPA 6. (b) String Handling Functions Fortunately, the C library supports a large number of string handling functions that can be used to carry out many of the string manipulations discussed so far. Following are the most commonly used string handling functions. Function strcat( ) strcmp( ) strcpy( ) strlen( ) Action concatenates two strings compares two strings copies one string over another finds the length of a string We shall discuss briefly how each of these functions can be used in the processing of strings. (i) strcat(s1, s2) strcat( ) Function The strcat function joins two strings together. It takes the following form: strcat(string1, string2); string1 and string2 are character arrays. When the function strcat executed, string2 is appended to string1. It does so by removing the null character at the end of string1 and placing string2 from there. The string at string2 remains unchanged. For example, consider the following three strings: Part1 = V E R Y \ Part2 = G O O D \ Part3 = B A D \0 Execution of the statement strcat (part1, part2); will result in: Part1 = V E R Y G O O D \ Part2 = G O O D \0 while the statement will result in: Part1 = V E R Y B A D \ Part3 = B A D \0 We must make sure that the size of string1 (to which string2 is appended) is large enough to accommodate the final string. 50

16 strcat function may also append a string constant to a string variable. The following is valid: strcat(part1, GOOD ) ; C permits nesting of strcat functions. For example, the statement strcat (strcat (string1, string2), string3) ; is allowed and concatenates all the three strings together. The resultant string is stored in string1. (ii) strchr(s1, char) Description : The strchr function searches string for the first occurrence of c. The null character terminating string is included in the search. Return Value The strchr function returns a pointer to the first occurrence of character c in string or a null pointer if no matching character is found. Example : #include <stdio.h> int main() char *s; char buf [] = "This is a test"; s = strchr (buf, 't'); if (s!= NULL) printf ("found a 't' at %s\n", s); return 0; It will proiduce following result: found a 't' at test (iii) isalpha(char) int isalpha(int c); Description : The function returns nonzero if c is any of: a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Return Value The function returns nonzero if c is just alpha otherwise this will return zero which will be equivalent to false. Example: #include <stdio.h> int main() if( isalpha( '9' ) ) 51

17 : F.E. SPA printf( "Character 9 is not alpha\n" ); if( isalpha( 'A' ) ) printf( "Character A is alpha\n" ); return 0; It will proiduce following result: Character A is alpha (iv) isdigit(char) The C library function void isdigit(int c) checks if the passed character is a decimal digit character. Decimal digits are(numbers): Declaration Following is the declaration for isdigit() function. int isdigit(int c); Parameters c -- This is the character to be checked. Return Value This function returns nonzero value if c is a digit, else 0 Example : The following example shows the usage of isdigit() function. #include <stdio.h> #include <ctype.h> int main() int var1 = 'h'; int var2 = '2'; if( isdigit(var1) ) printf("var1 = %c is a digit\n", var1 ); else printf("var1 = %c is not a digit\n", var1 ); if( isdigit(var2) ) printf("var2 = %c is a digit\n", var2 ); else 52

18 printf("var2 = %c is not a digit\n", var2 ); return(0); Let us compile and run the above program, this will produce the following result: var1 = h is not a digit var2 = 2 is a digit #include <stdio.h> char *strchr(char *string, int c); (v) strcmp(s1,s2) strcmp( ) Function The strcmp function compares two strings identified by the arguments and has a value 0 if they are equal. If they are not, it has the numeric difference between the first nonmatching characters in the strings. It takes the form: strcmp(string1, string2); string1 and string2 may be string variable or string constants. Examples are: strcmp (name1, name2) ; strcmp (name1, John ) ; strcmp ( Rom, Ram ) ; Our major concern is to determine whether the strings are equal; if not, which is alphabetically above. The value of the mismatch is rarely important. For example, the statement strcmp( their, there ) ; will return a value of 9 which is the numeric difference between ASCII i and ASCII "r". That is, i minus r in ASCII code is 9. If the value is negative, string1 is alphabetically above string2. (vi) strcpy(s1,s2) strcpy( ) Function The strcpy function works almost like a string assignment operator. It takes the form: strcpy(string1, string2); and assigns the contents of string2 to string1. string2 may be a character array variable or a string constant. For example, the statement strcpy(city, DELHI ) ; will assign the string DELHI to the string variable city. Similarly, the statement strcpy(city1, city2) ; will assign the contents of the string variable city2 to the string variable city1. The size of the array city1 should be large enough to receive the contents of city2. 53

19 : F.E. SPA (vii) strlen(s1) strlen( ) Function This function counts and returns the number of characters in a string. It takes the form n = strlen = strlen(string); Where n is an integer variable, which receives the value of the length of the string. The argument may be a string constant. The counting ends at the first null character. (viii)islower(char) int islower(int c); DESCRIPTION The islower() function tests for any character that is a lowercase letter or is one of an implementation-defined set of characters for which none of iscntrl(), isdigit(), ispunct(), or isspace() is true. In the C locale, islower() returns true only for the characters defined as lowercase letters. The behavior of the islower() function is affected by the current locale. To modify the behavior, change the LC_CTYPE category in setlocale(), that is, setlocale(lc_ctype, newlocale). In the C locale or in a locale where character type information is not defined, characters are classified according to the rules of the U.S. ASCII 7-bit coded character set. PARAMETERS Is an integer whose value is representable as an unsigned char, or the value of the macro EOF. RETURN VALUES The islower() function returns non-zero for true and zero for false. If the parameter is not in the domain of the function, the return result is undefined. 54

Chapter 8 Character Arrays and Strings

Chapter 8 Character Arrays and Strings Chapter 8 Character Arrays and Strings INTRODUCTION A string is a sequence of characters that is treated as a single data item. String constant: String constant example. \ String constant example.\ \ includes

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

ONE DIMENSIONAL ARRAYS

ONE DIMENSIONAL ARRAYS LECTURE 14 ONE DIMENSIONAL ARRAYS Array : An array is a fixed sized sequenced collection of related data items of same data type. In its simplest form an array can be used to represent a list of numbers

More information

Chapter 8: Character & String. In this chapter, you ll learn about;

Chapter 8: Character & String. In this chapter, you ll learn about; Chapter 8: Character & String Principles of Programming In this chapter, you ll learn about; Fundamentals of Strings and Characters The difference between an integer digit and a character digit Character

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

Operators and Expressions:

Operators and Expressions: Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

More information

Introduction to string

Introduction to string 1 Introduction to string String is a sequence of characters enclosed in double quotes. Normally, it is used for storing data like name, address, city etc. ASCII code is internally used to represent string

More information

Chapter 8 C Characters and Strings

Chapter 8 C Characters and Strings Chapter 8 C Characters and Strings Objectives of This Chapter To use the functions of the character handling library (). To use the string conversion functions of the general utilities library

More information

Strings and Library Functions

Strings and Library Functions Unit 4 String String is an array of character. Strings and Library Functions A string variable is a variable declared as array of character. The general format of declaring string is: char string_name

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous

More information

Chapter 8 - Characters and Strings

Chapter 8 - Characters and Strings 1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions 8.5 Standard Input/Output Library

More information

C Programming Multiple. Choice

C Programming Multiple. Choice C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980

More information

UNIT 3 OPERATORS. [Marks- 12]

UNIT 3 OPERATORS. [Marks- 12] 1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,

More information

Basics of Programming

Basics of Programming Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

More information

Fundamentals of Programming. Lecture 11: C Characters and Strings

Fundamentals of Programming. Lecture 11: C Characters and Strings 1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

More information

today cs3157-fall2002-sklar-lect05 1

today cs3157-fall2002-sklar-lect05 1 today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical

More information

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6. Iulian Năstac Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Q 1. Attempt any TEN of the following:

Q 1. Attempt any TEN of the following: Subject Code: 17212 Model Answer Page No: 1 / 26 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The

More information

Contents. Preface. Introduction. Introduction to C Programming

Contents. Preface. Introduction. Introduction to C Programming c11fptoc.fm Page vii Saturday, March 23, 2013 4:15 PM Preface xv 1 Introduction 1 1.1 1.2 1.3 1.4 1.5 Introduction The C Programming Language C Standard Library C++ and Other C-Based Languages Typical

More information

Important Questions for Viva CPU

Important Questions for Viva CPU Important Questions for Viva CPU 1. List various components of a computer system. i. Input Unit ii. Output Unit iii. Central processing unit (Control Unit + Arithmetic and Logical Unit) iv. Storage Unit

More information

PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur

PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam-613 403 Thanjavur 01. Define program? 02. What is program development cycle? 03. What is a programming language? 04. Define algorithm? 05. What

More information

UNIT-I Input/ Output functions and other library functions

UNIT-I Input/ Output functions and other library functions Input and Output functions UNIT-I Input/ Output functions and other library functions All the input/output operations are carried out through function calls. There exists several functions that become

More information

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size]; Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data

More information

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered )   FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING ( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character 1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa)

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa) Looping Forward Through the Characters of a C String A lot of C string algorithms require looping forward through all of the characters of the string. We can use a for loop to do that. The first character

More information

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g. 1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object

More information

C: How to Program. Week /May/28

C: How to Program. Week /May/28 C: How to Program Week 14 2007/May/28 1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Data Types. Data Types. Integer Types. Signed Integers

Data Types. Data Types. Integer Types. Signed Integers Data Types Data Types Dr. TGI Fernando 1 2 The fundamental building blocks of any programming language. What is a data type? A data type is a set of values and a set of operations define on these values.

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

About Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

LESSON 4. The DATA TYPE char

LESSON 4. The DATA TYPE char LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated

More information

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23. Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into

More information

Object Oriented Pragramming (22316)

Object Oriented Pragramming (22316) Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data

More information

'C' Programming Language

'C' Programming Language F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax

More information

https://www.eskimo.com/~scs/cclass/notes/sx8.html

https://www.eskimo.com/~scs/cclass/notes/sx8.html 1 de 6 20-10-2015 10:41 Chapter 8: Strings Strings in C are represented by arrays of characters. The end of the string is marked with a special character, the null character, which is simply the character

More information

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical

More information

UNIT- I INTRODUCTION TO PROBLEM SOLVING TECHNIQUES

UNIT- I INTRODUCTION TO PROBLEM SOLVING TECHNIQUES UNIT- I INTRODUCTION TO PROBLEM SOLVING TECHNIQUES Short Answer Type Questions - 2 Marks 1. Define Algorithm. A. Definition: A set of sequential steps usually written in Ordinary Language to solve a given

More information

Chapter 7. Basic Types

Chapter 7. Basic Types Chapter 7 Basic Types Dr. D. J. Jackson Lecture 7-1 Basic Types C s basic (built-in) types: Integer types, including long integers, short integers, and unsigned integers Floating types (float, double,

More information

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo 1. (a)what is an algorithm? Draw a flowchart to print N terms of Fibonacci

More information

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1 (a) List any four relational operators.

More information

Department of Computer Applications

Department of Computer Applications Sheikh Ul Alam Memorial Degree College Mr. Ovass Shafi. (Assistant Professor) C Language An Overview (History of C) C programming languages is the only programming language which falls under the category

More information

Characters and Strings

Characters and Strings Characters and Strings 60-141: Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2013 Instructor: Dr. Asish Mukhopadhyay Character constants A character in single quotes,

More information

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, Strings Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, decimal digits, special characters and escape

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

Programming and Data Structures

Programming and Data Structures Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

More information

Lecture 02 C FUNDAMENTALS

Lecture 02 C FUNDAMENTALS Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

Language Reference Manual simplicity

Language Reference Manual simplicity Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

Programming. Elementary Concepts

Programming. Elementary Concepts Programming Elementary Concepts Summary } C Language Basic Concepts } Comments, Preprocessor, Main } Key Definitions } Datatypes } Variables } Constants } Operators } Conditional expressions } Type conversions

More information

THE FUNDAMENTAL DATA TYPES

THE FUNDAMENTAL DATA TYPES THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

SECTION II: LANGUAGE BASICS

SECTION II: LANGUAGE BASICS Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

More information

Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators. Portability: Printing Numbers Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

More information

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ... Why Pointers Pointers They provide the means by which functions can modify arguments in the calling function. They support dynamic memory allocation. They provide support for dynamic data structures, such

More information

Lecture 3. More About C

Lecture 3. More About C Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

More information

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

More information

C Language Programming

C Language Programming Experiment 2 C Language Programming During the infancy years of microprocessor based systems, programs were developed using assemblers and fused into the EPROMs. There used to be no mechanism to find what

More information

Questions Bank. 14) State any four advantages of using flow-chart

Questions Bank. 14) State any four advantages of using flow-chart Questions Bank Sub:PIC(22228) Course Code:-EJ-2I ----------------------------------------------------------------------------------------------- Chapter:-1 (Overview of C Programming)(10 Marks) 1) State

More information

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition

More information

CS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their

More information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

SWEN-250 Personal SE. Introduction to C

SWEN-250 Personal SE. Introduction to C SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

These are reserved words of the C language. For example int, float, if, else, for, while etc.

These are reserved words of the C language. For example int, float, if, else, for, while etc. Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

More information

Write a C program using arrays and structure

Write a C program using arrays and structure 03 Arrays and Structutes 3.1 Arrays Declaration and initialization of one dimensional, two dimensional and character arrays, accessing array elements. (10M) 3.2 Declaration and initialization of string

More information

M1-R4: Programing and Problem Solving using C (JULY 2018)

M1-R4: Programing and Problem Solving using C (JULY 2018) M1-R4: Programing and Problem Solving using C (JULY 2018) Max Marks: 100 M1-R4-07-18 DURATION: 03 Hrs 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter

More information

System Design and Programming II

System Design and Programming II System Design and Programming II CSCI 194 Section 01 CRN: 10968 Fall 2017 David L. Sylvester, Sr., Assistant Professor Chapter 10 Characters, Strings, and the string Class Character Testing The C++ library

More information

Procedural programming with C

Procedural programming with C Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical

More information

C mini reference. 5 Binary numbers 12

C mini reference. 5 Binary numbers 12 C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Fundamentals of Computer Programming Using C

Fundamentals of Computer Programming Using C CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US01CBCA01 (Fundamentals of Computer Programming Using C) *UNIT 3 (Structured Programming, Library Functions

More information

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C. EECS 2031 Fall October 27, 2014 File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

More information

String Class in C++ When the above code is compiled and executed, it produces result something as follows: cin and strings

String Class in C++ When the above code is compiled and executed, it produces result something as follows: cin and strings String Class in C++ The standard C++ library provides a string class type that supports all the operations mentioned above, additionally much more functionality. We will study this class in C++ Standard

More information

بسم اهلل الرمحن الرحيم

بسم اهلل الرمحن الرحيم بسم اهلل الرمحن الرحيم Fundamentals of Programming C Session # 10 By: Saeed Haratian Fall 2015 Outlines Examples Using the for Statement switch Multiple-Selection Statement do while Repetition Statement

More information

KARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur

KARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur KARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur Bachelor of Engineering First Year Subject Name: Computer Programming Objective: 1. This course is designed to provide a brief study of the C programming

More information

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

ARRAYS(II Unit Part II)

ARRAYS(II Unit Part II) ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful

More information

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities SOLUTION OF CONTINUOUS INTERNAL EVALUATION TEST -1 Date : 27-02 2018 Marks:60 Subject & Code : Programming in C and Data Structures- 17PCD23 Name of faculty : Dr. J Surya Prasad/Mr. Naushad Basha Saudagar

More information

Computer Programming Unit 3

Computer Programming Unit 3 POINTERS INTRODUCTION Pointers are important in c-language. Some tasks are performed more easily with pointers such as dynamic memory allocation, cannot be performed without using pointers. So it s very

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

Computers Programming Course 7. Iulian Năstac

Computers Programming Course 7. Iulian Năstac Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); } C Program Output #include main () { printf ( Hi everyone\n ); Hi everyone #include main () { printf ( Hi everyone\n ); #include and main are Keywords (or Reserved Words) Reserved Words

More information