0% found this document useful (0 votes)
66 views4 pages

C Programming Lab Manual for CSE 1102

The document is a lab manual for the CSE 1102 course at Rajshahi University of Engineering & Technology, focusing on basic input/output in C programming. It includes problem statements and practice problems that guide students through creating, compiling, and running C programs, as well as understanding key concepts like case sensitivity, comments, and arithmetic operations. The manual provides specific coding examples and exercises to reinforce learning.

Uploaded by

arafatshitul
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)
66 views4 pages

C Programming Lab Manual for CSE 1102

The document is a lab manual for the CSE 1102 course at Rajshahi University of Engineering & Technology, focusing on basic input/output in C programming. It includes problem statements and practice problems that guide students through creating, compiling, and running C programs, as well as understanding key concepts like case sensitivity, comments, and arithmetic operations. The manual provides specific coding examples and exercises to reinforce learning.

Uploaded by

arafatshitul
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

Heaven’s Light is Our Guide

Rajshahi University of Engineering & Technology


Department of Computer Science & Engineering

Lab Manual

Course Code: CSE 1102 (Sec A & C)


Course Title: Sessional based on CSE 1101
Module 1 [Basics Input/Output]: (for Week 1)

1. Problem Statement: Familiarize with Codeblocks


i) Create New Project
ii) Open Old Project
iii) Create Source file
iv) Save Source file
v) Compile .c file
iv) Run a .c file

2. Problem Statement:
i). Write the following C program in Codeblocks
ii). Compile the program and run

#include <stdio.h>
main()
{
/* My first program */
printf("Hello World! \n");
}

Now Read the following statements carefully and test it


 C is case sensitive. All commands in C must be lowercase.
 C has a free-form line structure. End of each statement must be marked with a
semicolon. Multiple statements can be on the same line. White space is ignored.
Statements can continue over many lines
 The C program starting point is identified by the word main().
 The two braces, { and }, signify the begin and end segments of the program. In general,
braces are used throughout C to enclose a block of statements to be treated as a unit.
COMMON ERROR: unbalanced number of open and close curly brackets.
 The purpose of the statement #include is to allow the use of the printf statement to
provide program output. For each function built into the language, an associated header
file must be included. Text to be displayed by printf() must be enclosed in double
quotes.
 printf()is actually a function (procedure) in C that is used for printing variables and text.
Where text appears in double quotes "", it is printed without modification. There are
some exceptions however. This has to do with the \ and % characters. These characters
are modifiers, and for the present the \ followed by the n character represents a newline
character.
 The program prints
Hello World!
 And the cursor is set to the beginning of the next line. As we shall see later on, what
follows the \ character will determine what is printed (i.e., a tab, clear screen, clear line,
etc.)
 /* My first program */
Comments can be inserted into C programs by bracketing text with the /* and */
delimiters. As will be discussed later, comments are useful for a variety of reasons.
Primarily they serve as internal documentation for program structure and functionality.
A single line comments can done by //

3. Practice Problem: Write a program to pirnt your name and address in different line by using
i) one printf()
ii) More than one printf()
iii) Use comments

4. Practice Problem: [store data into memory] Write the following programs and run.
i)
#include <stdio.h>
main()
{
int data;
data=10;
printf("%d",data);
}

ii)
#include <stdio.h>
main()
{
int a,b,s;
a=10; b=20;
s=a+b;
printf("s=%d",s);
}

5. Practice Problem: Write a program that stores two integers in x and y. Now write codes
to find i) x+y ii) x-y iii) x*y and iv) x/y

6. Practice Problem: Write a program that calculate the area of a triangle if three sides are
given.
Snapshot of the program
Enter Three sides: 3 4 5
Area=6.0
7. Practice Problem: Write a program that calculate the area of a triangle if three vertices
are given.
Snapshot of the program
Enter First vertex: 2 2
Enter Second vertex: 2 0
Enter Third vertex: 5 0
Area=3.0

8. Practice Problem: Write a program that calculate the total bill of a Fast Food Restaurant.
There are 4 types of items are available in the restaurant such as: 1) Burger ii) Sandwich iii)
Pizza and iv) Cold Drinks. Assume prices of Burger=200 Tk., Sandwich=75 Tk. , Pizza=750 Tk. And
Cold Drinks=40 Tk.

Snapshot of the program


Enter NO. of Burgers, Sandwiches, Pizzas, Cold Drinks: 1.0,1,3
Total Bill=1170
Payment=1200
Return=130

Common questions

Powered by AI

You can store integers in variables by declaring them and assigning values, as shown in int data where data=10 stores the value 10. To perform arithmetic operations, declare multiple integer variables, assign them values, and use arithmetic operators. For example, to find x+y, declare x and y, assign values, and use the + operator to compute the result .

Comments improve code readability and maintenance by providing explanations about code logic, purpose, and structure. They act as internal documentation, helping developers understand the code, especially in collaborative environments or after a period of time since the program was written .

To solve a billing problem, define variables to store the quantities of each item. Assign fixed prices to these variables and compute the total bill by multiplying quantities by their respective prices and summing the results. Finally, compute the change by subtracting the total bill from the payment amount as demonstrated in the program snapshot .

To create and execute a C program in Codeblocks, follow these steps: Create a new project, open or create a source file, write the program code, save the file, compile the .c file, and then run it. Common syntax mistakes to avoid include improper casing since C is case sensitive, missing semicolons at the end of statements, unbalanced curly braces, and incorrect or missing header file inclusion needed for functions such as printf .

Using one printf statement involves compiling strings and commands to print outputs on a single line. Multiple printf statements allow greater control over output formatting, such as printing on new lines or organizing data outputs clearly by breaking them into several parts .

The printf statement's functionality changes with the use of modifiers such as \ and %. The \ character followed by another character represents special formatting, such as a newline with \n. Comments in C, enclosed between /* and */, provide internal documentation to explain code structure and functionality, improving readability and maintenance .

Header files in C programs are crucial because they declare the interfaces to functions and macros used in the program. For example, stdio.h must be included for using the printf function, as it provides the necessary declarations to ensure correct compilation and function usage .

To calculate the area of a triangle given its three sides, use Heron's formula, which involves calculating the semi-perimeter and then using it to find the area. For vertices, use the formula involving differences and cross-product of coordinates to derive the area, as illustrated in the provided program examples .

Troubleshooting unbalanced curly braces requires checking if each opening brace has a matching closing brace. A systematic approach is to align braces and use consistent indentation. For missing semicolons, verify the end of each statement visually. IDE error messages often point out specific lines needing correction, which aids in resolving these issues effectively .

In C programming, white spaces are mostly ignored, which allows for flexible code formatting. This feature enables writing multiple statements on one line or spreading a single statement across multiple lines, thus enhancing readability and structuring of code .

You might also like