0% found this document useful (0 votes)
21 views17 pages

Electronicsnotes-3 66947

The document provides an overview of the C programming language, detailing its features, structure, and fundamental concepts such as data types, operators, control statements, and functions. It covers the syntax for writing basic C programs, including the use of preprocessor directives, keywords, identifiers, and various types of operators. Additionally, it explains control flow mechanisms like conditional and iterative statements, along with examples for better understanding.

Uploaded by

aditianand2705
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)
21 views17 pages

Electronicsnotes-3 66947

The document provides an overview of the C programming language, detailing its features, structure, and fundamental concepts such as data types, operators, control statements, and functions. It covers the syntax for writing basic C programs, including the use of preprocessor directives, keywords, identifiers, and various types of operators. Additionally, it explains control flow mechanisms like conditional and iterative statements, along with examples for better understanding.

Uploaded by

aditianand2705
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/ 17

12.

2 Electronics

Synopsis
C is a general purpose, structured programming language also called mid level language as it combines the features of
high level & low level language.

C language is created by “Dennis Ritchie” in 1972,


Features of C:
• Suitable for both system software & application programmes
• highly portable
• Efficient & fast
• Easy debugging & testing
• Self extending ability
• Any complex program can be written

Format of basic C program:

main ( ) ← Function name


{ ← Start of program

]← Function body

} ← End of program
• main ( ) is a special function used to tell the complier where the program starts & the empty pair of paranthesis
indicate that the function main has no arguments.
• ‘{‘ indicates the starting of main function & ‘}’ indicates the end of the function & also end of the program.
• Function body between the braces contain a set of instruction that perform the given task.
• The lines beginning with /* & ending with */ are called comment lines used to enhance the readability &
understanding & these are not executable statements. // Can also be used for single line comment.
The C preprocessors: It is a program that process the source code before passing to complier.
It operates under the control of preprocessor directives and included in the program before main function.
Commonly used directives are
# include → Specifies the files to be included that required for the program.
# define → Define a macro substitution
# include directive: To include an external file containing functions & definition that required for the program so
that, need not require to rewrite them.
To include the file: # include < filename >
Or # include “file name”
Commonly include header files are #include “stdio.h” [standard input output header file]
#include “conio.h” [Consolidated input output header file]
An include file can include other files ‘but cannot include itself.
# define directive: Here preprocessor replaces the name by the equivalent where ever it occur in the program.
# define name equivalent
There are different forms of macro substitution.
• Simple macro substitution:
# define PI 3.1415
# define CAPITAL “BANGALORE”
• Argumented macro substitution:
# define SQUARE (x) (x * x)
• Nested macro substitution:
#define SQUARE (X) (X *X)

#define FOURTH(X) (SQUARE(X) * SQUARE(X))
C-Programming 12.3

→ Commonly include leader files are # include “stdio.h” [standard input output leader free]
# include “conio.h” [consolidated input output leader free]
Character set: These are used to form words, numbers & expression. The C character set can be classified int
• Letters: A………….Z
a ………… z
• Digits: 0 ………… 9
• Special characters: , . : ; ? “ ‘ # = & * > < / { [
• White space: ‘ ’
C Tokens: The basic & the smallest unit of C program. They are
• Keywords • Identifiers
• Constants • Strings
• Operators • Special symbols
Keywords
The special words used in C program which have specific meaning that already defined in C.
There are 32 keywords in C & they must written in lower case.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Identifiers
They are the names given to the program elements such as variables, arrays & functions.
Rules for Identifier Name
• The first character must be an alphabet or an underscore.
• All succeding character must be either letters or digits.
• Only first 31 character. are considered.
• Keyword should not be used as identifier.
• No special character. are considered except ‘ ’(underscrore)
• No two successive underscores are allowed.
• Must not contain white space.
Variables: The quantity that change during the execution of program.
• They represent a particular memory location where data be scored.
• There is no limit on number of character is variable name.
• All variables must be declared before they used in C program.
• Key words should not be used as variable name.
Syntax for declaration: Datatype variablename;
Syntax for assigning value: Variablename = value;
Datatype: It tell the type of data a variable can hold. The data types are classified into
• Built in data type:
Keyword Size in byte Range
1. Integer int 2 –32, 765 to 32,767
2. Floating-point (Real) float 4 3.4 e – 38 to 3.5e + 38
3. Character char 1 –128 to 127
4. Double precision double 8 1.7e – 308 to 1.7ef 308
5. Non specific void - -
12.4 Electronics

