0% found this document useful (0 votes)
10 views3 pages

03 First Programs

The document outlines the steps in programming, including requirement specification, analysis, design, implementation, and verification. It also introduces the building blocks of a C program with an example that converts weight from pounds to kilograms and grams. Additionally, it discusses the role of the preprocessor and reserved words in C programming.
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)
10 views3 pages

03 First Programs

The document outlines the steps in programming, including requirement specification, analysis, design, implementation, and verification. It also introduces the building blocks of a C program with an example that converts weight from pounds to kilograms and grams. Additionally, it discusses the role of the preprocessor and reserved words in C programming.
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/ 3

Introduction to Programming

Steps in Programming

REQUIREMENT SPECIFICATION

Understanding the Problem


What is required?

ANALYSIS

Defining the Program Objectives


What outputs?
What inputs?
Any necessary formulas ?

DESIGN

Designing the Program


Which variables?
Steps to be followed

IMPLEMENTATION

Writing the Code


Compiling the Program
Running the Program

VERIFICATION

Testing and Debugging


Maintaining and Modifying Code

6
Introduction to Programming

.CPP
Source File .C

Libraries
COMPILER

LINKER
Executable
Object File LOADER File
.OBJ .EXE

Building Blocks of a C Program


We will start learning about the building blocks of a C program by analyzing the
following example.
/****************************************************************/
/* CTIS151 Introduction to Programming */
/* */
/* Purpose : Input a weight in pounds and output weight in */
/* kilograms and grams */
/* */
/****************************************************************/

#include <stdio.h> /* Standard I/O Library */


#include <stdlib.h>
#define KG_PER_POUND 0.453592 /* Conversion constant */
int main(void)
{
double pounds; /* input - weight in pounds */
double kilograms, /* output - weight in kilograms */
grams; /* output - weight in grams */

/* input weight in pounds */

printf("Enter weight in pounds: ");


scanf("%lf", &pounds);

/* calculate the kilogram and gram equivalents */

kilograms = pounds * KG_PER_POUND;


grams = kilograms * 1000;

/* output the results */


printf("%0.2f pounds is %0.2f kilograms and %0.2f grams\n",
pounds, kilograms, grams);

return (0);
}

7
Introduction to Programming

Preprocessor and Preprocessor Directives


Preprocessor is a feature of C Language which is not found in most of the other high-
level programming languages and is a part of the C compilation process. The source
code is first analyzed by the preprocessor and any replacements indicated by the
preprocessor directives are made. A preprocessor directive has the sign # as the first
non-blank character of the line.

Characters representing
the source code created by
using a text editor
( .C or .CPP)

Preprocessor COMPILER
scans for directives
expands any macros

Reserved Words
Every programming language contains some words reserved for special purposes.
These words are called keywords or reserved words.

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

You might also like