0% found this document useful (0 votes)
5 views

Pspc Lecture 3 - First Program in c

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

Pspc Lecture 3 - First Program in c

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

LET US STEP INTO THE WORLD

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!");
}

Preprocessing  Compiling  Execution


TRY ON YOUR OWN

 Write a C program to Greet a person by saying:


Good Morning
First name
Last Name

For example:
Good Morning
Jane
Doe
Solution

#include<stdio.h>
void main()
{
printf(“Good morning\nJane\nDoe”);
}
ESCAPE SEQUENCES

 Specialsymbols that are used to modify the


output in some manner.
Examples

#include <stdio.h>

int main() { A B C
printf("A\tB\tC\n1\t2\t3"); 1 2 3
return 0;
}
Examples

#include <stdio.h>

int main() { This is a backslash: \


printf("This is a backslash: \\");
return 0;
}
Examples

#include <stdio.h>

int main() { "Hello, World!"


printf("\"Hello, World!\"");
return 0;
}
Examples

#include <stdio.h>

int main() { World


printf("Hello\rWorld");
return 0;
}

You might also like