1. Fill in the blanks: (a) C is a strucutured programming language. (b) C language was originally developed by Dennis Ritchie in 1972. (c)printf() is a output function in C language. (d) PRINT is a output statement in QBASIC. (e) Every C program must start with main() function. (f) AND (&&) operator produces true result if all given condition are true. (g) In C language, remainder is found using % operator. (h) In C language, every line of the program must terminatewith semicolon. (i) printf() function is defined in stdio.h header file. 2. State wehter each of the following statements is True or False. (a) In C program, variables must be declared before they are used. TRUE (b) In QBASIC program, variables must be declared before they are used. FALSE (c) printf() in C is equivalent to INPUT statement in QBASIC. FALSE (d) In C language, void must return a value. FALSE (e) The total number of keywords in C language is 28. FALSE (f) % operator is used to find percentage in C language. FALSE (g) clrscr() function is defined in "stdio.h". FALSE 3. Write the purpose of the following functions/operators in C language. (a) printf() - used to display output on screen. (b) scanf() - used to get input from keyboard. (c) % - used to get remainder (d) && - used for AND operation (e) ||- used for OR operation (f) getch() - Used to halts the output screen to press any single character from keyboard. 4. Answer the following questions. (a) Define C language. Who developed it? Ans: C is a structure programming language that divides a program into many functions , which is developed by Dennis Ritchie at Bell Laboratories in 1972 AD. (b) Write the important features of C language. Ans: - It is powerful and highly portable Language. - It is a structured programming language because the program is divided into a number of functions. - It is a general purpose high level programming language. - It is an internationally standardized programming language. (c) List the basic data types with their memory consumption in C. Ans: char - 1 Byte , int - 2 Bytes float - 4 Bytes, double - 8 Bytes (d) Write the formart specifier of basic data types of C language. Ans: char - %c , int - %d float - %f , double - %lf (e) Define variable. Write down the rules for writing a variable name. Ans: An identifier that is used to represent some specified single data item that is numeric or string type is called variable. Rule for naming variables in C: - The first character of a variable name must be a character. - Both uppercase and lowercase letters are permitted. - Uppercase and lowercase letters are not interchangeable. - Space is not allowed in variable name. (f) Differentiate between local and global variables.
Ans:Global Variable | Local Variable |
1. Variable declared outside a function is called Global variable. | 1. Variable declared inside the procedure is called Local Variable. |
2. It is visible to other functions or modules. | 2. It is not visible to other nodules or functions. |
3. Example:
new()
{
// Local variables declaration
int a=92;
int b;
int c=a+b;
}
Here, a,b, and c are global variable. |
3. Example: int a;
main()
{
a=10;
}
function1()
{
int b;
b=a;
}
Here, variable a is called global variable. |
(g) What is a global variable? Give an example of its declaration. Ans: The variable which is declared outside any function is called global variable. They are visible to other functions or modules. For example: int a; main() { a=10; } function1() { int b; b=a; } Here, variable a is called global variable. (h) What do you understand by decision making statements? List the decision making statements supported by C. Ans: Decision making statements choose among different courses of actions available during a program’s execution. C has two major decision making statements. They are: (1) if statement (2) switch statement (i) What are arithmetic operators? Write them in their hierarchy. Ans: The operators, which are used in mathematical calculations are called arithmetic operators. Hierarchy of operators: 1st : () 2nd : *,/,% 3rd : + , - (j) What is a header file? Give any two examples. Ans: The header files are system files are system files stored with extension ".h" that contain pre-defined functions. To use functions provided by "C language" we need to includes specific header file. Two examples of header files are: (i) stdio.h (ii) math.h (k) What is loop? List the different looping statements used in C language. Ans: A control structure that executes the same program statement or block of program statements repeatedly for a specified number of times or till the given condition is satisfied is called Loop. Different looping statements supported by C language are: 1. for loop 2. while loop 3. do-while loop 5. Evaluate the expressions and find out the final values for the following: (Suppose a=2,b=3,c=4) (a) s = (a+b)/3 ANSWER: S = (2+3) / 3 = 5/3 = 1.666667 (b) s= 40%(a+b+c) ANSWER: S = 40 % (2+3+4) = 40 % 9 = 4 (c) s = a/b*c/b+c*a ANSWER: S = 2/3 * 4/3 + 4 * 2= 0.666667*1.333333+8 = 0.888889 + 8 = 8.888889 (d) s=(a+b)/(a*c) ANSWER: S = (2+3) / (2*4) = 5 / 8 = 0.625000 (e) s=(a+b+c)+(a+b+c)%2 ANSWER: S = (2+3+4)+(2+3+4) % 2 = 9 + 9 %2 = 9 + 1 = 10
6. Write down C programs for the following:for loop | while loop | do-while loop |
---|---|---|
#include<stdio.h>
main()
{
int i,a=100;
for(i=0;i<10;i++)
{
printf("%d\n",a);
a=a-2;
}
} |
#include<stdio.h>
main()
{
int i=0,a=100;
while(i<10)
{
printf("%d\n",a);
a=a-2;
i++;
}
} |
#include<stdio.h>
main()
{
int i=0,a=100;
do
{
printf("%d\n",a);
a=a-2;
i++;
}while(i<10);
} |
for loop | while loop | do-while loop |
---|---|---|
#include<stdio.h>
main()
{
int i;
for(i=1;i<=10;i++)
{
printf("%d\n",i*i);
}
} |
#include<stdio.h>
main()
{
int i=1;
while(i<=10)
{
printf("%d\n",i*i);
i++;
}
} |
#include<stdio.h>
main()
{
int i=1;
do
{
printf("%d\n",i*i);
i++;
}while(i<10);
} |
for loop | while loop | do-while loop |
---|---|---|
#include<stdio.h>
main()
{
int i,a;
for(i=1;i<=10;i++)
{
a=i*i*2;
printf("%d\n",a);
}
} |
#include<stdio.h>
main()
{
int i=1,a;
while(i<=10)
{
a=i*i*2;
printf("%d\n",a);
i++;
}
} |
#include<stdio.h>
main()
{
int i=1,a;
do
{
a=i*i*2;
printf("%d\n",a);
i++;
}while(i<=10);
} |
for loop | while loop | do-while loop |
---|---|---|
#include<stdio.h>
main()
{
int a=2,b=2,c,i;
for(i=0;i<10;i++)
{
printf("%d\n",a);
c=a+b;
a=b;
b=c;
}
} |
#include<stdio.h>
main()
{
int a=2,b=2,c,i=0;
while(i<10)
{
printf("%d\n",a);
c=a+b;
a=b;
b=c;
i++;
}
} |
#include<stdio.h>
main()
{
int a=2,b=2,c,i=0;
do
{
printf("%d\n",a);
c=a+b;
a=b;
b=c;
i++;
}while(i<10);
} |