Pspc Lecture 3 - First Program in c
Pspc Lecture 3 - First Program in c
OF PROGRAMMING…….
WHAT DO WE NEED BEFORE WE START
CODING?
Problem statement
Sample input and expected output
Good logic (algorithm/pseudo-code)
A window to write/edit our programs
A window to interact with the machine
by giving the input and viewing the
output (GUI)
One more thing….. Can you guess????
COMPILERS!!!
They translate source code into machine
language/binary language
The .c file gets converted into a .obj file.
The .obj file is then sent for execution
GENERAL STEPS OF
PROGRAMMING
1. Write the code
2. Save the file with .c extension
3. Compile the code
4. Debug code and remove errors if any
5. Repeat the steps 3-4 until compiler
gives no error
6. Execute the code by giving the
required input and viewing the output.
FIRST PROGRAM IN C
Every statement/instruction in C ends with a ;
printf is used to print a string on the output screen
#include<stdio.h> needs to be written at the
beginning if we want to use printf
void main() is used to enclose the set of
executable instructions. It tells us the beginning
and end points of the execution via the { and }
Can you point out all the errors in the
following?
void Main
{
#include <stdio.h>
print("Hello World!");
}
For example:
Good Morning
Jane
Doe
Solution
#include<stdio.h>
void main()
{
printf(“Good morning\nJane\nDoe”);
}
ESCAPE SEQUENCES
#include <stdio.h>
int main() { A B C
printf("A\tB\tC\n1\t2\t3"); 1 2 3
return 0;
}
Examples
#include <stdio.h>
#include <stdio.h>
#include <stdio.h>