Vous êtes sur la page 1sur 6

# Unit I

Syllabus

## Algorithm / pseudo code, flowchart, program development steps, structure of C

program, A Simple C program, identifiers, basic data types and sizes, Constants,
variables, arithmetic, relational and logical operators, increment and decrement
operators, conditional operator, bit-wise operators, assignment operators, expressions,
type conversions, conditional expressions, precedence and order of evaluation. Input-
output statements, statements and blocks, if and switch statements, loops- while, do-
while and for statements, break, continue, goto and labels, programming examples

Algorithms,Flowcharts

## 1.Draw a Flowchart for the following

The average score for 3 tests has to be greater than 80 for a candidate to
qualify for the interview. Representing the conditional logic for generating
reject letters for all candidates who do not get the required average &
interview call letters for the others.

| Start |
---------
|
|
----------
/ Read M1 /
----------
|
----------
/ Read M2 /
----------
|
----------
/ Read M3 /
----------
|
----------------
| Tot=M1+M2+M3 |
----------------
|
|
----------------
| |
| avg=tot/3 |
| |
----------------
|
|
/\
/ \
/ \
/ \ NO
/if avg<80\_______
\ / |
\ / |
\ / |
\ / ----------
\/ / /
| / Print /
Yes| / Reject /
| ----------
| |
---------- |
/ / |
/ Print / |
/ Call / |
/ / |
---------- |
| |
| |
------------
|
|
---------
| Stop |
---------

## a. Explain the basic structure of C program. [Answer Tip] [10+6]

Basics (I/O)

2.

a.Distinguish between get char and scanf functions for reading strings
Type

## o getchar( ) accepts only character type

o scanf( ) accepts any type
White space

## o getchar( ) can accept strings with spaces

o scanf( ) accepts string without space (Space is separator)

Size

## o getchar( ) can accept string of dynamic size

o scanf( ) can accept only fixed size string

a. What is the difference between signed integer and unsigned integer in terms of
memory and range [Answer Tip]
3.
a. What are the general characteristics of C? [Answer Tip]
b. Give and Explain the structure of a C program? [Answer Tip]
c. Write a C program to print the Pascal’s triangle. [Answer Tip]
[4+4+8]

## Constants, Data types and Variables

4. Write about space requirements for variables of different data types.[Answer Tip]. [16]
5.
a. What is the difference between signed integer and unsigned integer in terms of
memory and range [Answer Tip].
b. List the entire data types in C. What is the size of each of these data types [Answer
Tip]. [8+8]
6.
a. What is a string constant? How do string constants differ from character constants?
Do string constants represent numerical Values?
b. Summarize the standard escape sequences in C. Describe them. [Answer Tip]
c. What is a variable? How can variables be characterized? Give the rules for variable
declaration.

## Variable is a place holder to store values or other variables or expressions

These are also called as dataname to store data value
Better to give the name of the variable that reflects meaningful way
Rules for Variable Name

## Whitespace is not allowed

Variable name may be mix of upper/lower case letters

d. What is the purpose of type declarations? What are the components of type
7.
a. What are different types of integer constants? What are long integer con- stants? How
do these constants differ from ordinary integer constants? How can they be written
and identified? [Answer Tip]
b. Describe two different ways that floating-point constants can be written in C. What
special rules apply in each case?[Answer Tip]
c. What is a character constant? How do character constants differ from numeric type
constants? Do character constants represent numerical values? [Answer Tip][6+4+6]

Operators

8.
a. What is meant by operator precedence? What are the relative precedence of the
arithmetic operators? [Answer Tip]
b. What is the associatively of the arithmetic operators?[Answer Tip]
c. How can the value of an expression be converted to a different data types? What is

## If the operands are of different types,

the lower/less priority type is automatically converted
in to higher/more priority type
Result of the expression is of higher type
This process is called as type conversion
eg: int a=10; long int b=21414321L;
a+b results towards long int

d. What are unary operators? Explain example for each. [Answer Tip][4+4+4+4]
9.
a. Explain the following & illustrate it with an example each.
i. Increment & Decrement operator.[Answer Tip]
ii. Conditional operator. [Answer Tip]
iii. Bitwise operator. [Answer Tip]
iv. Assignment operator. [Answer Tip]
b. State the rules that applied while evaluating expression in automatic type conversion.
Loops

10.
a. What is the purpose of break statement? [Answer Tip]
b. Suppose a break statement is included within the innermost of several nested control
statements. What happens when break statement is executed?
for(i=0;i<n;i++)
{
------
---
--
for(j=0;j<n;j++)
{
------
---
for(k=0;k<n;k++)
{
---
----
if(condition)
break;
---
-----
}
}
}
whenever the if condition is satisfied the control immediately exit from
the k for loop,now the control will be present in j for loop [Answer Tip]

## Write a program to print the multiplication table up to 20 with proper format.

#include<stdio.h>
void main()
{
int i,n;
printf("\n enter n value");
scanf("%d",&n);
printf("\n MULTIPLICATION TABLE FOR %d IS",n);
for(i=1;i<=20;i++)
printf("\n %d X %d = %d",n,i,(n*i));
}
OUTPUT
enter n value 2
MULTIPLICATION TABLE FOR 2 IS
2X1=2
2X2=4
2X3=6
2X4=8
-----
--------
------
2 X 18 = 36
2 X 19 = 38
2 X 20 = 40

Programs

11.a)Write a program to determine and print the sum of the following harmonic series for a given
value of n: 1+1/2+1/3+.....+1/n.

#include<stdio.h>
void main()
{
int i,n;
float sum=0.0;
printf("\n enter n value");
scanf("%d",&n);

for(i=1;i<=n;i++)
sum=sum+(1.0/i);
printf("\n Sum= %f",sum);
}

OUTPUT
enter n value 5

Sum=2.2833333333333333333333333333333

b).What are the logical operators used in C and illustrate with examples. [Answer Tip][8+8]

12.write a C program to print the lower triangular of a given square matrix. [Answer Tip][16]

for(i=1;i<=m;i++)
for(j=1;j<=m;j++)
if (i<=j)
printf("%d",i);
else
printf("%d",0);