1. Derived data type: Arrays, Pointers


2. User defined datatype: User can define his own data type.

Note

Precision floating point: Float stores maximum of 6 dig. after decimal point but double stores 16 digits after decimal
point.

Constants:
The quantity that do not change during the execute in of program.
In order to keep a value constant the keyword “const” in used.
Example: Const int P = 10;
Const float p =10.7842;

C constant

Numeric constant Non-Numeric constant

Integer Floating Character String


constant point const. const. const.

Character constant: There a single character enclosed with a pair of single quotes.
Example: ‘a’, ‘ ‘, ‘?’, ‘ y’
String constants: Here a sequence of character enclosed with pair of double quotes.
Example: “Hi”, “y”
The string constant is terminated by ‘\0’ [null character] (hence ‘y’ ≠ ‘‘y’’).

Operators
An operator is a symbol that tells the computer to perform certain mathematical or logical operations.
• Arithmetic Operators:
+ → unary plus
– → unary minus
* → multiplication
/ → division gives quotient
% → modulo division gives remainder
• Relational operators: These are used to compare two operands (const or variables) in an expression & gives
result as True (1) or false (0).
Relational operation are <, < =, >, > =, = =, ! =
• Logical operator: These operators make logic decision & gives result as Ture(1) or false (0).
Operators are
Logical AND &&
Logical OR ||
Logical NOT ! → [It is a unary operator]
Ex.: If a = 2, b = 4, c = 7
a && b || c && (!b)
= 2 && 4 || 7 && (!4)
= 2 && 4 || 7 && 0
= 1 || 7 && 0 = 1 || 0 = 1
C-Programming 12.5

• Bitwise operator: These operator perform bit by bit operation.


& → Bitwise AND [Ampersand]
1 → Bitwise OR [Pipeline]
^ → XOR [caret]
∼ → 1’s complement [Tilde]
<< → Left shifting a bit [Double less than]
<< → Right shifting a bits [Double greater than]
Ex.: a= 1 1 1 1 1

a>>1 0 1 1 1 1 → a becomes after Right shifting by 1 bit

a>>3 1 1 0 0 0 → a becomes after Left shifting by 3 bit


• Assignment operator: ‘=’ is the assignment operator used to assign some value.
Example c = a + b; c + = b;
c = 10; a * = b;
• Conditional operator: This is used to test the relationship between two variable
<Expression> ? < value 1> : <value 2>;
Example: c = a > b? a : b;
Here C is assigned with the value of a if condition is true i.e., a : b else assigned with the value of b. Conditional
operator is a ternary operator.
• Increment & decrement operator:
Increment operator used to increment the value of integer by 1 ‘++’ (double plus) is used to perform the operation
placing either before or after the variable name.
Example: a = 5;
a++; or ++a; make the value of a = 6,
Decrement operator: Used to decrement the value of variable by 1 ‘- -‘ (double minus) in the operator used to
perform decrement operation, by placing either before or after the variable.
Example: a = 5;
- -a; or a - -; make the value of a = 4;
• Special operators: Comma operator ‘,’ is used to link related expression together.
Example: Int a, b = 10, c;
Size of operator: a unary operator used to find the size of datatype, constant, array, structure etc.,
Example: Int a;
print f(“ % d”, size of (a));
print the output as 4.

Note

Difference between + + a & a ++;


