c language basic
TRANSCRIPT
-
7/29/2019 c Language Basic
1/11
FIRST INTERNALS OF BCA 1st SEM
PROGRAMMING CONCEPTS USING C
SCHEME&SOLUTION
SECTION-A
1. What is a flowchart?
Flowchart is a pictorial representation of the step by step
instructions of an algorithm. (1 mark)
2. What is an algorithm?
An Algorithm is a step by step procedure to solve a given
problem. (1 mark)
3. Why C is called as middle level language?
C is called a middle level language because it combines the
features of high level as well as low level programming. (1
mark)
4. What is the purpose of printf in c?
Print f is a library function in C that simply prints or displays
its arguments at terminal. (1 mark)
5. what does preprocessor and definition section contain?
Pre processor section contains Header files, definition section
contains symbolic constants to be defined. (1 mark)
6. What are identifiers?
Identifiers are the sequence of characters chosen from set of
A-Z, a-z, 0-9 and _ (underscore). (1 mark)
-
7/29/2019 c Language Basic
2/11
7. Define constants?
Any fixed value that does not change during the execution of
the program is known as the constant. (1 mark)
8. What is user defined data type?C supports a feature known as type declaration that follows
users to define an identifier, this is known as user defined data
type. (1 mark)
9. What is a character set?
Character set is a collection of symbols such as alphabets,
digits or special symbols used to represent information. (1
mark)
10. What is a token?
Token is the basic and the smallest unit of a program. (1
mark)
11. What are tri-graph characters?
Some of the characters are not supported by non-English
keywords, those are called tri-graph characters. (1 mark)
12. Give the syntax of Assignment statement?
Variable _ name=constant; is the syntax for assignment
statement. (1 mark)
SECTION-B
1. Write an algorithm to accept temperature in degree
Celsius and convert it in to Fahrenheit?Algorithm: To convert temperature in Celsius to
Fahrenheit.
Step 1: start.
Step 2: read c.
Step 3: calculate Fahrenheit=9/5(c+32).
-
7/29/2019 c Language Basic
3/11
Step 4: print temperature in F=, F.
Step 5: stop. (3 marks)
2. What is structured programming? What are its
advantages.Structured programming is a well designed programming
technique used to read, write, debug and maintain.
Advantages:
1. Clear and easy to understand.
2. Debugging is easy.
3. Easy to update and modify the program without
modifying the structure. (3 marks)
3. Discuss about programming style with an example?
C does not have any restrictions while typing and hence it is
known as free-form language. However one should follow a
particular style while writing programs. Program statements
must be written in lower case, upper case must be used for
symbolic constants. When writing a group of statements within
braces, the opening and closing braces must be aligned.
Statements within braces must be indented. Each specific taskmust be labeled with a comment statement.
Example: p=a + b;
Q=q +12;
It can also be written as p= a + b; q= q + 12;
In the above example for better readability the statement
can be written in separate lines. (3 marks)
4. List out the various C tokens available?
There are six C-tokens available in C:1. Keywords. 2. Identifiers.
3. Constants 4. Strings.
5. Operators. 6. Special symbols.
(3 marks)
-
7/29/2019 c Language Basic
4/11
5. What is a variable? Give an example for it.
Variable is an identifier used to store a single data item.
Example:
Consider the following C program segment:
int x, y, z;char p;
x=1; /*value 1 is assigned for x */
y=2; /*value 2 is assigned for y*/
z=3; /*value 3 is assigned for z*/
p=A /*value 65 is assigned for p*/ (3 marks)
SECTION-C
1. Explain in detail about flowcharts with an example. Also
mention about its advantages and disadvantages?
Flowchart is a pictorial representation of the step by step
instructions of an algorithm.
It is of two types:
1. Program flowchart: represents pictorially the sequence
of instructions for solving a problem.2. System flowcharts: indicates the flow of data in to a data
processing system, through the system and out of
system.
Rules for writing a flowchart
1. Flow charts are drawn from top to bottom or left to right.
2. Flowchart always begins with start symbol and ends with
a stop symbol.
3. Flow lines are used to join the symbols.
4. There should be at least one stop symbol in any flowchart.5. A condition box should have one entry point and 2 exit
points.
6. For lengthy flowcharts, covering more than a page,
connectors can be used to join them.
-
7/29/2019 c Language Basic
5/11
Advantages of flowchart
1. Flowcharts form a good visual aid to represent the logic
for the program solution.
2. It is a form of program documentation.
3. The program can be coded efficiently using flowchart.4. It facilitates orderly debugging and testing of program.
5. It provides efficient program maintenance.
Disadvantages of flowchart
1. It is not useful to represent complex program logic, since
it becomes clumsy and lacks clarity.
2. For any alterations the flowcharts have to redrawn
completely.
Example:
Write a flowchart to input marks of four subjects
and find their total and average.
-
7/29/2019 c Language Basic
6/11
(7 marks)
2. Discuss briefly about the basic structure of a C program.Documentation section
Pre processor section
Definition section
Global declaration section
Main ( )
{
Declaration part
Executable part}
Subroutine section
F1
..
Fn
START
TOTAL = M1+M2+M3+M4
AVERAGE=TOTAL/4
STOP
INT M1, M2, M3, M4
PRINT TOTAL AND AVE
RAVERA AVERAGE
-
7/29/2019 c Language Basic
7/11
1. Documentation section: This section contains a set of
comment lines useful for documentation.
2. Pre processor section: This section contains header files
which begin with a # symbol and are extended with [.h].Example for pre processor statements:
#include
#include
3. Definition section: This is used to define symbolic
constants.
# define PI=3.14159
4. Global declaration section: It is used to define variables
that would be used more than in one function. Suchvariables are called global variables which are declared
before the function.
5. The main ( ) function: All programs must contain main ( )
function. Main ( ) denotes the starting of a c-program.
6. Braces: All c-programs incorporate a set of curly braces {
}. The body of the program is written within the braces.
7. Declaration part: This part is used to declare all
variables, arrays, functions used in the c-program.8. Executable part: This part of the program consists of the
set of executable statements such as input/output
statements, arithmetic statements which is used in the
execution of the program.
9. Subroutine section: This section is optional and contains
all the user-defined functions called in the main function.
(7 marks)
3. a) Write a program to find total and average of marksobtained in 4 subjects?
#include
#include
{
int m1, m2, m3, m4;
-
7/29/2019 c Language Basic
8/11
float total, avg;
clrscr( );
printf( enter the marks of 4 subjects \n);
scanf( %d %d %d %d,&m1,&m2,&m3,&m4);
total= m1+m2+m3+m4;avg= total/4;
printf(\n the average marks =%f, avg);
return;
} (3.5 marks)
b) Write a program to compute area of the circle.
#include#include
void main( )
{
float pi,r,area;
clrscr( );
pi=3.14159;
r=5;
area= pi*r*r;printf(\n area of the circle=%f, area);
return;
} (3.5 marks)
4. Explain in detail the various C constants with examples.
Any fixed value that does not change during the execution of
the program is called a constant.
Constants are of two types1) primary constants
2) secondary constants
these can be further divided into
-
7/29/2019 c Language Basic
9/11
Integer constants
An integer constant consists of a sequence of digits and is an
integer-valued number.
It is of 3 types
1) Decimal : It is a combination of digits from 0 to 9.
2) Octal : : It is a combination of digits from 0 to 7.
3) Hexa-decimal: : It is a combination of digits from 0to 9 and letters from A through F representing
numbers from 10 to 15.
Real constants
Quantities which are represented by numbers with fractional
part are called real or floating point constants.
Example:
+325.66, 45.0, -38.2, 124.6789 are valid realconstants.
11,530, -5E 10 are invalid real constants.
C constants
primary Secondary
Numeric Character
Integer
RealSingle
characterString
Array
Pointers
Structure
Union
Enumerate
-
7/29/2019 c Language Basic
10/11
Character constants
A character constant is a single character within single quotes ,
the maximum length of a character constant is 1.
Example:
\o a | 5 = are valid character constants.xy a4 26 are invalid character constants.
String constants
A string constant consists of zero or more number of
characters enclosed within double quotes.
Example:
red phone:344-5670 are valid string constants.
tc error are invalid string constants.The string is a null string.
(7 marks)
5. Write a program to illustrate the working of a simple
macro.
#include
#define AREA length*width
#define EQUALS ==#define OR ||
void main ( )
{
int length, width;
clrscr( );
printf(\n enter length and width:);
scanf(%d %d , &length, &width);
if( length EQUALS 0) or (width EQUALS 0))
printf(\n area does not exist);else
printf(\n area =%d , AREA);
return;
}
( 7 marks)
-
7/29/2019 c Language Basic
11/11