Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
67 views

Introduction To C Programming: R. Jothi Scope Vit

This document provides an introduction to the C programming language. It discusses the history and development of C, common uses of C including operating systems and device drivers, and basic steps for writing a C program. It also provides examples of simple C programs to add two numbers, both integers and floating point, and demonstrates the use of basic functions like scanf(), printf(), and getch(). The document covers fundamental C concepts like variables, data types, and control structures.

Uploaded by

sisil amose
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Introduction To C Programming: R. Jothi Scope Vit

This document provides an introduction to the C programming language. It discusses the history and development of C, common uses of C including operating systems and device drivers, and basic steps for writing a C program. It also provides examples of simple C programs to add two numbers, both integers and floating point, and demonstrates the use of basic functions like scanf(), printf(), and getch(). The document covers fundamental C concepts like variables, data types, and control structures.

Uploaded by

sisil amose
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Introduction to C

Programming

R. Jothi
SCOPE VIT
Overview
• Introduction to C Language
• Turbo C Compiler
• C Program Example
• Text Books
Text Books
• Programming in ANSI C,
Balagurusamy
• Let Us C, Yashavant
Kanetkar
• C: The Complete
Reference, Herbert Schildt
HISTORY OF C
• The C programming language was designed by
Dennis Ritchie at Bell Laboratories in the early 1970s

• ANSI standard in 1999


USE OF C
• OPERATING SYSTEMS
• EDITORS
• COMPILER CONSTRUCTION
• INTERPRETERS
• ASSEMBLERS
• DBMS/RDBMS
• APPLICATION SOFTWARE
• GENERAL-PURPOSE SOFTWARE
USE OF C
• DEVELOPING GAMES
• COMMUNICATION PROTOCOLS
• DEVICE DRIVER PROGRAMMING
• PROGRAMS FOR MOBILE DEVICES
• ROBOTICS
STEPS FOR WRITING A PROGRAM

PROGRAM

INSTRUCTION INSTRUCTION INSTRUCTION

CONSTANTS
VARIABLES
KEYWORDS

SPECIAL
ALPHABETS DIGITS SYMBOLS
C CHARACTER SET
• ALPHABETS : A…Z,a…z
• DIGITS : 0…9
• SPECIAL
SYMBOLS : ~ ` ! @ # %^
& * ()_ - + =
| \ { } [ ]:
; “ ‘ < > , . ? /
Structure of C Program
A Simple C Program to display “Hello Electrical Engineers”
Source
Code
/* This is my first program */

#include <stdio.h>

void main()
{
printf(“Hello Electrical Engineers”);
}
Hello.c
How does a computer execute a program
Few functions
scanf() : for reading input from user (keyboard)
scanf(“control string”, argument)
e.g. scanf(“%d”, &number1)
- read an integer value to the variable number1 and store it in the memory
location ( &number1);

“Always use an & in front of each variable”

printf() : for displaying output on the screen


printf(“ Hello”); // print message hello
printf(“ The sum is %d”, number1);
// print the value of integer variable number 1

clrscr() : clear screen

getch() : output screen waits for some time until a key is hit
Program to Add Two Numbers

#include <stdio.h>
void main()
{
int a , b, c ; // declaration of variables
printf( " Enter first number ");
scanf(" %d ", &a);
printf( " Enter second number ");
scanf(" %d ", &b);
c = a+ b;
printf( " Sum of given two numbers is %d ", c );

}
#include <stdio.h>
void main()
{ int a , b, c;
printf( " Enter first number \n");
scanf(" %d ", &a);
printf( " \nEnter second number ");
scanf(" %d ", &b);
c = a+ b;
printf( " \nSum of given two numbers is %d ", c );
}
Remember

1. C Language is case sensitive


a and A are different
2. Every statement in C program must be terminated
by a semicolon.
3. Every C program must have one main function.
4. Check for parenthesis balance
{ }
5. Every variable must be declared.
Input - scanf()

scanf(“control string”, argument)

e.g. scanf(“%d”, &number1)

Control string Data type meaning


%d int integer
%f float float
%lf double double
%c char Character
%s string Character array
Reading Two Numbers in single scanf
#include <stdio.h> // header file
#include <conio.h> // header file
void main( ) // function
{ /* Program to add 2 Nos. */
int a, b, c;  
clrscr();
printf( " Enter 2 Nos. ");
scanf ("%d %d",&a,&b);  // input
c = a + b; // add 2 nos.
printf("%d + %d = %d", a,b,c);
getch();
}

2+3=5
Program to Add , subtract, mult, div Two
Integer Numbers
#include <stdio.h> // header file
#include <conio.h> // header file
void main( ) // function
{ /* Program to add 2 Nos. */
int a, b, c;
clrscr();
printf( " Enter 2 Nos. ");
scanf ("%d %d",&a,&b); // input
c = a + b;
printf("%d + %d = %d\n", a,b,c);
c = a - b;
printf("%d + %d = %d\n", a,b,c);
getch();
} 2+3=5
Program to Add , subtract, mult, div Two
Floating Numbers
#include <stdio.h> // header file
#include <conio.h> // header file
void main( ) // function
{ /* Program to add 2 Nos. */
float a, b, c;
clrscr();
printf( " Enter 2 Nos. ");
scanf ("%f %f",&a,&b); // input
c = a + b; // add 2 nos.
printf("%f + %f = %d\n", a,b,c);
c = a - b; // subtract 2 nos.
printf("%f + %f = %d\n", a,b,c);
getch();
} 2.2 + 3.5 = 5.7

You might also like