↑ ↑
Int a = 5; Preincrement Post increment
Printf(“%d”, a ++); [print the value of a as 5 then the value incremented to 6] is, O/P is 5.
Printf(“% d”, ++ a); [first increment the value of a as 6, then it print the value] is, o/p is 6
Similarly - - a & a -- ;
↑ ↑
Predecrement Post decrement
12.6 Electronics

Selective Control Statements


Generally the statements in program are executed in the order in which they appear in the program, this type of
execution is called sequential execution. But in some programmes it is necessary to skip a set of statements or to repeat
a set of statements, in such situation we use control statements.
The control statements are
• Conditional control statements • Iterative control statements
Conditional control statements: Here the condition is checked to make the decision. to execute a set of statements
or to skip them.
The conditional control statements are
• If statement • If-else statement
• nested-if statement • switch statement
1. If statement: This is used to execute a set of statements only if the condition in true. It is also called one way
branching
Syntax:
If (condition)
{
Statement 1;
Statement 2;
}
Write a program to print if the entered number is even
# include <stdio.h>
# include <conio.h>
Void main ( )
{
Int P;
printf(“enter the number\n”);
scanf(“% d”, & p);
If ((p % 2) = = 0)
{
Printf (“the number is even % d”, p);
}
}

2. If-else statement: This is used to execute a set of statements if the conditional is true else to execute another set.
It is also called two way branching.
Syntax:
If (condition)
{
Statement 1;
}
else
{
Statement 2;
}
Write a program check whether the entered number is even or odd.
# include <stdio.h>
# inclue <conio.h>
Void main ( )
{
int p;
printf (“ enter the number\n”);
If ((p%2) = = 0)
{
printf(“The number is even\n”);
}
else
{
printf(“The number is odd\n”);
}
}
C-Programming 12.7

