Skip to main content

#lecture 2 coding of your First C program

Structure of a C program:

#include<header file>
Int main() 
{
----;
---;
---;
}

The # sign tells the compiler to include the header file(generally iostream)

Header file is included as it is the standard library of all readymade C commands that are fed to the compiler. "Iostream" stands for input output library and has various commands like cin>>, cout<<, basic arithmetic operations. 

The main() is very crucial in C. The Main() is a C function and just like a calculator returns a value, the main function returns integer value. So we write int before main.
The compilers like turbo C/C++ even allow us yo return no value from main function i.e. void
So we sometimes write void main(). 

The sequence of commands that the compiler has to follow are written between the curly brackets. 
The statement in C are ended with ' ; '

Before writing your first C program u need to equip with these things first! 

Data types in C :

Data type of a variable simply means what kind of data is going to be stored in the declared variable. 
There are following data types in C

1. Numeric
    It consist of integer(denoted by int) ex:4, -78, etc and floating types (denoted         by float) ex: 3.14,-5.67, etc. 

2.strings and character:
  Strings are composed of character, symbols and numbers. They are enclosed       within double quotations. 
    You have to include string file first. 

Ex:
#include<string>
      Int main() 
{
  string a= "hi, I am John! ";
}
Characters are single letters or symbols that are enclosed within single quotes. 

Ex: char letter= 'a';


3. Boolean :
    It either returns 0 (false) or 1 (true).
     Ex -   bool official= false;

Variable declaration:

In C/ C++ we deal most of the manipulation by assuming variables first and then we try to solve the problem in terms of those variables. 

Where to write C program:

On PC or laptop u can download free IDEs (Integrated Development Environment) which consists of editor as well as a compiler. 
U can download turbo C++.

Turbo C++ for PC and latops.

                                      This is ur CPPdroid app. For Android. 

For androids I would suggest u a free IDE  named CPPdroid. 
 Here I am using the same. 

Your first programs:

1) Program to print your name
 
     We will use printf(" Text to be printed is typed here") Command.
      Don't forget to end the sentence with ;.


This is your source code written in CPPdroid. 


                                This is how ur program looks after excecution.


2) Let's try another one , say, program that prints sum of two numbers
 
     We will have to first declare two variables(say integers a and b) whose sum          is  to be taken and a third variable named "sum" For better understanding of        the program.


       here I've used std::cout command. It means standard output and it is used            to display the output in my mobile IDE. But with turbo C++ u can directly u              use   cout command.

          This is ur source code!


                                 It is the excecution of ur commads.


Conclusions:

1. You will be equipped with some basics and tools( CPPdroid, turbo C++ )               essential to code ur first C program

2. You will be guided to write ur first C program. 


Was it helpful for u? Do u have any suggestions? 



Comments

Popular posts from this blog

Python tutorial - #4 (Operators in Python)

OPERATORS IN PYTHON The general purpose of a program is to accept data and perform some operations on the data. The data in the program is stored in variables. The next question is how to perform operations on the data. For example, when a programmer wants to add two numbers, he simply type '+' symbol. This symbol performs addition operation. Such symbols are called operators. ⇨ Operator = An operator is a symbol that performs an operation.  When an operator acts on some variables then it is called operands . Example :- a + b in the given equation '+' operator acts on two operands 'a' and 'b'. If an operator acts on single operands then it is called unary operator . And when an operator acts on two operands then it is called binary operator . And when an operator acts on more than two operands (variable) It is called Tertiary operator . ➠Classifications of Operator -- a) Arthimatic operators b) Assignment operators c) Unary minu...

Python tutorial - #5 (Operators in Python)

Membership Operators This operator helps us to check an element is found in a sequence or not. It gives there result in Boolean value (True or False). ➥There are two types of Membership operator :- a) in b) not in ➢in membership operator This membership operator returns True if an element is found in a sequence and it returns  False When an element is not found in a sequence. Program - #1 ➢not in membership operator This membership operator returns True if an element is not found in a sequence and it returns False if an element is found in a sequence. Program = #2 Identity Operators This operator helps us to check whether two element are same or not. Actually, this operator compares the memory location of two object, if the memory locations are same then objects are also same otherwise the objects are not same.                                      ...

Python tutorial - #6 (Control statements)

Control Statements When we write a simple program, generally it executes line by line and this execution are called sequential execution. This type of execution is suitable only for developing simple programs. It is not suitable for developing complex programs. To develop a program which contains complex logic. Then we need to execute statements according to our requirement for this we uses Control statements in which we can control the statements according to our need.  ➠ There are types of control statements in Python:- a) If... statements b) If... else.. Statements c) If...elif....else.. Statements  d) While loop  e) For loop f) Nested loop  g) Else suit h) Continue statements  i) Break statements j) Pass statements  k) Assert statements l) Return statements  ↷If... statements    Syntax:-  if condition:                 Statements Here, at first...