0% found this document useful (0 votes)
14 views6 pages

Lab 1

CodeBlocks is a free integrated development environment used to create, edit, compile, debug and execute C/C++ programs. It allows users to create C program files, write code, and build and run programs in both Linux and Windows operating systems. The structure of a basic C program includes header files, source code with main functions, and format specifiers used in output statements. Sample programs demonstrate basics like displaying text, calculating sums and products, and computing circle properties.

Uploaded by

Iftimam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

Lab 1

CodeBlocks is a free integrated development environment used to create, edit, compile, debug and execute C/C++ programs. It allows users to create C program files, write code, and build and run programs in both Linux and Windows operating systems. The structure of a basic C program includes header files, source code with main functions, and format specifiers used in output statements. Sample programs demonstrate basics like displaying text, calculating sums and products, and computing circle properties.

Uploaded by

Iftimam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CodeBlocks:

CodeBlocks is an IDE (Integrated Development Environment) used to create, edit,


compile, debug and execute C/C++ programs in single place. It is very powerful IDE for
developing C projects.
It can be used in both Linux and Windows Operating System.
How to create C program file in CodeBlocks IDE:
1.Open CodeBlocks IDE and create a new file. Go to File -> New -> Empty file.

l
e

2.Click on “Build” Option

.
3.Save the file with .c extention.

4.Write your first code here and then click on “Build and Run” icon.

5.Output:
STRUCTURE OF „C‟ PROGRAM :

HEADER FILES

Header files are helping file of your C program which holds the definitions of various
functions and their associated variables that needs to be imported into your C program
with the help of pre-processor #include statement. All the header file have a '.h' an
extension that contains C function declaration and macro definitions. In other words, the
header files can be requested using the preprocessor directive #include. The default header
file that comes with the C compiler is the stdio.h.

Including a header file means that using the content of header file in your source program.

“#include<stdio.h>” is the basic header that must be added to a C program. Other headers
that can be needed are:

1. math.h: includes mathematical function like:

abs(),sqrt(),pow(),sin(),cos(),tan(),log(),ceil(),floor(),round() etc.

2. stdlib.h: includes function like:

rand(),atof(),atoll(),atoi() etc.

3. string.h: strcpy(), strcat(),strlen(),strcmp() etc.


4. ctype.h: isupper(), islower(),toupper(), tolower()

Can see more details of these functions from this website:

https://en.cppreference.com/w/c/header

FORMAT SPECIFIER IN C:
LAB EXERCISE #1

Objective(s):
To be familiar with syntax and structure of C- programming. To learn
problem-solving techniques using C

Program: Write a Program to calculate and display the volume of a CUBE having its height
(h=10cm), width (w=12cm) and depth (8cm).

Code: (Use comments wherever applicable)

//Following code is written and compiled in GCC

#include<stdio.h>

void main()
{
//start the program

int h,w,d,vol;
//variables declaration

h=10;w=12;d=8;
//assign value to variables

vol=h*w*d;
//calculation using mathematical formula

printf("The Volume of the cube is: %d",vol);


//display the volume

getch();
//end the main program
}

Output :
The Volume of the cube is: 960
SAMPLE PROGRAMS

(Students are to code the following programs in the lab and show the output to instructor/course
teacher)
Instructions

● Write comment to make your programs readable.


● Use descriptive variables in your programs(Name of the variables should show their purposes)

Programs List

1. Write a C program to display “This is my first C Program”.


2. Write a C program to add two numbers (2 and 6) and display its sum.
3. Write a C program to multiply two numbers (4 and 5) and display its product.
4. Write a C program to calculate area and circumference of a circle.

You might also like