1 introduction to c programming
DESCRIPTION
This is a lecture note from a class i attended by-Lecture 1-Dr. Sunil K. Jha Programing 1TRANSCRIPT
Introduction• Why do we need it?• Where can we use it?
• How can we write the code?• How the code is organized?
• In this subject we will program in C language.
C language• Why do we learn C language as a structural programming
language?
• C based languages• C++• C#• Java
• As a compiler you can use CodeBlocks, or any other C compiler (http://www.codeblocks.org/)
How can we write program in C language?
1. Declaration of the main functon2. Declaration of varialbes and constants.3. The main logic of the program4. Showing the results
• Declaring some external functions (optional)
void main(){
Declaration of the variables;Main logic of the program;Here we can use predeclared functions.Final output or result.
}
Defining variables in CThere are multiple types of variables• integer (Real numbers)• float (Decimal point numbers)• char (Characters, single or string)
Our first C program
#include <stdio.h>void main(){
printf(“Welcome to UIST!\n”);/* This will be printed on the screen */
}
Examplevoid main(){
int a;float p;p=1.0/2.0; /* p=0.5 */a=5/2; /* a=2 */p=(1/2)+(1/8); /* p=0.0 */p=3.5/2.8; /* p=1.25 */a=p; /* a=1 */a=a+1; /* a=2 */
}
Operators in CMath operators• Addition +• Subtraction –• Multiplication *• Division /• Power ^
Logical operators• Equal ==• Not equal !=• Greater > (Greater equal >=)• Smaller < (Smaller or equal <=)