1 Lab

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Lab -1

PROGRAMMING IN C

Programming

To solve a computing problem, its solution must be specified in terms of sequence of


computational steps such that they are effectively solved by a human agent or by a digital
computer.

Programming Language

1) The specification of the sequence of computational steps in a particular


programming language is termed as a program
2) The task of developing programs is called programming
3) The person engaged in programming activity is called programmer

Techniques of Problem Solving


Problem solving an art in that it requires enormous intuitive power & a science for it takes
a pragmatic approach.
Here a rough outline of a general problem solving approach.
1) Write out the problem statement include information on what you are to solve &
consider why you need to solve the problem
2) Make sure you are solving the real problem as opposed to the perceived problem. To
check to see that you define & solve the real problem
3) Draw & label a sketch. Define & name all variables and /or symbols. Show numerical
values of variables, if known.
4) Identify & Name
a. relevant principles, theories & equations
b. system & subsystems
c. dependent & independent variables
d. known & unknowns
e. inputs & outputs
f. necessary information
5) List assumptions and approximations involved in solving the problem. Question the
assumptions and then state which ones are the most reasonable for your purposes.
6) Check to see if the problem is either under-specified, figure out how to find the
missing information. If over-specified, identify the extra information that is not
needed.
7) Relate problem to similar problem or experience
8) Use an algorithm
9) Evaluate and examine and evaluate the answer to see it makes sense.
Introduction to C Programming

C is a general-purpose computer programming language developed in 1972 by Dennis


Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. C is a
structured programming language, which means that it allows you to develop programs using
well-defined control structures (you will learn about control structures in the articles to
come), and provides modularity (breaking the task into multiple sub tasks that are simple
enough to understand and to reuse). C is often called a middle-level language because it
combines the best elements of low-level or machine language with high-level languages.

Where is C useful?
C’s ability to communicate directly with hardware makes it a powerful choice for system
programmers. In fact, popular operating systems such as Unix and Linux are written entirely
in C. Additionally, even compilers and interpreters for other languages such as FORTRAN,
Pascal, and BASIC are written in C. However, C’s scope is not just limited to developing
system programs. It is also used to develop any kind of application, including complex
business ones. The following is a partial list of areas where C language is used:

Ø Embedded Systems

Ø Systems Programming

Ø Artificial Intelligence

Ø Industrial Automation

Ø Computer Graphics

Ø Space Research

Why you should learn C?

You should learn C because:

 C is simple.
 There are only 32 keywords so C is very easy to master. Keywords are words that
have special meaning in C language.
 C programs run faster than programs written in most other languages.
 C enables easy communication with computer hardware making it easy to write
system programs such as compilers and interpreters.

WHY WE NEED DATA AND A PROGRAM


Any computer program has two entities to consider, the data, and the program. They are
highly dependent on one another and careful planning of both will lead to a well planned and
well written program. Unfortunately, it is not possible to study either completely without a
good working knowledge of the other. For that reason, this tutorial will jump back and forth
between teaching methods of program writing and methods of data definition. Simply follow
along and you will have a good understanding of both. Keep in mind that, even though it
seems expedient to sometimes jump right into coding the program, time spent planning the
data structures will be well spent and the quality of the final program will reflect the original
planning

How to run a simple c program


1. Copy Turbo c/c++ in computer

2. Open c:\tc\bin\tc.exe

3. A window appears

4. Select File->new to open a new file

5. Type the following program on editor

#include <stdio.h>

void main()

printf(“hello”);

6. compile the program by pressing ALT+F9

7. Run the program by pressing CTRL +F9

Note:

1. C is case sensitive

2. Always terminate statements with semicolon.

3. A program starts with main()


Explanation of program
#include is known as compiler directive. A compiler directive is a command to compiler to
translate the program in a certain way. These statement are not converted into machine
language but only perform some other task.

main() is a function which the staring point for complier to start compilation. So a function
must contain a main() function.

You might also like