0% found this document useful (0 votes)
44 views31 pages

QA UNIT I Basics of C Programming

Jjñhhggyttttggkmmkkkk

Uploaded by

taneshbirari22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views31 pages

QA UNIT I Basics of C Programming

Jjñhhggyttttggkmmkkkk

Uploaded by

taneshbirari22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

[Link]

com/programming-in-c-
for-msbte-k-scheme/
312303 - Programming In ‘C’ (Sem II)
As per MSBTE’s K Scheme
CO / CM / IF / AI / AN / DS

Unit I Basics of ‘C’ Programming Marks - 12

S.N. MSBTE Board Asked Questions with Answers Year Marks

S-22,
1 List any four key words used in ‘C’ W-23 S- 2M
19
Ans. auto Double int struct

break Else long switch

case Enum register typedef

char Extern return union

const Short float unsigned

3 Give theuse of Printf( ) S-23 2M


Ans. The printf( ) is a library function to send formatted output to the screen. The function
prints the string inside quotations. To use printf( ) in our program, we need to
include stdio.h header file using the #include <stdio.h> statement.

4 Define algorithm S-23 2M

Ans. An algorithm is a sequence of instructions that are carried out in a predetermined


sequence in order to solve a problem or complete a work. A function is a block of code
that can be called and executed from other parts of the program.

A set of instructions for resolving an issue or carrying out a certain activity.


Draw flowchart for checking whether given number is positive or
5 W-23 2M
negative.
Ans.

W-23, S-
6 Drawandlabeldifferentsymbolsusedin flowchart. 2M
22, W-19
Ans.
Draw flow chart for finding largest number among three W-23, S-
7 4M
numbers. 22, S-19
Ans.

W-23, S-
8 State the use of printf() and scanf( ) with suitable example. 4M
22
Ans. The printf( ) function is used to display output and the scanf() function is used to take
input from users.

The printf( ) and scanf( ) functions are commonly used functions in C Language. These
functions are inbuilt library functions in header files of C programming.

printf( ) Function
In C Programming language, the printf( ) function is used for output.

printf( ) function can take any number of arguments. First argument must be
enclosed within the double quotes “hello” and every other argument should be
separated by comma ( , ) within the double quotes.

Important points about printf( ):

 printf( ) function is defined in stdio.h header file. By using this function, we can
print the data or user-defined message on monitor (also called the console).
 printf( ) can print a different kind of data format on the output string.
 To print on a new line on the screen, we use “\n” in printf() statement.

C language is case sensitive programming language. For example, printf() and scanf()
in lowercase letters treated are different from Printf() and Scanf(). All characters in
printf() and scanf() builtin functions must be in lower case.

Syntax

printf("format specifier",argument_list);

The format string for output can


be %d (integer), %c (character), %s (string), %f (float) %lf (double)
and %x (hexadecimal) variable.

Simple Example of printf( ) Function

#include<stdio.h>

Int main( )

Int num =450;// print number

printf("Number is %d \n", num);

