Skip to main content

C Programming for Beginners



Introduction

Programming is a tool to perform various computations with the help of a machine. There are numerous programming languages(coding language) based on need and machine on which program will execute. 


Data Types

In our childhood we learned mathematical numbers and the English alphabet(Data Types). 

In programming languages like in C data are categorized in different groups. 



Function

Functions are the building blocks of a programming language. A function performs a designated task. 

In C language

Syntax to write function without input

main(), add(), nothing() 


Syntax to write function with integer input(add, subtract, multiply, divide)+ no output

void main(int x, int y) 


Syntax to write function with integer input + integer output

int main(int x, int y) 


Syntax to write function with integer input + character output

char main(int x, int y) 



Types of Function




1. User defined function- defined by the programmer or user to perform designated tasks. 


2. Pre defined functions(Library function)- function predefined to perform certain tasks. These functions are used by including their definition in user defined functions. The square root function→ sqrt(x) function is used with input x and this function is defined in the math.h library. 

Similarly, printf() and scanf() → most used pre defined function(defined in stdio.h)



Example of Function

Void main() 

{

}

Here 

main() {    --> start of Program 

} --> end of program



Next program is Printing Hello Program

#include <stdio.h>

Void main() 

{

printf("Hello");

}

In this program printf() is a function with input Hello text. And the print function is defined in stdio.h (#include <stdio.h> → to include the definition print function)



Printing Integer value Program

#include <stdio.h>

Void main() 

{

Int a= 3;     // defining an integer with alphabet a= 3

printf("Number = %d", a);

/* in print function whater written between “ ” will get displayed on output 

The print function replace value after  % (%d will get printed as value of a that is 3) 

*/

}

Comments in C language

// → program will not execute things written after this(single line comment) 

/*...........*/ → multi line comment

Except comments every line ends with a semicolon(;)




Comments

Popular posts from this blog

The Archadian

Every Archadian were looking towards the sky in the hope of sunset and with every passing moment they were afraid of lose. Their fear made them more weak and they lost more life in battle field in-front of large Valvan army. The field was full of blood surrounded by hill on one side and forests from another side. Rest of the two sides covered with two army in front of each other. Archadian vs Valvan The Valvan get more aggressive with their swords flying in the battle field. Finally with sunset, drum sound spread all over the field and war was at end. With sunset over the hills, darkness spread in the field and blood became more red in absence of sun. Alkan, the arrogant Valavn king, ask his solider to return back to tent leaving behind injured and dead Valvan solider in field. Both the army headed towards their tent leaving blood on the earth of Archadians. The Valvan get busy in celebrating their victory in today's battle field. While in Archadian tent, king Arithm order a...

Warrior Wang

 1954, Guangyuan Lin(11 year old): Mom! Will brother Wang come today? Xiabo: He has an exam. He will come next week. Lin: But mom, today is my birthday. Xiabo: That's why your brother sent you a gift. Lin: where is it? Xiabo: Not now. I will give it to you tonight. What would you like to eat at night? Lin: Rice cake. Rice cake. In the evening, when Lin was playing outside with her friends. Quan entered the house. Xiabo: Why are you looking tense? Quan(starts crying): Our field. Xiabo: What happened to the field? Quan: There was fire, half of our crop got burnt. Xiabo holds the hand of Quan and says "we will find out some way". Quan: Sorry, I made your life hard. Xiabo: You gave me two beautiful kids and I am happy with this family. Whatever hard time will come, we will face it together. By the way, today is Lin's birthday and she wants to eat rice cake. Why don't you go to the market and buy some rice. Quan takes a bag and heads toward the market. In the market Qu...

Human Body

  Lecture 5 Human Body Heart Vertebrate(animal with backbone) heart performs the function of pumping blood around body. The blood flow in heart is unidirectional because of heart valves.  Fish- 2 chember heart(1 atrium, 1 ventricle)  Amphibian and Reptile- 3 chember heart(2 atria, 1 ventricle)              Exception- Crocodiles and Alligators(4 chember heart)  Bird and Mammal- 4 chember heart(2 atria, 2 ventricle)  Atrium- Upper chember of heart that receive blood from body and send it to ventricle.  Ventricle- Lower chember of heart that pump blood throughout the body. Ventricles have thicker wall than Atrium.  Pulmonary Circulation- Blood flow to lungs for oxygen enrichment.  Systemic Circulation- Oxygen enriched blood flow to body parts.  Human Heart Blood flow in human heart- Deoxygenated Blood(enters via Vena Cava) → Right Atrium → Right ventricle → Lung(via Pulmonary Artery) → Left Atrium(via Pulmo...