Historical philosophical, theoretical, and legal foundations of special and i...
Programming C Part 01
1. Dhaka University of Engineering & Technology, (DUET) Gazipur
Department of Textile Engineering
Course NO: CSE- 3702
Course Name: Computer Applications and Programming
(Sessional)
Date of Submission:21-03-2021
Experiment No: 01
Name of the Experiment: Introduction to C Programming.
Submitted To
Mr. Khawja Imran
Masud
Lecturer,
Department of CSE,
DUET
Submitted By
Name: Md. Rasel mondal
Student ID: 175013
Year/Semester: 3/1
Session: 2019-20
2. Report No: 01
Report Name: Introduction to C Programming.
1.0 Objectives:
1. To know about C programming.
2. To know about Hello world program.
3. To know how to calculate summation, subtraction and multiplication
of two numbers in C programming.
2.0 Theory:
2.1 Introduction:
C programming is considered as the base for other programming languages, that is
why it is known as mother language. C is a procedural programming language. It
was initially developed by Dennis Ritchie in the year 1972. It was mainly
developed as a system programming language to write an operating system. The
main features of C language include low-level access to memory, a simple set of
keywords, and clean style, these features make C language suitable for system
programming’s like an operating system or compiler development.
Many later languages have borrowed syntax/features directly or indirectly from C
language. Like syntax of Java, PHP, JavaScript, and many other languages are
mainly based on C language. C++ is nearly a superset of C language (There are
few programs that may compile in C, but not in C++).
2.2 C - Basic Syntax:
2.2.1 Tokens in C
A C program consists of various tokens and a token is either a keyword, an
identifier, a constant, a string literal, or a symbol. For example, the following C
statement consists of five tokens −
printf("Hello, World! n");
The individual tokens are −
3. printf
(
"Hello, World! n"
)
;
2.2.2 Semicolons
In a C program, the semicolon is a statement terminator. That is, each individual
statement must be ended with a semicolon. It indicates the end of one logical entity.
Given below are two different statements −
printf("Hello, World! n");
return 0;
2.2.3 Comments
Comments are like helping text in your C program and they are ignored by the
compiler. They start with /* and terminate with the characters */ as shown below −
/* my first program in C */
You cannot have comments within comments and they do not occur within a string
or character literals.
2.2.4 Identifiers
A C identifier is a name used to identify a variable, function, or any other user-
defined item. An identifier starts with a letter A to Z, a to z, or an underscore '_'
followed by zero or more letters, underscores, and digits (0 to 9).
C does not allow punctuation characters such as @, $, and % within identifiers. C
is a case-sensitive programming language. Thus, Manpower and manpower are
two different identifiers in C. Here are some examples of acceptable identifiers −
mohd zara abc move_name a_123
myname50 _ _temp j a23b9 retVal
2.3 Data Types:
Here’s a table containing commonly used types in C programming for quick
access.
4. Type Size (bytes) Format Specifier
int at least 2, usually 4 %d, %i
char 1 %c
float 4 %f
double 8 %lf
2.4 Variables:
A variable is a name of the memory location. It is used to store data. Its value can
be changed, and it can be reused many times. It is a way to represent memory
location through symbol so that it can be easily identified. Let's see the syntax to
declare a variable: type variable list; The example of declaring the variable is given
below: int a; float b; char c Here, a, b, c are variables. The int, float, char are the
data types.
We can also provide values while declaring the variables as given below: int a=10,
b=20; //declaring 2 variable of integer type float f=20.8; char c='A'; Where
variables to be declared:
• Inside function (local variables)
• In the definition of function parameters (Formal parameters)
• Outside of all functions (global variables)
3.0 Program:
3.1 Hello World Program:
5. /* write a program that display Hello world */
#include<stdio.h>0
int main ()
{
printf("Name: Md. Rasel mondalnStudent ID: 175013nDepartment: Textile
EngineeringnUniversity: Dhaka University of Engineering and Technology,
GazipurnAddress: Jamalpur, Joypurhat, Rajshahi");
return 0;
}
Output:
3.2 Summation of two numbers:
#include <stdio.h>
int main ()
{
int num1, num2, summation;
printf("Enter the first number: ");
scanf("%d", &num1);
6. printf("Enter the second number:");
scanf("%d", &num2);
summation= num1+ num2;
printf("Summation of two number: %d", summation);
return 0;
}
Output:
3.3 Task:
#include <stdio.h>
int main()
{
int num1, num2;
int summation, subtraction, multiplication ;
7. printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number:");
scanf("%d", &num2);
summation = num1 + num2;
subtraction = num1 - num2;
multiplication = num1 * num2;
printf("The summation of the two numbers : %dn", summation);
printf("The subtraction of the two numbers : %dn", subtraction);
printf("The multiplication of the two numbers : %dn", multiplication);
return 0;
}
Output:
8. 4.0 Conclusion:
In this Experiment we know about basic function of C programming like
Hello world, subtraction of two numbers also know subtraction,
multiplication of two number. O hope this experiment will help in my
practical life.