This document provides an overview of operators, loops, and input/output functions in the C programming language. It begins by explaining different types of operators in C like relational, logical, unary, binary, ternary, and increment/decrement operators. Examples of using logical, unary, binary, and ternary operators are given. The document then discusses loops in C, specifically for loops. It provides examples of using loops to accept input until a certain condition is met. The key topics covered in 3 sentences or less are: types of operators in C, examples of using various operators, an overview of loops in C including for loops, and examples of using loops to accept input until a condition is met.
The aptitude test consisted tricky questions on core subjects of CSE like C , C++, Java ,Data Structures, Database, Computer Networks, Theory of Computation.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
The French Revolution Class 9 Study Material pdf free download
C programming session 02
1. Slide 1 of 50Ver. 1.0
Programming in C
In this session, you will learn to:
Work with operators
Use loops
Use formatted input-output functions
Objectives
2. Slide 2 of 50Ver. 1.0
Programming in C
Working with Operators
An operator:
Is a symbol used to command the computer to do
mathematical or logical manipulations.
Operates on data and variables.
C has a rich set of operators, which can be classified into
following various categories:
Relational operators
Logical operators
Unary operators
Binary operators
Ternary operator
Compound assignment operators
Increment/Decrement operators
3. Slide 3 of 50Ver. 1.0
Programming in C
Logical Operators
Notations for logical operators in C are:
Operator Notation
OR | |
AND &&
NOT !
Operator precedence:
NOT (!) is evaluated before AND (&&), which is evaluated
before OR (||). Brackets () are used to change this order.
4. Slide 4 of 50Ver. 1.0
Programming in C
Practice: 2.1
Write a function that accepts either y or n only as input. For
any other character input, an appropriate error message
should be displayed and the input is accepted again.
5. Slide 5 of 50Ver. 1.0
Programming in C
Practice: 2.1 (Contd.)
Solution:
#include<stdio.h>
main()
{ char yn;
do {
puts(“Enter y/n (Yes/No)”);
yn=getchar ();
fflush (stdin);
if(yn!=’y’ && yn!=’n’)
puts(“Invalid input”);
}
while(yn!=’y’ && yn!=’n’);
}
6. Slide 6 of 50Ver. 1.0
Programming in C
Unary Operators
Unary Operators:
Operates on a single operand.
Prefixed to an integer constant.
Tells the compiler to reverse the sign by subtracting the value
(or variable) from zero.
Has the same effect as the – sign, which is used to indicate a
number less than zero, for example -12.
7. Slide 7 of 50Ver. 1.0
Programming in C
Practice: 2.2
Which of the following are valid?
1. valuea=-12; /* valuea is int* /
2. valuea = - valueb – 12 /* valuea and valueb
both are int */
8. Slide 8 of 50Ver. 1.0
Programming in C
Practice: 2.2 (Contd.)
Solution:
1. Valid
2. Valid
9. Slide 9 of 50Ver. 1.0
Programming in C
Binary Operators
Binary Operators:
Operate on two operands.
Are as follows:
+ (add)
- (subtract)
* (multiply)
/ (divide)
% (modulo)
10. Slide 10 of 50Ver. 1.0
Programming in C
Practice: 2.3
In the following set of statements:
char ch;
ch=’S’;
ch=ch+’a’-‘A’; /*statement A*/
ch=ch+’A’-‘a’; /*statement B*/
What will be the value of ch after:
1. Statement A is executed?
2. Statement B is executed?
11. Slide 11 of 50Ver. 1.0
Programming in C
Practice: 2.3 (Contd.)
Solution:
1. ch is equal to s. Note that ‘a’-‘A’ gives 32 after statement 1 is
executed.
2. ch is back to S after statement 2 is executed.
12. Slide 12 of 50Ver. 1.0
Programming in C
Binary Operators (Contd.)
There are some set or rules, if followed, would prevent
unexpected results, at the time of execution of programs:
Any operand of type char is converted to int.
All floats are converted to doubles.
If either operand is double, the other is converted to a
double, giving a double result.
13. Slide 13 of 50Ver. 1.0
Programming in C
Practice: 2.4
1. In which of the following assignments is there no loss of
data? (i is an int, f a float, and d a double)
i=d;
d=f;
f=d;
i=f+d;
d=i+f;
1. Is type casting necessary in the following example?
int i,j;
float f;
double d;
d=f+(float) i + j;
14. Slide 14 of 50Ver. 1.0
Programming in C
Solution:
1. a. Loss of data. int set equal to a double.
b. No loss of data. double set equal to a float.
c. Loss of data. float set equal to a double.
d. Loss of data. Right-hand result is a double while left-hand
side is just an int.
e. No loss of data. Right-hand result is a double and
left-hand side is also a double.
2. Not necessary. The ints will automatically be converted to
doubles (following the conversion of the float to a double).
Practice: 2.4 (Contd.)
15. Slide 15 of 50Ver. 1.0
Programming in C
Ternary Operator
Ternary Operator:
Is a shorthand method for writing if.else conditional
construct.
Helps in reducing lines of code.
Has the following form for the expression using the ternary
operator:
(test-expression) ? T-expression : F-expression;
16. Slide 16 of 50Ver. 1.0
Programming in C
Ternary Operator (Contd.)
Consider the following example:
if(condition)
{ Statements if condition is true }
else
{ Statements if condition is false }
Can be rewritten using the shorthand operator as follows:
larger_of_the_two = ( x > y ) ? x : y;
17. Slide 17 of 50Ver. 1.0
Programming in C
Practice: 2.5
1. State whether True or False:
In the general form of an expression that uses a ternary operator,
the test expression will be checked. If it is true, the T-expression
will be evaluated, otherwise the F-expression will be evaluated.
2. What will the following statement do?
quotient = (b==0) ? 0 : (a/b); /*a, b, and
quotient are ints*/
3. Can the preceding statement be written as follows?
quotient = (b) ? (a/b) : 0;
4. What will the following statement do?
always_negative = (j>0) ? j : (-j);
18. Slide 18 of 50Ver. 1.0
Programming in C
Solution:
1. True.
2. If b is non-zero, it will determine the quotient of a and b. If b
equals zero, quotient is set to 0.
3. Yes. Note that if b is non-zero, the test expression (b)
evaluates to true and hence quotient is set to (a/b).
4. The variable always_negative will always take on a non-
negative value, i.e. it will be assigned the absolute value of j.
The name of the variable always_negative is just a red
herring. Remember that self-documenting variable names will
help in writing programs that are readable. Note the unary
operator (-j).
Practice: 2.5 (Contd.)
19. Slide 19 of 50Ver. 1.0
Programming in C
Compound Assignment Operators
Compound Assignment Operators:
Are useful especially when long variable names are used.
Has the following general form:
left-value op= right-expression;
Here op can be either + (add), - (subtract, * (multiply), /
(divide), and % (modulo).
Consider the following example:
a_very_long_identifier=a_very_long_identifier + 2;
It can be written as:
a_very_long_identifier += 2;
20. Slide 20 of 50Ver. 1.0
Programming in C
Increment / Decrement Operators
Increment / Decrement Operators:
Are used to increase or decrease the value of a variable by 1.
Has the following two forms:
The ++ (two plus symbols without a space), called the increment
operator while that in ++ before the variable is called the pre
increment operator and after the variable is called the post
increment operator.
The -- (two minus symbols without a space), called the decrement
operator while that in ++ before the variable is called the pre
decrement operator and after the variable is called the post
increment operator.
21. Slide 21 of 50Ver. 1.0
Programming in C
Increment / Decrement Operators (Contd.)
Consider the following code snippet:
total = sum++; /* statement A */
total = ++sum; /* statement B */
The first statement is equivalent to:
total = sum; sum = sum + 1;
While the second is the same as:
sum = sum + 1; total = sum;
22. Slide 22 of 50Ver. 1.0
Programming in C
Practice: 2.6
1. Consider the following code snippet:
int sum = 3, total = 5;
total = sum++;
total = ++sum; /*statement A */
total = sum—
total = --sum; /*statement B */
What will be the values of total and sum after:
a. statement A is executed?
b. statement B is executed?
23. Slide 23 of 50Ver. 1.0
Programming in C
Practice: 2.6 (Contd.)
2. State whether True or False:
The following statement:
for(i = 0; i< 100); i = i + 1)
{
Some statements
}
can be written as:
for (i = 0; i < 100; i++)
{
Some statements
}
24. Slide 24 of 50Ver. 1.0
Programming in C
Practice: 2.6 (Contd.)
3. State whether True or False:
The for statement in #2 can also be written as:
fori = 0; i < 100; ++i)/*Note: ++i and not i++*/
{
Some statements
}
4. Write a program, which reads in a year and reports on
whether it is a leap year or not (centuries should also be
considered).
25. Slide 25 of 50Ver. 1.0
Programming in C
Solution:
1. total=5, sum=5
total=3, sum=3
quite a complicated way of reducing total by 2.
2. True. i+1 is equivalent to i++.
3. True. i+1 is equivalent to 1+i.
4.
Practice: 2.6 (Contd.)
Microsoft Word
Document
26. Slide 26 of 50Ver. 1.0
Programming in C
Using Loops
The while and do…while looping constructs are generally
used in situations where the number of execution of the loop
is not known.
The for loop construct is used when the number of
execution of the loop is known.
27. Slide 27 of 50Ver. 1.0
Programming in C
The for Loop Construct
The for loop construct:
Has three components in the loop control:
Initialization
Condition
Re-initialization (increment/decrement)
Has the following sequence of execution:
Initialization
Evaluation of loop condition
Body of loop
Re-initialization
28. Slide 28 of 50Ver. 1.0
Programming in C
The sequence of execution of a complete for loop construct
is shown in the following figure.
TRUE
INITIALIZATION
EVALUATE
CONDITION
BODY OF LOOP
REINITIALIZATION
FALSE
The for Loop Construct (Contd.)
29. Slide 29 of 50Ver. 1.0
Programming in C
In a for loop construct:
Multiple initializations and/or multiple re- initializations, are
separated by commas.
Multiple conditions are specified using logical operators.
The for Loop Construct (Contd.)
30. Slide 30 of 50Ver. 1.0
Programming in C
Practice: 2.7
1. Write a function to accept twenty characters from the
character set, and to display whether the number of lower-
case characters is greater than, less than, or equal to
number of upper-case characters. Display an error
message if the input is not an alphabet.
2. Modify the function to accept characters endlessly until the
character ! is input from keyboard.
31. Slide 31 of 50Ver. 1.0
Programming in C
Solution:
1.
2.
Practice: 2.7 (Contd.)
Microsoft Office
Word 97 - 2003 Document
Microsoft Office
Word 97 - 2003 Document
32. Slide 32 of 50Ver. 1.0
Programming in C
Controlling the Loop Execution
At times there is a need to exit from a loop before the loop
condition is re-evaluated after iteration.
To exit from loop control, break and continue statements
are used.
33. Slide 33 of 50Ver. 1.0
Programming in C
Practice: 2.8
Write a function, which accepts numbers until 0 is entered
or 10 numbers have been accepted. The function prints the
total number of entries, the number of positive entries, and
the sum of all the positive numbers.
34. Slide 34 of 50Ver. 1.0
Programming in C
Practice: 2.8 (Contd.)
Solution:
Microsoft Office
Word 97 - 2003 Document
35. Slide 35 of 50Ver. 1.0
Programming in C
Using Formatted Input-Output Functions
C provides the following functions for formatted input-output:
printf()
scanf()
36. Slide 36 of 50Ver. 1.0
Programming in C
Formatted Output
Syntax of the formatted output function printf() is:
printf (format, data1, data 2, ….);
Consider the following example:
printf(“%c”, inp);
The character specified after % is called a conversion
character.
The conversion character allows one data type to be
converted to another type and printed.
37. Slide 37 of 50Ver. 1.0
Programming in C
Formatted Output (Contd.)
The conversion characters and their meanings are shown in
the following table.
Character Meaning
d the data is converted to decimal (integer)
c the data is taken as a character
s the data is a string and characters from
the string are printed until a NULL
character is reached
f the data is output as a double or float with
a default precision to 6
38. Slide 38 of 50Ver. 1.0
Programming in C
Practice: 2.9
What is the output of the statement:
printf(“Integer is: %d; Alphabet is: %cn”,
inum, inp);
where inum contains 15 and inp contains Z.
39. Slide 39 of 50Ver. 1.0
Programming in C
Practice: 2.9 (Contd.)
Solution:
Integer is: 15; Alphabet is Z.
40. Slide 40 of 50Ver. 1.0
Programming in C
Formatted Input
The scanf() function is used for formatted input.
The syntax for the scanf() functions is as follows:
scanf (format, data1, data2……);
Here
format - The format-specification string
data1, data2 - Data names where the input data
is to be stored as per the
format-specification string
41. Slide 41 of 50Ver. 1.0
Programming in C
Formatted Input (Contd.)
The format-specification string in scanf() consists of:
Blanks, tabs, (also called white space characters).
New line which are ignored.
Conversion consisting of %, an optional number specification
specifying the width and a conversion character.
While accepting strings using scanf(), a space is
considered as a string terminator.
42. Slide 42 of 50Ver. 1.0
Programming in C
Practice: 2.10
Write a function to accept and display the element number
and the weight of a Proton. The element number is an
integer and weight is fractional.
43. Slide 43 of 50Ver. 1.0
Programming in C
Practice: 2.10 (Contd.)
Solution:
#include<stdio.h>
main()
{
int e_num;
float e_wt;
printf(“Enter the Element No. and Weight of a
Protonn”);
scanf(“%d %f”, &e_num, &e_wt);
fflush(stdin);
printf(“The Element No. is: “, e_num);
printf(“The weight of a Proton is: %fn“,
e_wt);
}
44. Slide 44 of 50Ver. 1.0
Programming in C
Practice: 2.11
Write a function to input a string of continuous characters
with no white space as part of the input. The function should
assign the input to variables of the types specified in the
following table.
The function should also print out each of the assigned data
items in separate lines.
Position of character from
start of string
Number of
characters
Type of argument to
assign
1 2 int
3 4 float
7 2 char (string)
9 3 int
45. Slide 45 of 50Ver. 1.0
Programming in C
Practice: 2.11
Solution:
#include<stdio.h>
main()
{
int i,j;
char str[3];
float fnum;
printf(“Enter a string of 11 chrsn”); /*why
11: because 11 is the total length of */
/*input.*/
scanf(“%2d %4f %2s %3d”,&i, &fnum, str, &j);
fflush(stdin);
printf(“%2dn %4fn %2sn %3dn”, i, fnum,
str, j);
}
46. Slide 46 of 50Ver. 1.0
Programming in C
Summary
In this session, you learned that:
An operator is a symbol that is used to command the computer
to do mathematical or logical manipulations.
The operators in C language are classified into the following
categories:
Logical operators
Unary operators
Binary operators
Ternary operator
Compound assignment operators
Increment/Decrement operators
47. Slide 47 of 50Ver. 1.0
Programming in C
Summary (Contd.)
The logical operators of C and their notations are as follows.
The unary operator prefixed to an integer constant or variable
tells the compiler to reverse the sign by subtracting the value
or variable from zero.
Binary operators in C language are + (add), - (subtract), *
(multiply), / (divide), and % (modulo).
Ternary operator offers a shorthand way of writing the
commonly used if…else construct.
Operator Notation
OR ||
AND &&
NOT !
48. Slide 48 of 50Ver. 1.0
Programming in C
Summary (Contd.)
The syntax for using the ternary operator is:
(test-expression) ? T-expression : F-expression;
Compound assignment operators simplify the statements.
Increment / Decrement operators are used to
increment/decrement a variable by 1.
A for loop is used when the number of execution of the loop is
known.
The components of a for loop construct are:
initialization
loop condition
reinitialization (increment/decrement)
49. Slide 49 of 50Ver. 1.0
Programming in C
Summary (Contd.)
The sequence of execution of a complete for loop is:
initialization
evaluation of the loop condition
the body of the loop
reinitialization
The break and continue statements are used to exit from
loop control.
The break statement is used to exit from all loop constructs
(while, do...while, and for) and switch...case
statements.
The continue statement is used to skip all subsequent
instructions and brings the control back to the loop.
The function printf() is used for formatted output to
standard output based on a format specification.
50. Slide 50 of 50Ver. 1.0
Programming in C
Summary (Contd.)
The syntax of the function printf() is:
printf(format, datal, data 2,,..);
The function scanf() is used for formatted input from
standard input and provides many of the conversion facilities of
the function printf().
The syntax of the function scanf() is:
scanf (format, datal, data2, ...);
Editor's Notes
Begin the session by explaining the objectives of the session.
Tell the students that they cannot create a useful programs without using the operators. A simple program such as adding two variables and showing the result needs the use of variables.
Operator precedence is very important in a program. If the operator precedence is not considered then the program might produce an unexpected result. Give an example, which produces a result different from the expected result because of incorrect operator precedence.
Use Slide 4 to test the student’s understanding on logical operators.
Use Slide 7 to test the student’s understanding on unary operators.
Use Slide 10 to test the student’s understanding on binary operators.
Use this slide to test the student’s understanding on binary operators.
Use this slide to test the student’s understanding on ternary operators.
Use this slide to test the student’s understanding on increment/decrement operators.
Explain definite and indefinite loops. Give some examples, which distinguish between definite and indefinite loops.
The for loop consists of three parts : Initialization Condition Re-initialization (increment/decrement) In a for loop, after initialization, the condition is first checked. If the condition is valid, the body of the for loop is executed. For each iteration, re-initialization is done before the condition is checked again. Any or all of these parts may be left out of the construct. For example : for ( ; ; ) { } is an infinite loop (as there is no condition).
Use this slide to test the student’s understanding on loops.
Use this slide to test the student’s understanding on controlling the loop execution.
When used with strings, the format string could be quite confusing. The statement: printf ( “%15.5s”, string) prints the first 5 characters of the string right-justified in 15 spaces. When used with floats, it represents the precision required.
Use this slide to test the student’s understanding on formatted output.
Use this slide to test the student’s understanding on formatted input.
Use this slide to test the student’s understanding on formatted input-output.
The output buffer is flushed only if it is full, or if the string to be printed contains a newline character at the end or if it is explicitly flushed using fflush () . The last option is used if the string does not contain a new line character. The string might not be displayed at the right place at the right time otherwise.
Use this and the next 4 slides to summarize this session.