return 0;

}
W-23, S-
6 Write a program to print Fibonacci series starting from 0 and 1. 6M
22, W-19
Ans. #include <stdio.h>
int main( )
{
int i, n;
// initialize first and second terms
int t1 = 0, t2 = 1;
// initialize the next term (3rd term)
int nextTerm = t1 + t2;
// get no. of terms from user
printf("Enter the number of terms: ");
scanf("%d", &n);
// print the first two terms t1 and t2
printf("Fibonacci Series: %d, %d, ", t1, t2);
// print 3rd to nth terms
for (i = 3; i <= n; ++i) {
printf("%d, ", nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
Write algorithm and draw flow-chart to print even numbers W-23, W-
7 4M
From 1 to 100. OR 1 to 50 18
Ans Algorithm
1. Start
2. Initialize the variable i to 1.
3. while i<=100
4. if i%2==0
5. print the number
6. increment value of i
7. stop
Flowchart

8 List the symbol used in flow chart any four S-23 2M

Ans.
Write a c program among three numbers find largest number
11 S-23 4M
Among three
Ans.

#include <stdio.h>

Int main( ) {

intA, B, C;

printf("Enter three numbers: ");

scanf("%d %d %d", &A, &B, &C);

if(A >= B) {

if(A >= C)

printf("%d is the largest number.", A);

else

printf("%d is the largest number.", C);

else{

if(B >= C)

printf("%d is the largest number.", B);

else

printf("%d is the largest number.", C);

return 0;

}
12 Explain use comment in clanguage S-23 4M

Ans. The comments in C are human-readable explanations or notes in the source code of
a C program. A comment makes the program easier to read and understand. These
are the statements that are not executed by the compiler or an interpreter.

It is considered to be a good practice to document our code using comments.

When and Why to use Comments in C programming?


1. A person reading a large code will be bemused if comments are not
provided about details of the program.
2. C Comments are a way to make a code more readable by providing more
descriptions.
3. C Comments can include a description of an algorithm to make code
understandable.
4. C Comments can be used to prevent the execution of some parts of the code.

Types of comments in C
In C there are two types of comments in C language:

 Single-line comment
 Multi-line comment
 Single-line Comment in C
A single-line comment in C starts with ( // ) double forward slash. It extends till the
end of the line and we don’t need to specify its end.

Syntax of Single Line C Comment

// This is a single line comment

Multi-line Comment in C
The Multi-line comment in C starts with a forward slash and asterisk ( /* ) and ends
with an asterisk and forward slash ( */ ). Any text between /* and */ is treated as a
comment and is ignored by the compiler.

It can apply comments to multiple lines in the program.

Syntax of Multi-Line C Comment


/*Comment starts
continues
continues
.
.
Comment ends*/

13 Describe use of header files in c language S-23 4M

Ans.

In C language, header files contain a set of predefined standard library functions.


The .h is the extension of the header files in C and we request to use a header file in
our program by including it with the C preprocessing directive “#include”.

C Header files offer the features like library functions, data types, macros, etc by
importing them into the program with the help of a preprocessor directive
“#include”.

Syntax of Header Files in C


We can include header files in C by using one of the given two syntax whether it is a
pre-defined or user-defined header file.
#include <filename.h> // for files in system/default directory
or
#include "filename.h" // for files in same directory as source file
The “#include” preprocessor directs the compiler that the header file needs to be processed
before compilation and includes all the necessary data types and function definitions.
14 Explain formatted input out put function with example S-23 4M

Ans. This article focuses on discussing the following topics in detail-

 Formatted I/O Functions.


 Unformatted I/O Functions
Formatted I/O Functions vs Unformatted I/O Functions.

Define the terms :


15 i) Flowchart W-22 2M
ii) Algorithm.
Ans. Algorithm:
An Algorithm is a set of commands that must be followed for a computer to perform
calculations or other problem-solving operations.
Flowchart:
A flowchart is a pictorial representation of an algorithm. It uses different patterns to
illustrate the operations and processes in a program.

19 Explain any four guide lines for preparation of flow chart. W-22 4M

Ans. 1. The flowchart should be neat, clear and easy to follow.


2. Symbols should be used correctly to show flow of program.
3. There should not be any ambiguity in understanding the flowchart. 4. The flowchart is
to be read from left to right and top to bottom.
16 State any four data types used in ‘C’. W-22 2M

Ans.
Types Data Types

Basic Data Type int, char, float, double

Derived Data Type array, pointer, structure, union

Enumeration Data Type Enum

Void Data Type Void

17 List logical operators in ‘C’. W-22 2M

Ans.

Logical operators in C are used to combine multiple conditions/constraints. Logical


Operators returns either 0 or 1, it depends on whether the expression result is true
or false. In C programming for decision-making, we use logical operators.

We have 3 logical operators in the C language:

 Logical AND ( && )


 Logical OR ( || )
 Logical NOT ( ! )

24 Write syntax and use of PQW ( ) function or header file. S-22 2M

:
pow()- compute the power of a input value Syntax: double pow (double x, double y);

Ans.
Draw any two symbols used to construct flow chart. Also state
18 W-22 2M
Their use.
Ans.

20 Explain data type conversion with example. W-22 4M

Ans. Type conversion:


It is referred as Type Casting. It is used to convert one data type into another
data type.
Implicit conversion :
It converts any intermediate values to the proper type automatically.
Example: If one of the operands is double, the other will converted to double and the
result will be in double data type.
Explicit conversion:
The process of converting one data type to another data type forcefully is
known as explicit conversion.
Syntax : (data_type name) expression;
Example: double x = 1.2; int sum = (int)x + 1;
The above statement converts value of variable x from double to integer.
Explain any two string handling functions with syntax and
21 W-22 4M
example.
Ans. 1. strlen function:
strlen( ) function in C gives the length of the given string. strlen( )
function counts the number of characters in a given string and returns the integer
[Link] stops counting the character when null character is found. Because, null
character indicates the end of the string in C.
Syntax:
strlen(stringname);
Example:
Consider str1=”abc”
strlen(str1); returns length of str1 as 3
2. strcat( ) function:
In C programming, strcat( ) concatenates (joins) two strings. It concatenates source
string at the end of destination string.
Syntax:
strcat( destination string, source string);
Example:
Consider str1=”abc” and str2=”def”
strcat(str1,str2); returns abcdef in str1 and str2 remains unchanged.
3. strcpy() function
strcpy( ) function copies portion of contents of one string into another string.
Syntax:
strcpy( destination string, source string);
Example:
Consider str1=”abc”
strcpy(str1,str2);
[Link]( ) function
The strcmp function compares two strings which are passed as Arguments to it. If the
strings are equal then function returns value 0 and if they are not equal the function
returns some numeric value.
Syntax:
strcmp( str1, str2);
22 Describe scanf( ) function with its syntax and example W-22 4M

Ans. scanf( ) function:


It is used to accept input from user during execution
of a program.
Syntax: scanf("Control string",arg1,arg2,...,argn);
control string specifies the field format in which the data is to be entered. Control
string contains conversion character % and a data type character and optional number
specifying the field width. The arguments arg1,arg2,...,argn specify the address of
locations where the data is stored. Control string and arguments are separated with
comma. It can also have blanks, tabs, or newlines.
Example: scanf("%d%f",&a, &b);
In the above example, %d inside control string indicates integer data type whereas %f
inside control string indicates float data type. Ampersand symbol (&) written before
variable name is used to retrieve address / memory location of variable. This scanf ( )
function accepts one integer value and stores it in variable a and one float value that is
stored in variable b.
Writeanalgorithmanddrawaflowcharttofindlargestnumber
23 W-22 4M
fromthree numbers.
Ans. Algorithm: Step 1:Start Step
2:Declare variables no1,no2,no3
Step 3: Accept / Initialize values for variables no1,no2,no3 Step 4: If no1 >no2 and
no1>no3 then display "no1 is largest" otherwise check if no2>no1 and no2>no3 then
display "no2 is largest" otherwise display "no3 is largest"
Step 5: Stop
25 Drawflowchartforadditionoftwonumbers. S-22 2M

Ans.

26 Writeanalgorithmtofindlargestofthree numbers. S-22 4M

Ans. Algorithm:
Step 1:Start
Step 2:Declare variables no1,no2,no3
Step 3: Accept / Initialize values for variables no1,no2,no3
Step 4: If no1 >no2 and no1>no3 then display "no1 is largest" otherwise check if
no2>no1 and no2>no3 then display "no2 is largest" otherwise display "no3 is largest"
Step 5: Stop

S- 22,
Describethefollowingterms:(i)Keyword(ii)Identifier(iii) Variable (iv)
27 W-19, 4M
Constant
W-23
Ans Keyword: Keywords are special words in C programming which have their own
predefined meaning. The functions and meanings of these words cannot be altered.
Some keywords in C Programming are if, while, for, do, etc..

(ii) Identifier: Identifiers are user-defined names of variables, functions and arrays. It
comprises of combination of letters and digits. Example int age1; float height_in_feet;
Here, age1 is an identifier of integer data type. Similarly height_feet is also an identifier
but of floating integer data type,

(iii) Variable: A variable is nothing but a name given to a storage area that our programs
can manipulate. Each variable in C has a specific type, which determines the size and
layout of the variable's memory; the range of values that can be stored within that
memory; and the set of operations that can be applied to the variable. Example: add, a,
name

(iv) Constant:

Constants refer to fixed values that the program may not change during its execution.
These fixed values are also called literals. Constants can be of any of the basic data types
like an integer constant, a floating constant, a character constant, or a string literal.
There are enumeration constants as well.

28 Writeaprogramtodisplaytableofgivennumber(Accept S-22 4M
numberfromuser).
Ans.
1. #include <stdio.h>
2. int main( ) {
3. int num, i; // declare a variable
4. printf (" Enter a number to generate the table in C: ");
5. scanf (" %d", &num); // take a positive number from the user
6.
7. printf ("\n Table of %d", num);
8. // use for loop to iterate the number from 1 to 10
9. for ( i = 1; i <= 10; i++)
10. {
11. printf ("\n %d * %d = %d", num, i, (num*i));
12. }
13. return 0;
14. }
29 Write a program to sum all the even numbers between 1 to 100. S-22 4M

Ans. /**
* C program to print sum of all even numbers between 1 to n
*/

#include <stdio.h>

int main()
{
int i, n, sum=0;

/* Input upper limit from user */


printf("Enter upper limit: ");
scanf("%d", &n);

for(i=2; i<=n; i+=2)


{
/* Add current even number to sum */
sum += i;
}

printf("Sum of all even number between 1 to %d = %d", n, sum);

return 0;
}

30 Find the output of the following program: W-19 2M


# include < stdio.h>
void main()
{
intx=10,y=10,v1,v2; v1 = x++ ;
v2 = ++y ;
printf("valueofv1:%d",v1);
printf("valueofv2:%d",v2);
}
Ans
Output: value of v1:10value of v2:11
32 Draw flow chart for addition of two numbers. W-19 2M

Ans

33 State the importance of flowchart. W-19 4M

Ans. A flowchart is a type of diagram that represents an algorithm. It is a visual


representation of a sequence of steps to complete the process. A flow chart describes a
process using symbols rather than words. Computer programmers use flow charts to
show where data enters the program, what processes the data goes through, and how the
data is converted to output.
 It can be used to quickly communicate the ideas or plans that one programmer
envisions to other people who will be involved in the process.
 It aid in the analysis of the process to make sure nothing is left out and that all
possible inputs, processes, and outputs have been accounted better understanding.
 It help programmers develop the most efficient coding because they
 It can clearly see where the data is going to end up.
 It help programmers figure out where a potential problem area is and helps them
with debugging or cleaning up code that is not working.
 They are a useful tool in visualizing a module's flow of execution before writing any
code. This allows developers to do three things: verify the algorithm's correctness
before writing code, visualize how the code will ultimately be written, and
communicate and document the algorithm with other developers and even non-
developers.
 It may be used in conjunction with other tools, such as pseudo-code, or may be used
by itself to communicate a module's ultimate design, depending on the level of
detail of the flowchart

34 Explain conditional operator with example. W-19 4M

Ans. Conditional Operator (Ternary Operator):


It takes the form „? :‟ to construct conditional expressions
The operator „? :‟ works as follows:
exp1 ? exp2 : exp 3
Where exp1, exp2 and exp3 are expressions.exp1 is evaluated first, If it is true, then the
expression exp2 is evaluated and becomes the value
Conditional Operator (Ternary Operator):
It takes the form „? :‟ to construct conditional expressions The operator „? :‟ works as
follows: exp1 ? exp2 : exp 3 Where exp1, exp2 and exp3 are expressions.exp1 is evaluated
first, If it is true, then the expression exp2 is evaluated and becomes the value
Write an algorithm to determine the given number is odd or
35 W-19 4M
even.
Ans. Step 1- Start
Step 2- Read / input the number.
Step 3- if n%2==0 then number is even.
Step 4- else number is odd.
Step 5- display the output.
Step 6- Stop
Write a program to calculate sum of all the odd numbers between
36 W-19 6M
1 to 20.
Ans. #include<stdio.h>
#include<conio.h>
void main( ) {
inti,sum=0;
clrscr( );
for(i=1;i<=20;i++)
{
if(i%2!=0)
{
sum=sum+i;
}
}
printf("Sum=%d",sum);
getch();
}
Draw f low chart for checking whether given number is even or
37 S-19 2M
odd
Ans.

38 List any four keywords used in ‘ C’ with their use. S-19 2M


Ans. Keywords Used in C are listed below -
 auto - It is used to declare auto storage class variable.
 Break - It is used to exit from block or loop.
 case - It is used to represent possible case inside switch case statement
 char - Used for declaration of character type variable
 const - It is used to declare a constant.
 Continue - It is used pass control at the beginning of the loop
 default - It is used to represent default case inside switch case statement.
 do - It is used to execute loop in association with while condition.
 double - Used for declaration of double type variable
 else - It is used with if statement to transfer control to statement when condition is
false.
 enum - It is used to declare enumerated data.
 extern - It is used to declare extern storage class variable
 float - Used for declaration of float type variable
 for - Used for repetitive execution of statements
 goto - It is used to transfer control from one statement to another
 if - It is used for condition checking
 int - Used for declaration of integer type variable
 long - Used for declaration of long type variable
 register - It is used to declare register storage class variable
 return - It is used to return value from function.
 short - Used for declaration of short type variable
 signed - Used for declaration of signed type variable
 sizeof - It returns memory size allocated to variable or data type
 static - It is used to declare static storage class variable
 struct - It is used to declare user defined data type structure
W-23
39 Write a program to sum all the odd numbers between1 to20. 4M
, S-19
Ans. #include<stdio.h>
#include<conio.h>
void main( ) {
inti,sum=0;
clrscr( );
for(i=1;i<=20;i++) {
if(i%2!=0) {
sum=sum+i;
}
}
printf("Sum=%d",sum);
getch( );
}

40 Explain any four bit-wise operator used in ‘C’ with example. S-19 4M

Ans. Bitwise OR |
It takes 2 bit patterns and performs OR operations on each pair of
corresponding bits. The following example will explain it.
1010
1100
--------
OR 1110

Bitwise AND &


It takes 2 bit patterns and performs AND operations with it.
1010
1100
-------
AND 1000
-------
The Bitwise AND will take pair of bits from each position, and if
only both the bit is 1, the result on that position will be 1. Bitwise
AND is used to Turn-Off bits.

Bitwise NOT
One s complement operator (Bitwise NOT) is used to convert each
-bit to 0- -bit to1-
unary operator i.e. it takes only one operand.
1001
NOT 0110

Bitwise XOR ^
Bitwise XOR ^, takes 2 bit patterns and perform XOR operation with
it.

41 Describe generic structure of ‘C’ program. S-19 4M

Ans. Documentation section:


The documentation section consists of a set of comment lines giving the name of the
program, the author and other details, which the programmer would like to use later.
Link section:
The link section provides instructions to the compiler to link functions from the system
library such as using the #include directive.
Definition section:
The definition section defines all symbolic constants such using the #define directive.
Global declaration section:
There are some variables that are used in more than one function. Such variables are
called global variables and are declared in the global declaration section that is outside
of all the functions.
Declaration part:
The declaration part declares all the variables used in the executable part.
Subprogram section:
If the program is a multi-function program then the subprogram section contains all the
user-defined functions that are called in the main () function.
User-defined functions are generally placed immediately after the main () function,
although they may appear in any order.
Header files
A header file is a file with extension .h which contains C function declarations and macro
definitions to be shared between several source files.
Include Syntax
Both the user and the system header files are included using the preprocessing directive
#include.
main() function is the entry point of any C program. It is the point at which execution of
program is started. Every C program have a main() function.
42 Write a program to accept ten numbers and print average of it. S-19 6M
Ans. #include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,sum=0;
float avg;
clrscr();
printf("Enter numbers:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
sum=sum+a[i];
avg=sum/10;
printf("\n Average =%f", avg);
getch();
}
43 Enlist different format specifiers with its use. S-19 6M
Ans. Format specifier tells the compiler what type of data a variable holds
during taking input and printing output using scanf() and printf()
functions respectively.
Format specifiers used in C programming:Format
specifier
Use
%d Specify data type as short signed
%u Specify data type as short unsigned
%ld Specify data type as long singed
%lu Specify data type as long unsigned
%x Specify data type as unsigned hexadecimal
%o Specify data type as unsigned octal
%f Specify data type as float
%lf Specify data type as double
%Lf Specify data type as long double
%c Specify data type as signed character
%s Specify data type as unsigned group of
characters(Strings)

44 Define Algorithm. W-18 2M


Ans.
Algorithm:- Algorithm is a stepwise set of instructions written to
perform a specific task.
45 Give the significance of and header files. W-18 2M
Ans.
math.h” header file supports all the mathematical related functions in C language. stdio.h
header file is used for input/output functions like scanf and printf
46 Write syntax and use of pow( ) function of header file. W-18 2M
Ans.
pow()- compute the power of a input value
Syntax: double pow (double x, double y);

47 Draw and label symbols used in flow chart. W-18 2M


Ans.

48 Explain increment and decrement operator. W-23, W-18 4M


Ans. Increment operator is used to increment or increase the value of a
variable by one. It is equivalent to adding one to the value of the
variable. The symbol used is ++. The decrement operator is used to
decrement or decrease the value of variable by 1. It is equivalent to
subtracting one from the value of the variable. The symbol used is --.
Syntax: ++var or var++ for increment and --var or var--for
decrement.
Example:
int m=5;
int n = ++m;
printf(%d%d”,m,n);
When the increment operator is used prior to the variable name m, the
value of the variable m is incremented first and then assigned to the
variable n. The values of both the variable m and n here will be 6. But
if the increment operator ++ is used after the variable name, then the
value of the variable m is assigned to the variable n and then the
value of m is increased. Therefore the values of m and n will be 6 and
5 respectively.
Example for decrement operator
int m=5;
int n=--m
49 Explain conditional operator with example. W-18 4M
Ans. Conditional operators return one value if condition is true and returns
another value is condition is false. This operator is also called as
ternary operator as it takes three arguments.
Syntax :
(Condition? true_value: false_value);
Example:
#include<stdio.h>
#include<conio.h>
void main() {
int i;
clrscr();
printf("Enter a number:");
scanf("%d",&i);
i%2==0?printf("%d is even",i):printf("%d is odd",i) ;
getch();
}
50 Write a program to accept the value of year as input from the W-18 4M
Keyboard & print whether it is a leap year or not
Ans. #include<stdio.h>
#include<conio.h>
void main() {
int year;
clrscr();
printf("Enter year");
scanf("%d",&year);
if(year%4==0) {
printf("Year %d is a leap year",year);
} else {
printf("Year %d is not a leap year",year);
}
getch();
}
51 Define type casting. Give anyone example. S-18 2M
Definition type casting:
The conversion of one data type to another is known as type casting.
The values are changed for the respective calculation only, not for
any permanent effect in a program.
For example,
x=int (7.5) means 7.5 is converted to integer by truncating it i.e. 7
b=(int) 22.7/(int) 5.3 means 22.7 will be converted to 22 and 5.3 to 5
so answer will be 22/5=4
c=(double) total/num means the answer will be in float value.
p=sin((int)x) means x will be converted to integer and then sine angle
will be calculated.
52. State the use of following symbols used for flowchart drawing :
(i)

(ii)
S-18
(iii) 2M

(iv)`

Ans.
53 State the use of printf( ) & scanf( ) with suitable example. S-18 4M
Ans. The printf() function is used to display output and the scanf() function is used
to take input from users.
The printf() and scanf() functions are commonly used functions in C
Language. These functions are inbuilt library functions in header files of C
programming.
________________________________________
printf() Function
In C Programming language, the printf() function is used for output.
printf() function can take any number of arguments. First argument must be
enclosed within the double quotes “hello” and every other argument should
be separated by comma ( , ) within the double quotes.
Important points about printf():
• printf() function is defined in stdio.h header file. By using this function,
we can print the data or user-defined message on monitor (also called the
console).
• printf() can print a different kind of data format on the output string.
• To print on a new line on the screen, we use “\n” in printf() statement.
C language is case sensitive programming language. For example, printf() and
scanf() in lowercase letters treated are different from Printf() and Scanf(). All
characters in printf() and scanf() builtin functions must be in lower case.
Syntax
printf("format specifier",argument_list);
The format string for output can be %d (integer), %c (character), %s (string),
%f (float) %lf (double) and %x (hexadecimal) variable.
Simple Example of printf() Function
#include<stdio.h>
int main(){int num = 450;// print numberprintf("Number is %d \n", num);
54 Develop a simple ‘C’ program for addition and multiplication S-18 4M
of
Two integer numbers.
Ans. #include<stdio.h>

#include<conio.h>

void main()

int a,b,add,mul;

clrscr();

printf("Enter value for a and b:");

scanf("%d%d",&a,&b);
add=a+b;

mul=a*b;

printf("\nAddition of a and b=%d\n",add);

printf("\Multiplication of a and b=%d",mul);

getch();

55 Explain any four library functions under conio.h header file. S-18 4M
Ans. clrscr() -This function is used to clear the output screen.
getch() -It reads character from keyboard
getche()-It reads character from keyboard and echoes to o/p screen
putch - Writes a character directly to the console.
textcolor()-This function is used to change the text color
textbackground()-This function is used to change text background
56 Explain how formatted input can be obtain , give suitable S-18 4M
example.
Ans. Formatted input:
When the input data is arranged in a specific format, it is called
formatted input. scanf function is used for this purpose in C.
General syntax:
scanf(“control string”, arg1, arg2..);
Control string here refers to the format of the input data. It includes
the conversion character %, a data type character and an optional
number that specifies the field width. It also may contain new line
character or tab. arg1, arg2 refers to the address of memory locations
where the data should be stored.
Example:
scanf(“%d”,&num1);
Eg:
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("Enter a number");
scanf("%d",&i);
printf("Entered number is: %d",i);
getch();
}
57 Write a program to swap the values of variables a = 10 , b = 5 S-18 4M
using function.
Ans.
#include<stdio.h
void swapvalues(int *i, int *j)
{
int temp;
temp=*i;
*i=*j;
*j=temp;
}
void main() {
int a=10;
int b=5;
clrscr();
printf("The values before swaping:\na=%d, b=%d",a,b);
swapvalues(&a,&b);
printf("\nThe values after swaping:\na=%d, b=%d",a,b);
getch();
}
58 Design a program to print a message 10 times. S-18 4M
Ans. #include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=0;i<10;i++)
{
printf("Welcome to C programming\n");
}
getch();
}
59 Implement a program to demonstrate logical AND operator. S-18 4M
Ans. #include<stdio.h>
#include<conio.h>
void main()
{
int i;
int j;
clrscr();
printf("Enter the values of i and j");
scanf("%d%d",&i,&j);
if(i==5 && j==5) {
printf("Both i and j are equal to 5");
} else {
printf("Both the values are different and either or both are not
equal to 5");
}
getch();
}
60 Design a program in C to read the n numbers of values in an S-18 6M
Array and display it in reverse order.
#include<stdio.h>
#include<conio.h>
#define max 50
void main()
{
int a[max],i,n;
clrscr();
printf("\n Enter number of elements:");
scanf("%d",&n);
printf("\n Enter array element:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n Array elements in reverse order:");
for(i=n-1;i>=0;i--)
printf("\t%d",a[i]);
getch();
}

sThank You
[Link]
scheme/

Visit
[Link]

You might also like