3. Nested if statement: This is used to check if the conditions are or then two.
Syntax:
if ( condition 1)
{
if (condition 2)
{
statement 1;
}
else
{
statement 2;
}
}
else if ( condition 3)
{
statement 3;
}
else
{
statement 4;
}
write a program to find largest if three number;
# include < stdio. h >
# include < conio. h >
viod main ()
{
int x,y,z;
print f (“ enter the value of x,y,z\ n”);
scanf (“ % .d% d% d% “, & x, &y, &z);
if (x >y )
{
if (x > Z)
{
print (“ x is largest \ n”);
}
else
{
}print (“ Z is largest \ m”);
else if (y > Z)
{
print (“ y is largest \n”);
}
else
{
printf (“ Z is largest \n”);
}
}
Switch Statement:
This is used to execute particular case among several tasks depending on user choice for expression. This is multiple
way of branching.
Syntax:
Switch ( expression)
{
case lable 1: statement 1;
break;
case lable 2: statement 2;
break ;

case default: statement n;
break ;
}
12.8 Electronics

Break indicates the end of particular case lable, & thereby switch statement terminated & case default is executed if the
selected value for expression is not matched with any of the case lable. The break statement for default case in optional.
Here the type of expression is int or char
write a program to find the area of geometrical figures as per user requirement.
# include < stdio. h>
# include < conio.h>
void main ( )
{
int choice;
float radius; breadth , base , height, area;
printf (“ 1 : circle 2: rectangle 3 : square);
printf ( “ enter your choice \n”);
scanf (“ % d”, & choice);
switch (choice)
{
case 1: print (“ welcome to find the area of circle\n’’);
print (“ enter the radian \n”);
scanf (“ %d”, & radius);
area= 3.14* radius * radius;
print (“ Area of circle = % f “ , area);
break;
case 2: print (“ welcome to find the area of rectangle\n”);
print (“ enter length & breadth \n”);
scanf (“ % d % d’’ , & length, & breadth);
area = length * breadth ;
print (“ Area of rectangle = % f “, area);
break ;
case 3: printf (‘‘welcome to find the area of Square\n’’);
print (“ enter the length\n”);
scanf(“ % d”, & length);
area = length * length ;
print (“ Area of square = % f’’, area);
break ;
Case default: printf (“ sorry, the choice is wrong \n”);
}
}
Loop (Iterative ) control statements: In some program a group of statements should execute repeatedly until
specified condition is satisfied, which can be achieved by Iterative or loop control statements
The loop control statements are
• while loop
• Do – while
• for
1. While loop: This is used to execute a set of statements until the specified condition is true or satisfied.
Syntax:
while (condition)
{
Statement ;
}
write a program to find sum of first n integers.
2. Do while loop: This is used to execute a set of statements until the specified condition becomes false.
Do while in called post- test loop where the statement will execute first then check for the condition. So it is the
only looping statement execute atleast once even if the condition is false.
C-Programming 12.9

Syntax:
do
{
statement ;
} while (condition);
Write a C program to find the sum of all even number between 1 to 100.
3. For statement: This is used when the programmer knows how many times does the set of statements to be
executed. It is also known as “fixed exaction”.
Here initialization, condition & Increment / decrement is mentioned in single line
Syntax:
for (intilization ; condition; increment/ decrement)
{
statement ;
}

Debugging of C Program
The process of detecting & correcting errors in the program in called debugging.
Generally programmers do 3 types of errors:
• Syntax error: This Type of errors occur due to grammatical mistake in the program. This errors are encountered
while compiling & displayed with line number where the error has occurred.
Ex.: Missing of semicolon, opening of brackets & double quote & missing of closing them.

• Logical error: This type of errors occur during coding process. if the logic used by the programmer for his problem
is not correct, the logical error occur where the program will be executed giving unwanted result.
It is difficult to debug such errors as the computer will not display them.
It can be eliminated by running the program for sample data & by inserting print statement in appropriate location.
• Run Time Errors : This type of error occur when we try to run ambiguity instruction like infinite looping.
Some run time errors are
• Divide by zero.
• Null printer assignment
• Data overflow
Testing: The process of executing the program to test the correctness of the outputs of the problem. The program is
tested with different set of data.
Input-Output Operations: In order to make the program or a system user friendly to enter his choice, input functions
are used & to display result or to help the user to choose the appropriate function output function are used.
To perform input-output operation C provides a standard input-output library. The header file that contain this
functions is stdio.h
Standard input function Standard output functions
scanf( ) printf ( )
getchar ( ) putchar ( )
gets ( ) puts ( )
getch ( )
The standard input output function are classified into two types
• Formated Input - output functions
• Unformated Input - output functions
12.10 Electronics

Type Input functions Output functions


Formated Scanf( ) printf ( )
Unformated getchar ( ) putchar ( )
gets ( ) gets ( )
Basic structure of C - Program:
# include < > 
# define  → Preprocessor directive

void main ( ) → main function
{ → start of program

Declaration port  → Program statements

} → end of program
Subroutine section
{ → uses defined function
}
Section - A
I. One Marks Questions with Answers

1. What is C programming language?


Ans. it is a mid level general purpose structure programming language.
2. Why is C language suitable for both systems and application programming?
Ans. Because C is a mid level language i.e., it has the property of both high level and low level language.
3. What is function?
Ans. it is a sub program which is written to perform a specific task and called by the main program when ever it is
required.
4. What is C pre-processor?
Ans. It is a program that process the source code before passing to complier.
It operates under the control of preprocessor directives and included in the program before main function.
5. What is debugging a C program?
Ans. It is the process of finding the logical errors in the program.
6. What is testing a program?
Ans. The process of checking the too correctness of logic used to get the expected result.
7. Where does the program be executed in a computer?
Ans. CPU
8. Write the range of values for a keyword int.
Ans. – 32 768 to + 32 767
9. What is the ASCII value of a character constant ‘ = ‘?
Ans. 61

10. What is the meaning of the symbol ‘~’ ?


Ans. The symbol ‘~’ perform is complement and called as Tilde.
C-Programming 12.11

11. What in the symbol used for XOR operation?


Ans. ^ called as caret.

12. Of A = 1 And B = 0, What is the value of A ^ B?


Ans. 1 ^ 0 = 1

13. What is the difference between ‘ = ’ and ‘ = = ’?


Ans. = is an assignment operator used to assign a value to a variable.
= = is a relational operator used to compare the values.

14. Which arithmetic operator used to represent remainder obtained in integer division.
Ans. % called modulo division.

15. What is a operator?


Ans. It is a symbol that tells the computer to certain mathematical or logical operations.

16. What is a relational operator?


Ans. The type of operators used to compare two operands In an expression and given result as True or False.

17. What is the description of the operator ^ = ?


Ans. a ^ = b or a = a^b

18. Where is conditional operator used?


Ans. It is used to test the relationship between two variables.

19. How do you represent increment operator?


Ans. Variable ++ or ++ variable.

20. How will be the number x = 998.286 displayed on the manilas?


Ans. printf (“ . 1. F”, X);

21. What is the use of a function conio.h?


Ans. It is a C header file used mostly by MS-DOS compilers to provide consolidated input/output.

22. What is the meaning of the symbol ‘∼’ in character set of C? 2015 (A)
Ans. Tilde which results in 1’s complement.

23. Find the value of a++ when a = 6 2015 (S)


Ans. 7

24. Mention the size of memory allocated for a character (char) type data in C-programming. 2016 (A)
Ans. One byte

25. Write C equivalent expression for the mathematical expression a2 + b2 . 2017(A)


Ans. Sqrt. ((a * a) + (b * b))

26. Write C equivalent expression for y = a2 + b2. 2016 (S)


Ans. ((a * a) + (b * b))

27. If a = 6 , and b = 9, what is the content of a after the execution of a + = b in C programing?


Ans. a = 15
12.12 Electronics

Section - B

I II. Two Mark Questions with Answers

1. Write the commonly used directive.


Ans. # include and # define

2. What does #include directive specifies?


Ans. It specifies that the standard header files and external filer can be included in the present program.

3. Briefly explain #define directive.


Ans. A preprocessor directive used to assign a constant value (like π) or an equation to a variable which is used in
program many times to avoided writing that again and again.

4. Write the steps involved in executing C program.


Ans. Writing a program including the required header files and external files if any compiling the program. Run the
program.

5. What are the different types of errors a programmer do?


Ans. Syntax error: Grammatical misstates.
Logical error: Error in using the logic which not gives.
Expected output Runt time error: which occure when we run the program due to ambiguity instruction written
in program.

6. For what purpose character sets are used?


Ans. It is used to form words, numbers and expressions.

7. Write the character sets of C.


Ans. Letters Digits
Special Characters Write space

8. Mention the different c tokens ?


Ans.
Keywords Strings
Identifiers Operators
Constants Special symbols

9. What is a character and string constant?


Ans. Xe constants written in single quotes are character constants.
Xe constants written in double quotes are string constants in string constant at the end of quotes system adds ‘10’
by default.

10. What are variables? Give example.


Ans. Variables are the quantity that change during the execution of program.
Example int a; a is the variable which hold integer data.
Int a = 10; a is the variable which holds the integer value 10.

11. Write the C equivalent expression for (2X + 1) (3Y + 2Z).


Ans. ((2* X) + 1)* ((3* Y) + (2 * Z))
C-Programming 12.13

12. Write any four arithmetic operators and its meaning.

Ans. + addition Subtraction % modulo division


*Multiplication / division

13. If a = 3, b = 5 and c = 6, find a && b|| c|| (!b) && (!c)


Ans. 3 & & 5|| 6|| (!5) && (!6)
1|| 1|| 0 && 0
1|| 1||0
1||1 = 0

14. What is data type condition? Explain.

Ans. Keyword Size in byte


1. Integer Int 2
2. Floating-point (Real) Float 4
3. Character Char 1
4. Double precision Double 8
5. Non specific Void -

15. Mention different conditional control statements?


Ans. If, if else, nested if, switch

16. Write the syntax of if statement?


Ans. If (condition)
{
Statement 1;
Statement 2;
}
17. Write the syntax of if else statement?
Ans. If (condition)
{
Statement 1;
}
else
{
Statement 2;
}
18. Write the syntax of do while statement
Ans. do
{
statement ;
} while (condition);

19. Write the syntax of for statement


Ans. for (intilization ; condition; increment/ decrement)
{
statement ;
}
12.14 Electronics

20. What is the use of break statement/ write its syntax.


Ans. Generally used in switch case to terminate the execution of particular case and to come out of switch loop.

21. Write any two types of errors that occur in C-program. 2016 (S)
Ans. Logical error
Run time error
Section - C

III. Three Mark Questions with Answers

1. Mention different sections appear is C programming.


Ans. Documentation section, link section, definition section, Global declaration section, Function section, subgroup
section.

2. Mention the different types of run time error.


Ans. • Divide by zero.
• Null printer assignment
• Data overflow

3. Write the different constants used in C program.


Ans.
C constant

Numeric constant Non-Numeric constant

Integer Floating Character String


constant point const. const. const.

4. Name the C operators.


Ans. Arithmetic Operator, Relational operator, Logical operator, Bitwise operator, Assignment operator, Conditional
operator, Increment & Decrement operator, Special operators.

5. Briefly explain bitwise operator.


Ans. These operator perform bit by bit operation.
& → Bitwise AND [Ampersand]
1 → Bitwise OR [Pipeline]
^ → XOR [caret]
∼ → 1’s complement [Tilde]
<< → Left shifting a bit [Double less than]
<< → Right shifting a bits [Double greater than]

6. Write the formatted and unformatted input and output function in C.

Ans. Type Input functions Output functions


Formated Scanf( ) printf ( )
Unformated getchar ( ) putchar ( )
gets ( ) gets ( )
C-Programming 12.15

7. How does monitor display 28.689 for 9 statement.


a. Printf (“%5 . 3f”, p) b. Printf (“%e”, y)
Ans. i. 28.689 ii. 2.8689e+01

8. Mention the different control statements.


Ans. The control statements are
• Conditional control statements • Iterative control statements
Conditional control statements: Here the condition is checked to make the decision. to execute a set of
statements or to skip them.
The conditional control statements are
• If statement • If-else statement
• nested-if statement • switch statement
Loop (Iterative ) control statements: In some program a group of statements should execute repeatedly
until specified condition is satisfied, which can be achieved by Iterative or loop control statements
The loop control statements are
• while loop • Do – while • for

9. Write the syntax of nested if statement.


Ans. if ( condition 1)
{
if (condition 2)
{
statement 1;
}
else
{
statement 2;
}
}
else if ( condition 3)
{
statement 3;
}
else
{
statement 4;
}
10. Briefly explain loop control statements.
Ans. Loop (Iterative ) control statements: In some program a group of statements should execute repeatedly until
specified condition is satisfied, which can be achieved by Iterative or loop control statements
The loop control statements are
• while loop
• Do – while
• for

11. Write any three features of C program. 2015 (A)


Ans. • Modularity → Makes program debugging, testing & maintenance easier.
• Portability → Program written in one computer can be run on another with little or no modification.
• Extendability → Can add the instructions in the middle after writing the program.
12.16 Electronics

12. Write the format of simple C program. 2015 (S)


Ans. # include < stdio.h > 
 Preprocessor directions
# include< conio.h > 
Void main ( )
{
Declaration part 
 function body
Executable part 
}
13. How do you represent.
(1) Logical AND (2) Logical OR
(3) Logical NOT operators in C Programming? 2017 (A)
Ans. • Logical AND & • Logical OR | • Logical NOT !

14. For a 8-bit computer, If A = 0000 0101 and B = 0011 0100. Compute the following bitwise operators.
(i) A & B (ii) A|B (iii) A ^ 8
Ans. A = 0000 0101
B = 0011 0100
A & B = 0000 0100
A | B = 0011 0101
A ^ B = 0011 0001
Section - D
IV. Five Mark Questions with Answers

1. Write the basic structure of C program.

Ans. # include < > 


# define  → Preprocessor directive

void main ( ) → main function
{ → start of program

Declaration port  → Program statements

} → end of program
Subroutine section
{ → uses defined function
}

2. Write the rules for forming identifier name.


Ans. • The first character must be an alphabet or an underscore.
• All succeding character must be either letters or digits.
• Only first 31 character. are considered.
• Keyword should not be used as identifier.
• No special character. are considered except ‘ ’(underscrore)
• No two successive underscores are allowed.
• Must not contain white space.
C-Programming 12.17

3. Write the rules for forming variable name.


Ans. Variables: The quantity that change during the execution of program.
• They represent a particular memory location where data be scored.
• There is no limit on number of character is variable name.
• All variables must be declared before they used in C program.
• Key words should not be used as variable name.
Syntax for declaration: Datatype variablename;
Syntax for assigning value: Variablename = value;

4. If a = 25 and b = 5, find
(a) a + b (b) a – b (c) a * b (d) a / b (e) a%b (f) –a % b (g) a % –b
Ans. a. 31 b. 19 c. 150 d. 4 e. 1 f. –1 g. 1

5. Write C program to accept the three integers & print the largest among them. 2015 (A)
Ans. # include < stdio. h >
# include < conio. h >
viod main ()
{
int x,y,z;
print f (“ enter the value of x,y,z\ n”);
scanf (“ %d%d%d”, & x, &y, &z);
if (x >y )
{
if (x > Z)
{
print (“ x is largest \ n”);
}
else
{
}print (“ Z is largest \ m”);
else if (y > Z)
{
print (“ y is largest \n”);
}
else
{
printf (“ Z is largest \n”);
}
}
6. Write a C program to accept two numbers & Compute their sum & average. 2015 (S)
Ans. # include < stdio. h >
# include < conio. h >
viod main ()
{
int a, b, c;
printf (“ enter any 2 values to find sum & average\n”);
scanf (“%d%d”, &a, &b);
c = a + b;
printf (“the sum is %d”, c);
c = c/2;
printf (“the average is %d”, c);
}
12.18 Electronics

7. Write a C program to print the sum of first n integers. 2016 (A)


Ans. # include < stdio. h >
# include < conio. h >
viod main ()
{
int a = 0, count;
printf (“ enter the count \n”);
scanf (“%d”, & count);
while (count! = 0)
{
a = a + count;
count – – ;
}
printf (“the sum of integers is %d”, a);
}
8. Write a C program to accept three integers & find their sum & average. Find the sum & average of 5, 6 & 7.
2017 (A)
Ans. # include < stdio. h >
# include < conio. h >
viod main ()
{
int a, b, c, d;
printf (“ enter any 3 values to find sum & average\n”);
scanf (“%d%d%d”, &a, &b, &c);
d = a + b + c;
printf (“The sum is %d”, d);
d = d/3;
printf (“The average is %d”, d);
}
enter any 3 values to find sum & average
567
The sum is 18
The average is 6
9. Explain the features of C-programming language. 2016 (S)
Ans. Features of C:
• Suitable for both system software & application programmes
• highly portable • Efficient & fast
• Easy debugging & testing • Self extending ability
• Any complex program can be written
10. Write a C program to accept the radius of a circle and compute its area and perimeter.
Ans. #include <stdio.h>
#include <conio.h>
vaid mian ()
{
Int r;
float A, P; 1
print (“enter the radius to find area & perimeterts”)
scarf (“ %d”, & r);
A = 3.14*r*r;
P = 2*3.14*r;
printf (“Area of circle in % f”, A);
printf(“Perimeter of circle in %f”, P);
}


You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy