The document is a chapter from an introductory C programming textbook. It covers basic C concepts like comments, variables, data types, functions, input/output, arithmetic operators, and conditional statements. It includes examples of simple C programs that print text, get user input, perform addition, and test for equality/relations between numbers. The chapter lays out fundamental building blocks to prepare the reader for more advanced C programming concepts covered later.
This document provides an overview of introductory concepts in C programming, including simple programs to print text and perform arithmetic. It covers basic syntax like comments, functions, variables, data types, operators, input/output, and conditional statements. Memory concepts are introduced, as well as the preprocessor, standard libraries, and control flow structures like if/else. Examples are provided to demonstrate printing text, taking user input, performing calculations, and making decisions based on relational comparisons.
The document is an outline from a textbook on C programming. It covers basic concepts like simple programs to print text and perform math operations, use of variables and data types, memory concepts, decision making using if statements and relational operators. It includes examples of simple C programs and explanations of the core components like main function, comments, preprocessor directives, functions etc.
This document introduces decision making in C programming using relational and equality operators. It defines operators like ==, !=, <, >, <=, >= and shows how they are used in if statements to check conditions. Examples show how to input two numbers, compare them using relations and print the results. The document also outlines the typical structure of a C program that performs input, decision making and output.
This document provides an overview of topics covered in a C++ programming course, including:
- Introduction to C++ language fundamentals like data types, variables, operators, control structures, functions, and classes
- Memory concepts, arithmetic, decision making, and algorithms
- Structured and object-oriented programming principles
- The basics of the C++ environment like compilers, linkers, and input/output streams
- Common library functions and concepts like headers, prototypes, and enumerations
The document serves as an introductory reference for anyone learning C++ or wanting to understand the basic building blocks of the language.
This document provides an introduction to basic C programming concepts like variables, data types, functions, comments, and input/output. It explains a simple program that prints text and another that adds two integers by initializing variables, taking input, performing calculations, and printing output. Key concepts covered include data types, variable declaration, input/output functions like printf and scanf, and the structure of a basic C program.
The document provides an introduction to C programming, covering topics such as what a program is, programming languages, the history of C, and the development stages of a C program. It discusses the key components of a C program including preprocessing directives, the main function, and program layout. Examples are provided to illustrate C code structure and the use of variables, keywords, operators, input/output functions, and formatting output with printf.
This document provides an outline and explanation of key concepts in the first two chapters of an introduction to C programming book. It introduces simple C programs that print text and perform arithmetic. It also covers basic programming concepts like functions, variables, data types, input/output, operators, and conditional statements.
This document provides an outline and explanation of key concepts in the first two chapters of an introduction to C programming book. It introduces simple C programs that print text and perform arithmetic. It also covers basic programming concepts like variables, data types, input/output functions, arithmetic operators, and conditional statements.
Lecture#2 Computer languages computer system and Programming EC-105NUST Stuff
油
The document discusses three types of computer languages: machine language, assembly language, and high-level languages. Machine language is directly understood by computers using binary, while assembly language uses abbreviations and high-level languages resemble English. It also introduces C++ programming concepts like variables, data types, input/output streams, arithmetic operators, and conditional statements. Sample programs are provided to demonstrate printing text, getting user input, performing calculations, and making decisions.
C++ is an object-oriented programming language that features better memory management using dynamic allocation, support for OOP concepts like inheritance and polymorphism, portability across operating systems, and simple syntax similar to C. A basic "Hello World" C++ program includes header files, namespaces, main and return functions, and output statements. Comments are used to explain code and provide information to other programmers. Key elements of C++ include variables to store values, basic and user-defined data types, operators to perform actions, and control flow statements.
This document discusses program structure, data types, variables, operators, input/output functions, and debugging in C programming. It provides sample code for a program that calculates the sum of two integers entered by the user. The key steps are: 1) declaring integer variables for the two numbers and their sum, 2) using printf and scanf functions to input the numbers and output the result, and 3) returning 0 at the end of the main function. The document also covers preprocessor directives, data types, naming conventions, arithmetic and logical operators, and debugging techniques.
The document provides an introduction to C++ programming including definitions of key concepts like compilers, variables, data types, operators, and common errors. It discusses rules for naming variables in C++ and different types of errors like syntax errors, semantic errors, type errors, runtime errors, and logical errors. Code snippets demonstrating these concepts are provided along with examples of errors. Best practices for programming and naming conventions are also outlined.
The document discusses header files and C preprocessors. It defines header files as files containing C declarations and macro definitions that can be shared between source files by including them using the #include directive. Common header files like stdio.h, conio.h, and math.h are given as examples. Preprocessors are described as a macro processor that transforms the program before compilation by handling preprocessor directives like #define. It allows defining macros which are abbreviations for longer code constructs. The document also provides examples of preprocessor directives like #include and #define.
C is a programming language developed in 1972 by Dennis Ritchie at Bell Labs. It is a structured programming language that is highly portable and supports functions. A C program consists of functions, with a main function that is the program entry point. Input/output in C uses predefined functions like printf() and scanf(). A C program is compiled into an executable file that can run on many machine architectures. The document then discusses C program structure, data types, libraries, variables, keywords, operators, and control flow statements like if/else, switch, while, do-while and for loops.
This document discusses functions and storage classes in C programming. It defines a function and explains the need for functions. The key components of a function are defined as the function prototype, function definition, function parameters, and function call. The document compares call by value and call by reference parameter passing. It also discusses recursion, storage classes like local and global variables, and scope. Functions can return values, manipulate parameters, or be strictly procedural. Arrays and strings can be passed to functions.
18CSS101J PROGRAMMING FOR PROBLEM SOLVINGGOWSIKRAJAP
油
The document discusses various operators, control statements, and arrays in C programming. It begins by explaining operator precedence and types of operators such as relational, logical, increment, assignment etc. It then covers control statements including if-else, switch case, for, while, do-while loops. It also discusses goto, break and continue statements. Finally, it describes arrays including initialization, declaration, accessing elements and array operations. The document provides examples to explain the concepts in detail.
This document discusses functions in C programming. It covers key concepts about functions including:
- Functions allow programmers to break programs into modular, reusable components.
- Functions are defined with a return type, name, and parameters. They can contain local variable declarations.
- Functions are called by name and passing arguments. They can return values.
- Function prototypes declare the name, parameters, and return type before the function is used.
- The document provides examples of defining, calling, and prototyping functions. It also covers scope, storage classes, and other aspects of working with functions in C.
1.History of C Language, Structure of a C program, Statements, Basic Data Types, Variables &Constants, Input & Output statements, Operators and Precedence, Expressions, Simple C programs.
This document provides an introduction to algorithms and imperative programming in C language. It defines an algorithm as a set of instructions to perform a task and discusses the differences between algorithms and programs. It also describes flowcharts for representing algorithms and discusses various programming elements in C like variables, data types, operators, functions, and comments. The document concludes with an example of a simple "Hello World" C program.
Introduction of function in c programming.pptxabhajgude
油
In C programming, a function is a block of code designed to perform a specific task. Functions help to organize code into manageable and reusable segments, making the program easier to understand, maintain, and debug. Functions allow you to break down a complex program into smaller, simpler tasks, each of which can be tested and executed independently.
This document summarizes key concepts from an introduction to C++ programming chapter, including:
- The main parts of a C++ program are comments, preprocessor directives, the main() function, and statements.
- Variables are used to store and manipulate data in a program. Variables are declared with a name and type before use.
- Arithmetic operators allow performing calculations in C++ programs. Expressions follow order of operations rules.
- Input and output streams allow getting user input and displaying output to the screen.
This document provides an introduction to the C programming language. It discusses fundamental C elements like data types, variables, constants, operators, and input/output functions. It explains how a basic C program is structured and compiled. Examples are provided to demonstrate simple C statements, arithmetic expressions, and how to write and run a first program that prints text. The key topics covered include basic syntax, program structure, data types, identifiers, operators, and input/output functions like printf() and scanf().
This document provides an overview of the C programming language. It covers C fundamentals like data types and operators. It also discusses various control structures like decision making (if-else), loops (for, while, do-while), case control (switch) and functions. Additionally, it explains input/output operations, arrays and string handling in C. The document is presented as lecture notes with sections and subsections on different C concepts along with examples.
Programming Fundamentals Functions in C and typesimtiazalijoono
油
Programming Fundamentals
Functions in C
Lecture Outline
Functions
Function declaration
Function call
Function definition
Passing arguments to function
1) Passing constants
2) Passing variables
Pass by value
Returning values from functions
Preprocessor directives
Local and external variables
This document provides an introduction to basic elements of C++ programming, including:
- The structure of a basic C++ program with an example main function.
- Common data types like integers, floating point numbers, characters, and strings.
- Arithmetic operators and precedence.
- Expressions, input/output, and type casting.
- Variables, memory allocation, and initializing variables.
- Control structures like increment/decrement operators.
- Program style guidelines including comments and formatting.
The document discusses various topics related to computer networks and cyber security. It begins by defining what a network is and describing the evolution and types of networks, including personal area networks (PAN), local area networks (LAN), metropolitan area networks (MAN), and wide area networks (WAN). It then discusses common network devices like modems, network interface cards, switches, routers, and gateways. The document also covers network protocols, the world wide web, internet addresses (URLs), email, cryptocurrencies, cyber security concepts like confidentiality and integrity, common cyber attacks, types of malware, and India's Information Technology Act of 2000.
This document appears to be a resume or CV listing the educational and professional experience of an individual. It includes the person's name, dates of study or employment at various institutions including the Department of Economics at PU Sangnawna (L) Nen from 1982-2022, the Education Department at NEHU from 1982-1984, and events they participated in such as the NAAC Grade 'A' Celebration Day in April 2022 and receiving the Principal's Award at an Annual Day.
Lecture#2 Computer languages computer system and Programming EC-105NUST Stuff
油
The document discusses three types of computer languages: machine language, assembly language, and high-level languages. Machine language is directly understood by computers using binary, while assembly language uses abbreviations and high-level languages resemble English. It also introduces C++ programming concepts like variables, data types, input/output streams, arithmetic operators, and conditional statements. Sample programs are provided to demonstrate printing text, getting user input, performing calculations, and making decisions.
C++ is an object-oriented programming language that features better memory management using dynamic allocation, support for OOP concepts like inheritance and polymorphism, portability across operating systems, and simple syntax similar to C. A basic "Hello World" C++ program includes header files, namespaces, main and return functions, and output statements. Comments are used to explain code and provide information to other programmers. Key elements of C++ include variables to store values, basic and user-defined data types, operators to perform actions, and control flow statements.
This document discusses program structure, data types, variables, operators, input/output functions, and debugging in C programming. It provides sample code for a program that calculates the sum of two integers entered by the user. The key steps are: 1) declaring integer variables for the two numbers and their sum, 2) using printf and scanf functions to input the numbers and output the result, and 3) returning 0 at the end of the main function. The document also covers preprocessor directives, data types, naming conventions, arithmetic and logical operators, and debugging techniques.
The document provides an introduction to C++ programming including definitions of key concepts like compilers, variables, data types, operators, and common errors. It discusses rules for naming variables in C++ and different types of errors like syntax errors, semantic errors, type errors, runtime errors, and logical errors. Code snippets demonstrating these concepts are provided along with examples of errors. Best practices for programming and naming conventions are also outlined.
The document discusses header files and C preprocessors. It defines header files as files containing C declarations and macro definitions that can be shared between source files by including them using the #include directive. Common header files like stdio.h, conio.h, and math.h are given as examples. Preprocessors are described as a macro processor that transforms the program before compilation by handling preprocessor directives like #define. It allows defining macros which are abbreviations for longer code constructs. The document also provides examples of preprocessor directives like #include and #define.
C is a programming language developed in 1972 by Dennis Ritchie at Bell Labs. It is a structured programming language that is highly portable and supports functions. A C program consists of functions, with a main function that is the program entry point. Input/output in C uses predefined functions like printf() and scanf(). A C program is compiled into an executable file that can run on many machine architectures. The document then discusses C program structure, data types, libraries, variables, keywords, operators, and control flow statements like if/else, switch, while, do-while and for loops.
This document discusses functions and storage classes in C programming. It defines a function and explains the need for functions. The key components of a function are defined as the function prototype, function definition, function parameters, and function call. The document compares call by value and call by reference parameter passing. It also discusses recursion, storage classes like local and global variables, and scope. Functions can return values, manipulate parameters, or be strictly procedural. Arrays and strings can be passed to functions.
18CSS101J PROGRAMMING FOR PROBLEM SOLVINGGOWSIKRAJAP
油
The document discusses various operators, control statements, and arrays in C programming. It begins by explaining operator precedence and types of operators such as relational, logical, increment, assignment etc. It then covers control statements including if-else, switch case, for, while, do-while loops. It also discusses goto, break and continue statements. Finally, it describes arrays including initialization, declaration, accessing elements and array operations. The document provides examples to explain the concepts in detail.
This document discusses functions in C programming. It covers key concepts about functions including:
- Functions allow programmers to break programs into modular, reusable components.
- Functions are defined with a return type, name, and parameters. They can contain local variable declarations.
- Functions are called by name and passing arguments. They can return values.
- Function prototypes declare the name, parameters, and return type before the function is used.
- The document provides examples of defining, calling, and prototyping functions. It also covers scope, storage classes, and other aspects of working with functions in C.
1.History of C Language, Structure of a C program, Statements, Basic Data Types, Variables &Constants, Input & Output statements, Operators and Precedence, Expressions, Simple C programs.
This document provides an introduction to algorithms and imperative programming in C language. It defines an algorithm as a set of instructions to perform a task and discusses the differences between algorithms and programs. It also describes flowcharts for representing algorithms and discusses various programming elements in C like variables, data types, operators, functions, and comments. The document concludes with an example of a simple "Hello World" C program.
Introduction of function in c programming.pptxabhajgude
油
In C programming, a function is a block of code designed to perform a specific task. Functions help to organize code into manageable and reusable segments, making the program easier to understand, maintain, and debug. Functions allow you to break down a complex program into smaller, simpler tasks, each of which can be tested and executed independently.
This document summarizes key concepts from an introduction to C++ programming chapter, including:
- The main parts of a C++ program are comments, preprocessor directives, the main() function, and statements.
- Variables are used to store and manipulate data in a program. Variables are declared with a name and type before use.
- Arithmetic operators allow performing calculations in C++ programs. Expressions follow order of operations rules.
- Input and output streams allow getting user input and displaying output to the screen.
This document provides an introduction to the C programming language. It discusses fundamental C elements like data types, variables, constants, operators, and input/output functions. It explains how a basic C program is structured and compiled. Examples are provided to demonstrate simple C statements, arithmetic expressions, and how to write and run a first program that prints text. The key topics covered include basic syntax, program structure, data types, identifiers, operators, and input/output functions like printf() and scanf().
This document provides an overview of the C programming language. It covers C fundamentals like data types and operators. It also discusses various control structures like decision making (if-else), loops (for, while, do-while), case control (switch) and functions. Additionally, it explains input/output operations, arrays and string handling in C. The document is presented as lecture notes with sections and subsections on different C concepts along with examples.
Programming Fundamentals Functions in C and typesimtiazalijoono
油
Programming Fundamentals
Functions in C
Lecture Outline
Functions
Function declaration
Function call
Function definition
Passing arguments to function
1) Passing constants
2) Passing variables
Pass by value
Returning values from functions
Preprocessor directives
Local and external variables
This document provides an introduction to basic elements of C++ programming, including:
- The structure of a basic C++ program with an example main function.
- Common data types like integers, floating point numbers, characters, and strings.
- Arithmetic operators and precedence.
- Expressions, input/output, and type casting.
- Variables, memory allocation, and initializing variables.
- Control structures like increment/decrement operators.
- Program style guidelines including comments and formatting.
The document discusses various topics related to computer networks and cyber security. It begins by defining what a network is and describing the evolution and types of networks, including personal area networks (PAN), local area networks (LAN), metropolitan area networks (MAN), and wide area networks (WAN). It then discusses common network devices like modems, network interface cards, switches, routers, and gateways. The document also covers network protocols, the world wide web, internet addresses (URLs), email, cryptocurrencies, cyber security concepts like confidentiality and integrity, common cyber attacks, types of malware, and India's Information Technology Act of 2000.
This document appears to be a resume or CV listing the educational and professional experience of an individual. It includes the person's name, dates of study or employment at various institutions including the Department of Economics at PU Sangnawna (L) Nen from 1982-2022, the Education Department at NEHU from 1982-1984, and events they participated in such as the NAAC Grade 'A' Celebration Day in April 2022 and receiving the Principal's Award at an Annual Day.
This document discusses privacy and security issues related to web browsers. It outlines research on establishing trusted paths for browsers to prevent spoofing of website identities. Approaches for separating status information from website content are proposed, such as using dedicated metadata windows or colored boundaries. A prototype uses synchronized random borders and labeling to make spoofed windows easier to detect. User studies found the security signals were noticeable and effective. The document also discusses approaches for managing browser cookies in a way that balances privacy, functionality, and usability.
God tells Noah that the world has become evil and corrupt, and plans to destroy it with a flood, saving only Noah, his family, and two of each animal species on an ark. Noah builds the ark as instructed and loads all the animals. When the flood comes, Noah and the animals are safe inside, but the rest of the wicked mankind who refused to listen to Noah's warnings are swept away by the rising waters. After the floodwaters recede, God puts a rainbow in the sky as a promise to Noah and all living creatures that he will never destroy the world with a flood again.
These certificates recognize participation in a cultural exchange program between Government Serchhip College in Mizoram, India and Maharaj Lakshmishwar Singh Memorial College in Bihar, India on December 18, 2020 under the Ek Bharat Shreshtha Bharat program. The certificates were issued and signed by the convener, principal, secretary, and coordinator of Government Serchhip College.
This document provides an overview of formatting text and paragraphs in Microsoft Word 2007, including alignment, tabs, indentation, line spacing, bullets and numbered lists. It discusses how to set different tab stops and align text using the horizontal ruler or paragraph dialog box. Shortcuts are provided for common text formatting and navigation tasks. The document also demonstrates how to apply bullets to an example list.
SIMULATION OF FIR FILTER BASED ON CORDIC ALGORITHMVLSICS Design
油
Coordinate Rotation Digital Computer (CORDIC) discovered by Jack E Volder. It is a shift-add operation and iterative algorithm. CORDIC algorithm has wide area for several applications like digital signal processing, biomedical processing, image processing, radar signal processing, 8087 math coprocessor, the HP-35 calculator, Discrete Fourier, Discrete Hartley and Chirp-Z transforms, filtering, robotics, real time navigational system and also in communication systems. In this paper, we discussed about the CORDIC algorithm and CORDIC algorithm based finite impulse response low pass & high pass filter. We have generated the M-code for the CORDIC Algorithm and CORDIC Algorithm based FIR filter with the help of MATLAB 2010a.We also discussed about the frequency response characteristics of FIR filter.
In this PDF document, the importance of engineering models in successful project execution is discussed. It explains how these models enhance visualization, planning, and communication. Engineering models help identify potential issues early, reducing risks and costs. Ultimately, they improve collaboration and client satisfaction by providing a clear representation of the project.
Floating Offshore Wind in the Celtic Seapermagoveu
油
Floating offshore wind (FLOW) governance arrangements in the Celtic Sea case are changing and innovating in response to different drivers including domestic political priorities (e.g. net-zero, decarbonization, economic growth) and external shocks that emphasize the need for energy security (e.g. the war in Ukraine).
To date, the rules of the game that guide floating wind in the UK have evolved organically rather than being designed with intent, which has created policy incoherence and fragmented governance arrangements. Despite this fragmentation, the UK has a well-established offshore wind sector and is positioning itself to become a global leader in floating wind.
Marine governance arrangements are in a state of flux as new actors, resources, and rules of the game are being introduced to deliver on this aspiration. However, the absence of a clear roadmap to deliver on ambitious floating wind targets by 2030 creates uncertainty for investors, reduces the likelihood that a new floating wind sector will deliver economic and social value to the UK, and risks further misalignment between climate and nature goals.
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...Priyanka Dange
油
Definition of airport engineering and airport planning, Types of surveys required for airport site, Factors affecting the selection of site for Airport
Barbara Bianco
Project Manager and Project Architect, with extensive experience in managing and developing complex projects from concept to completion. Since September 2023, she has been working as a Project Manager at MAB Arquitectura, overseeing all project phases, from concept design to construction, with a strong focus on artistic direction and interdisciplinary coordination.
Previously, she worked at Progetto CMR for eight years (2015-2023), taking on roles of increasing responsibility: initially as a Project Architect, and later as Head of Research & Development and Competition Area (2020-2023).
She graduated in Architecture from the University of Genoa and obtained a Level II Masters in Digital Architecture and Integrated Design from the INArch Institute in Rome, earning the MAD Award. In 2009, she won First Prize at Urban Promo Giovani with the project "From Urbanity to Humanity", a redevelopment plan for the Maddalena district of Genoa focused on the visual and perceptive rediscovery of the city.
Experience & Projects
Barbara has developed projects for major clients across various sectors (banking, insurance, real estate, corporate), overseeing both the technical and aesthetic aspects while coordinating multidisciplinary teams. Notable projects include:
The Sign Business District for Covivio, Milan
New L'Or辿al Headquarters in Milan, Romolo area
Redevelopment of Via C. Colombo in Rome for Prelios, now the PWC headquarters
Interior design for Spark One & Spark Two, two office buildings in the Santa Giulia district, Milan (Spark One: 53,000 m族) for In.Town-Lendlease
She has also worked on international projects such as:
International Specialized Hospital of Uganda (ISHU) Kampala
Palazzo Milano, a residential building in Taiwan for Chonghong Construction
Chua Lang Street Building, a hotel in Hanoi
Manjiangwan Masterplan, a resort in China
Key Skills
鏝 Integrated design: managing and developing projects from concept to completion
鏝 Artistic direction: ensuring aesthetic quality and design consistency
鏝 Project management: coordinating clients, designers, and multidisciplinary consultants
鏝 Software proficiency: AutoCAD, Photoshop, InDesign, Office Suite
鏝 Languages: Advanced English, Basic French
鏝 Leadership & problem-solving: ability to lead teams and manage complex processes in dynamic environments
Production Planning & Control and Inventory Management.pptxVirajPasare
油
Production Planning and Control : Importance, Objectives and Functions . Inventory Management - Meaning, Types , Objectives, Selective Inventory Control : ABC Analysis
1. 2000 Prentice Hall, Inc. All rights reserved.
1
Chapter 2 - Introduction to C
Programming
Outline
2.1 Introduction
2.2 A Simple C Program: Printing a Line of Text
2.3 Another Simple C Program: Adding Two Integers
2.4 Memory Concepts
2.5 Arithmetic in C
2.6 Decision Making: Equality and Relational Operators
2. 2000 Prentice Hall, Inc. All rights reserved.
2
2.1 Introduction
C programming language
Structured and disciplined approach to program design
Structured programming
Introduced in chapters 3 and 4
Used throughout the remainder of the book
3. 2000 Prentice Hall, Inc. All rights reserved.
3
2.2 A Simple C Program:
Printing a Line of Text
Comments
Text surrounded by /* and */ is ignored by computer
Used to describe program
#include <stdio.h>
Preprocessor directive
Tells computer to load contents of a certain file
<stdio.h> allows standard input/output operations
1 /* Fig. 2.1: fig02_01.c
2 A first program in C */
3 #include <stdio.h>
4
5 int main()
6 {
7 printf( "Welcome to C!n" );
8
9 return 0;
10 }
Welcome to C!
4. 2000 Prentice Hall, Inc. All rights reserved.
4
2.2 A Simple C Program:
Printing a Line of Text
int main()
C++ programs contain one or more functions, exactly one of
which must be main
Parenthesis used to indicate a function
int means that main "returns" an integer value
Braces ({ and }) indicate a block
The bodies of all functions must be contained in braces
5. 2000 Prentice Hall, Inc. All rights reserved.
5
2.2 A Simple C Program:
Printing a Line of Text
printf( "Welcome to C!n" );
Instructs computer to perform an action
Specifically, prints the string of characters within quotes ( )
Entire line called a statement
All statements must end with a semicolon (;)
Escape character ()
Indicates that printf should do something out of the ordinary
n is the newline character
6. 2000 Prentice Hall, Inc. All rights reserved.
6
2.2 A Simple C Program:
Printing a Line of Text
return 0;
A way to exit a function
return 0, in this case, means that the program terminated
normally
Right brace }
Indicates end of main has been reached
Linker
When a function is called, linker locates it in the library
Inserts it into object program
If function name is misspelled, the linker will produce an
error because it will not be able to find function in the
library
7. 2000 Prentice Hall, Inc. All rights reserved.
Outline
Outline
7
1. Initialize variables
2. Input
2.1 Sum
3. Print
Program Output
1 /* Fig. 2.5: fig02_05.c
2 Addition program */
3 #include <stdio.h>
4
5 int main()
6 {
7 int integer1, integer2, sum; /* declaration */
8
9 printf( "Enter first integern" ); /* prompt */
10 scanf( "%d", &integer1 ); /* read an integer */
11 printf( "Enter second integern" ); /* prompt */
12 scanf( "%d", &integer2 ); /* read an integer */
13 sum = integer1 + integer2; /* assignment of sum */
14 printf( "Sum is %dn", sum ); /* print sum */
15
16 return 0; /* indicate that program ended successfully */
17 }
Enter first integer
45
Enter second integer
72
Sum is 117
8. 2000 Prentice Hall, Inc. All rights reserved.
8
2.3 Another Simple C Program:
Adding Two Integers
As before
Comments, #include <stdio.h> and main
int integer1, integer2, sum;
Declaration of variables
Variables: locations in memory where a value can be stored
int means the variables can hold integers (-1, 3, 0, 47)
Variable names (identifiers)
integer1, integer2, sum
Identifiers: consist of letters, digits (cannot begin with a digit)
and underscores( _ )
Case sensitive
Declarations appear before executable statements
If an executable statement references and undeclared variable
it will produce a syntax (compiler) error
9. 2000 Prentice Hall, Inc. All rights reserved.
9
2.3 Another Simple C Program:
Adding Two Integers
scanf( "%d", &integer1 );
Obtains a value from the user
scanf uses standard input (usually keyboard)
This scanf statement has two arguments
%d - indicates data should be a decimal integer
&integer1 - location in memory to store variable
& is confusing in beginning for now, just remember to
include it with the variable name in scanf statements
When executing the program the user responds to the
scanf statement by typing in a number, then pressing the
enter (return) key
10. 2000 Prentice Hall, Inc. All rights reserved.
10
2.3 Another Simple C Program:
Adding Two Integers
= (assignment operator)
Assigns a value to a variable
Is a binary operator (has two operands)
sum = variable1 + variable2;
sum gets variable1 + variable2;
Variable receiving value on left
printf( "Sum is %dn", sum );
Similar to scanf
%d means decimal integer will be printed
sum specifies what integer will be printed
Calculations can be performed inside printf statements
printf( "Sum is %dn", integer1 + integer2 );
11. 2000 Prentice Hall, Inc. All rights reserved.
11
2.4 Memory Concepts
Variables
Variable names correspond to locations in the computer's
memory
Every variable has a name, a type, a size and a value
Whenever a new value is placed into a variable (through
scanf, for example), it replaces (and destroys) the previous
value
Reading variables from memory does not change them
A visual representation
integer1 45
12. 2000 Prentice Hall, Inc. All rights reserved.
12
2.5 Arithmetic
Arithmetic calculations
Use * for multiplication and / for division
Integer division truncates remainder
7 / 5 evaluates to 1
Modulus operator(%) returns the remainder
7 % 5 evaluates to 2
Operator precedence
Some arithmetic operators act before others (i.e.,
multiplication before addition)
Use parenthesis when needed
Example: Find the average of three variables a, b and c
Do not use: a + b + c / 3
Use: (a + b + c ) / 3
13. 2000 Prentice Hall, Inc. All rights reserved.
13
2.5 Arithmetic
Arithmetic operators:
Rules of operator precedence:
C operation Arithmetic
operator
Algebraic
expression
C expression
Addition + f + 7 f + 7
Subtraction - p c p - c
Multiplication * bm b * m
Division / x / y x / y
Modulus % r mod s r % s
Operator(s) Operation(s) Order of evaluation (precedence)
() Parentheses Evaluated first. If the parentheses are nested, the
expression in the innermost pair is evaluated first. If there
are several pairs of parentheses on the same level (i.e.,
not nested), they are evaluated left to right.
*, /, or % Multiplication,Divi
sion, Modulus
Evaluated second. If there are several, they are
evaluated left to right.
+ or - Addition
Subtraction
Evaluated last. If there are several, they are
evaluated left to right.
14. 2000 Prentice Hall, Inc. All rights reserved.
14
2.6 Decision Making: Equality and
Relational Operators
Executable statements
Perform actions (calculations, input/output of data)
Perform decisions
May want to print "pass" or "fail" given the value of a
test grade
if control structure
Simple version in this section, more detail later
If a condition is true, then the body of the if statement
executed
0 is false, non-zero is true
Control always resumes after the if structure
Keywords
Special words reserved for C
Cannot be used as identifiers or variable names
15. 2000 Prentice Hall, Inc. All rights reserved.
15
2.6 Decision Making: Equality and
Relational Operators
Standard algebraic
equality operator or
relational operator
C equality or
relational
operator
Example of C
condition
Meaning of C
condition
Equality Operators
= == x == y x is equal to y
not = != x != y x is not equal to y
Relational Operators
> > x > y x is greater than y
< < x < y x is less than y
>= >= x >= y x is greater than or
equal to y
<= <= x <= y x is less than or
equal to y
16. 2000 Prentice Hall, Inc. All rights reserved.
16
2.6 Decision Making: Equality and
Relational Operators
Keywords
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
17. 2000 Prentice Hall, Inc. All rights reserved.
Outline
Outline
17
1. Declare variables
2. Input
2.1 if statements
3. Print
1 /* Fig. 2.13: fig02_13.c
2 Using if statements, relational
3 operators, and equality operators */
4 #include <stdio.h>
5
6 int main()
7 {
8 int num1, num2;
9
10 printf( "Enter two integers, and I will tell youn" );
11 printf( "the relationships they satisfy: " );
12 scanf( "%d%d", &num1, &num2 ); /* read two integers */
13
14 if ( num1 == num2 )
15 printf( "%d is equal to %dn", num1, num2 );
16
17 if ( num1 != num2 )
18 printf( "%d is not equal to %dn", num1, num2 );
19
20 if ( num1 < num2 )
21 printf( "%d is less than %dn", num1, num2 );
22
23 if ( num1 > num2 )
24 printf( "%d is greater than %dn", num1, num2 );
25
26 if ( num1 <= num2 )
27 printf( "%d is less than or equal to %dn",
28 num1, num2 );
18. 2000 Prentice Hall, Inc. All rights reserved.
Outline
Outline
18
3.1 Exit main
Program Output
29
30 if ( num1 >= num2 )
31 printf( "%d is greater than or equal to %dn",
32 num1, num2 );
33
34 return 0; /* indicate program ended successfully */
35 }
Enter two integers, and I will tell you
the relationships they satisfy: 3 7
3 is not equal to 7
3 is less than 7
3 is less than or equal to 7
Enter two integers, and I will tell you
the relationships they satisfy: 22 12
22 is not equal to 12
22 is greater than 12
22 is greater than or equal to 12