Computer Programming (C) Lab Manual
Computer Programming (C) Lab Manual
MARDAN CAMPUS
LAB MANUAL
Computer Programming
Table of Contents
Lab Exercise#1: Title: Introduction to C Programming Language……………………………4
3
Lab Manual for C Programming
Lab Exercise #1
Title: Introduction to the C Programming Language
// Comments
Clrscr() function
Getch() function
Flowcharts:
Flowchart is a diagrammatic representation of an algorithm. Flowcharts are very helpful in writing
program and explaining program to others.
4
Lab Manual for C Programming
5
Lab Manual for C Programming
Write down the C program for the program flow given above and attach a screenshot of the
output.
START
READ
LENGTH &
BREADTH
CALCULATE
AREA A = L*B
DISPLAY
AREA
STOP
6
Lab Manual for C Programming
Program:
/* Header Files */
#include<stdio.h>
#include<conio.h>
void main()
{
int length=0, breadth=0;
int area=0;
clrscr();
printf("Enter the length and breadth of a rectangle");
scanf("%d%d", &length,&breadth);
area=length * breadth;
printf("Area of the Rectangle : %d", area);
getch();
}
Output:
Enter the length and breadth of a rectangle
4
5
Area of the Rectangle : 20
Task 2: Write a C program to find area and circumference of a circle by defining the value of
PI.
Flowchart
7
Lab Manual for C Programming
START
DEFINE VALUE
OF PI
READ VALUE
OF RADIUS 'R'
CALCULATE
AREA A =
CALCULATE C
=2
DISPLAY A &
C
STOP
Program
/* Header Files */
#include<stdio.h>
#include<conio.h>
#define PI 3.147
void main( )
{
float radius=0;
float area=0, circumf=0;
clrscr();
printf("Enter the radius of the Circle");
scanf("%f", &radius);
area = PI * radius * radius;
circumf = 2 * PI * radius;
printf("\nArea of the Circle : %f\n", area);
printf("Circumference of the Circle : %f", circumf);
8
Lab Manual for C Programming
getch();
}
Output:
6.5
Area of the Circle : 132.728
Circumference of the Circle : 40.839
9
Lab Manual for C Programming
Lab Exercise #2
The scanf function allows you to accept input from standard in, which for us is generally the keyboard.
The scanf function can do a lot of different things, but it is generally unreliable unless used in the
simplest ways. It is unreliable because it does not handle human errors very well. But for simple
programs it is good enough and easy-to-use. The simplest application of scanf looks like this:
scanf("%d", &b);
The program will read in an integer value that the user enters on the keyboard (%d is for integers, as is
printf, so b must be declared as an int) and place that value into b.
int uses %d
float uses %f
char uses %c
You MUST put & in front of the variable used in scanf. The reason why will become clear once you learn
about pointers.
10
Lab Manual for C Programming
Task1: Write a C program that takes two numbers as input from the user and displays their
sum.
Flowchart:
11
Lab Manual for C Programming
START
Printf("plz enter
length & breadth")
Scanf("%d \n %d",
&l, &b)
CALCULATE
AREA A = L*B
DISPLAY
AREA
STOP
12
Lab Manual for C Programming
Task 3: Write a C program to find area and circumference of a circle by defining the value of
PI.
Flowchart
START
DEFINE VALUE
OF PI
READ VALUE
OF RADIUS 'R'
CALCULATE
AREA A =
CALCULATE C
=2
DISPLAY A &
C
STOP
13
Lab Manual for C Programming
Lab Exercise# 3
Title: Conditional Statements (If/ Else)
Introduction
C programming provides two styles of flow control:
Branching
Looping
Branching is deciding what actions to take and looping is deciding how many times to take a certain
action. Branching is the topic under consideration and practice for today's tasks; while looping will be
dealt with in the upcoming exercises.
if statement:
This is the simplest form of the branching statements.
14
Lab Manual for C Programming
Task#1: Write a C program to find out if a number entered by the user, is positive or negative
number.
Flowchart:
START
READ ONE
NUMBER
TRUE FALSE
IS
NUMBER
>= 0?
WRITE WRITE
"NUMBER IS "NUMBER IS
POSITIVE" NEGATIVE"
STOP
15
Lab Manual for C Programming
Task 2: Write a C program that finds out whether a number is even or odd.
Flowchart:
START
READ A NUM
TRUE IS FALSE
NUM%2
= 0?
STOP
16
Lab Manual for C Programming
Task# 3: Write a program that reads the three sides of a triangle and tells the type of
triangle.
Flowchart:
START
READ THREE
SIDES A,B,C OF
TRIANGLE
NO
IS (A=B OR A=C)
YES WRITE
OR
(B=A OR B=C) "TRIANGLE IS
OR
(C=A OR C=B) ?
ISCOSCELES"
NO
WRITE
"TRIANGLE IS
SCALENE"
STOP
17
Lab Manual for C Programming
Lab Exercise # 4
Title: Nested If/Else Algorithms
Introduction:
Getting more involved in C programming, you will find out that you have to deal with problems that
require extensive logical reasoning and decision making. For this, at times you need to apply conditional
logic within an already applied if/else structure.
This will be illustrated with the help of the following tasks, developing the logic of which will help you
understand the phenomenon.
START
READ THREE
NUMBERS A, B & C
NO NO YES YES
B>C A>B A>C
? ? ?
YES NO
WRITE WRITE
"B is greatest" "A is greatest"
WRITE WRITE
"C is greatest" "C is greatest"
END
18
Lab Manual for C Programming
START
READ MARKS OF 5
SUBJECTS
DISPLAY
PERCENTAGE
YES
WRITE
IS perc>= 90?
"A+ Grade"
?
NO
YES WRITE
IS perc>= 85?
"A Grade"
?
NO
YES
WRITE
IS perc>= 70?
"B Grade"
?
NO
YES
WRITE
IS perc>= 60?
"C Grade"
?
YES
WRITE
IS perc>= 50?
"D Grade"
?
NO
WRITE
"FAIL !"
END
19
Lab Manual for C Programming
Lab Exercise # 5
Title: For Loops in C Programming
Introduction:
Loops cause program to execute the certain block of code repeatedly until test condition is false. Loops
are used in performing repetitive task in programming. Consider these scenarios:
1. for loop
2. while loop
3. do...while loop
20
Lab Manual for C Programming
Task1: Take your name and roll number as inputs and display them 7 times on the screen
using for loop.
Flowchart:
START
i=0
char name[10]
int roll_no
i++
YES
IS
i < 7?
NO
END
21
Lab Manual for C Programming
Task 2: Display the first ten positive integers, using for loop.
Flowchart:
START
int i = 1
DISPLAY i
i++
YES
IS
i <= 10?
NO
END
22
Lab Manual for C Programming
START
int i = 1
int fact = 1
int N
READ N
Fact = fact* i
i++
IS YES
i <= N?
NO
DISPLAY fact
END
23
Lab Manual for C Programming
Lab Exercise # 6
Title: Decision-Making in C using Switch-Case Statements
Introduction:
The switch and case statements help control complex conditional and branching operations.
The switch statement transfers control to a statement within its body.
Control passes to the statement whose case constant-expression matches the value of switch
( expression ). The switch statement can include any number of case instances, but no two case
constants within the same switch statement can have the same value. Execution of the statement body
begins at the selected statement and proceeds until the end of the body or until a break statement
transfers control out of the body.
24
Lab Manual for C Programming
Task1: Write a C program to perform a desired arithmetic operation using switch statement
and declaring choice as char data type.
Flowchart:
START
READ 2
NUMBERS A & B
READ OPCODE
(+ for addition, - for
subtraction, * for
multiplication, / for
division)
+ /
OPCODE
- *
YES
RESULT= B=0
A +B ?
RESULT= RESULT=
NO
A-B A *B
RESULT=
A/B
WRITE
"RESULT"
WRITE
"ERROR:
END
Denominator is 0"
25
Lab Manual for C Programming
START
NO YES
disc =
0?
YES flag = 0
disc >
0?
NO
flag = 1
flag = 2
26
Lab Manual for C Programming
Flag=?
1
0
2
√ ⁄ root2 = root1
√ ⁄
DISPLAY
root1 and root2
END
27
Lab Manual for C Programming
START
READ choice
(1 for area of triangle
2 for area of square
3 for area of circle)
1 Choice
2
?
READ READ
3
Base & hieght length
READ
radius
Area =
(1/2)*base*hieght Area = pi*radius*radius
Area = pi*radius*radius
DISPLAY
"Area of DISPLAY
DISPLAY "Area of Circle"
Triangle"
"Area of Circle"
END
28
Lab Manual for C Programming
Lab Exercise # 7
Title: While Loops in C Programming
Introduction:
while (test expression) {
statement/s to be executed.
The whi l e loop checks whether the test expression is true or not. If it is true, code/s inside the body
of while loop is executed,that is, code/s inside the braces { } are executed. Then again the test
expression is checked whether test expression is true or not. This process continues until the test
expression becomes false.
29
Lab Manual for C Programming
Task 1: Write a c program that uses while loop to find the factorial of a number.
Flowchart:
START
Fact = 1
READ
N
i =N
i >0
NO
?
YES
Fact = fact * i
i--
WRITE
"fact"
STOP
30
Lab Manual for C Programming
31
Lab Manual for C Programming
Lab Exercise 8
Title: Programming in C with Do-While Loops
Introduction:
In C, do...while loop is very similar to while loop. Only difference between these two loops is that, in
while loops, test expression is checked at first but, in do...while loop code is executed at first then the
condition is checked. So, the code are executed at least once in do...while loops.
do {
some code/s;
At first codes inside body of do is executed. Then, the test expression is checked. If it is true, code/s
inside body of do are executed again and the process continues until test expression becomes
false(zero).
32
Lab Manual for C Programming
Task 1: Write a C program to enter all numbers entered by a user until user enters 0.
Flowchart:
START
int sum = 0
int num
READ
num
Sum+= num
num YES
≠
0?
NO
WRITE
"sum"
STOP
33
Lab Manual for C Programming
Task 2:
Write a program to find the HCF and LCM of two numbers.
Algorithm:
HCF:
In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf),
or highest common factor (hcf), of two or more integers (at least one of which is not zero), is the largest
positive integer that divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4.
LCM:
In arithmetic and number theory, the least common multiple (also called the lowest common
multiple or smallest common multiple) of two integers a and b, usually denoted by LCM(a, b), is the
smallest positive integer that is divisible by both a and b
Flowchart:
START
READ 2
NUMBERS A & B
TEMP1 = A
TEMP2 = B
REM = A%B
A =B
B = REM
34
Lab Manual for C Programming
NO
WRITE
"HCF = A"
LCM =
(TEMP1*TEMP2)/A
WRITE
"LCM"
STOP
35
Lab Manual for C Programming
Lab Exercise # 9
Title: Built-in Functions in C
Introduction:
#include<ctype.h>
START
int a
float b
char c
double d
long int q
DISPLAY
SIZEOF a
DISPLAY
SIZEOF b
DISPLAY
SIZEOF c
DISPLAY
SIZEOF d
DISPLAY
SIZEOF q
STOP
36
Lab Manual for C Programming
Task 2: Write a C program to find whether a entered character is a number or digit using
both ASCII values and built-in functions.
START
char ch
READ ch
YES
('a' <= ch <= 'z')
OR WRITE
('A' <= ch <= 'Z') "ch is alphabet"
?
NO
YES WRITE
48 <= ch <= 56
? "ch is number"
NO
WRITE
"Invalid Character"
STOP
37
Lab Manual for C Programming
START
char ch
READ ch
YES
Isalpha(ch) > 0 WRITE
? "ch is alphabet"
NO
YES WRITE
Isdigit(ch) < 0
? "ch is number"
NO
WRITE
"Invalid Character"
STOP
38
Lab Manual for C Programming
Task 3: Write a C program to convert a lower case alphabet to uppercase and vice-versa
using both ASCII values and built-in functions.
Flowchart:
START
char ch
READ ch
YES
('a' <= ch <= 'z')
ch = ch - 32
?
WRITE
"Uppercase: ch"
NO
NO WRITE
"Lowercase: ch"
WRITE
"Invalid Character"
STOP
39
Lab Manual for C Programming
START
char ch
READ ch
YES WRITE
Islower(ch)
"Uppercase",
? toupper(ch)
NO
WRITE
YES
Isdigit(ch) < 0 "Lowercase",
? tolower(ch)
NO
WRITE
"Invalid Character"
STOP
40
Lab Manual for C Programming
Lab Exercise # 10
Title: User-Defined Functions in C
Introduction:
Function prototype (declaration):
Every function in C programming should be declared before they are used. These type of declaration are
also called function prototype. Function prototype gives compiler information about function name,
type of arguments to be passed and return type.
In the example, int add(int a, int b); is a function prototype which provides following information
to the compiler:
Function prototype are not needed if user-definition function is written before main() function.
Function call
Control of the program cannot be transferred to user-defined function unless it is called (invoked).
In the above example, function call is made using statement add(num1,num2); from main(). This make
the control of program jump from that statement to function definition and executes the codes inside
that function.
Function definition
Function definition contains programming codes to perform specific task.
Syntax of function definition
return_type function_name(type(1) argument(1),..,type(n) argument(n))
{
41
Lab Manual for C Programming
Example:
42
Lab Manual for C Programming
Task 1: Write a program with a function named swap() that takes input in two variables a
and b, and swaps their values.
Flowchart:
START
READ a, b
DISPLAY a, b
BEFORE
SWAPPING
swap(a,b)
END
43
Lab Manual for C Programming
START
int temp
temp = num2
num2 = num1
num1 = temp
DISPLAY a, b
AFTER
SWAPPING
STOP
44
Lab Manual for C Programming
Lab Exercise # 11
Title: More on User Defined Functions
Task 1: Write a C program in which define a function that returns greater of two numbers
inputted by user.
Flowchart:
START
Int I,j,k
READ i,j
Call
Larger(int a, int b)
DISPLAY k
END
45
Lab Manual for C Programming
Larger(a,b)
YES
Is
RETURN a
a> b?
NO
RETURN b
END
Task 2: Write a C program that uses pre-defined functions to convert celcius temperateure to
farenheit and vice versa.
The functions shall be able to perform the following calculations on the temperatures read as F in
farehnheit and C in celcius.
For conversion:
F=9.0/5.0*c+32
C=5.0/9.0*(F-32)
Algorithm:
2. Convert the Centigrade to Fahrenheit using the conversion function you defined outside the
main block.
46
Lab Manual for C Programming
7. Stop
Flowchart:
START
Factorial (N)
READ N
Call
F = factorial(N) Is RETURN
N<2? N*factorial(N-1)
B RETURN N
DISPLAY F
B
END
47
Lab Manual for C Programming
Lab Exercise # 12
Title: Arrays in C Programming
Introduction:
There are times while writing C code, you may want to store multiple items of same type as contiguous
bytes in memory so that searching and sorting of items becomes easy. For example:
Storing a string that contains series of characters, like storing a name in memory.
C programming language provides the concept of arrays to help you with these scenarios. An array is a
collection of same type of elements which are sheltered under a common name. An array can be
visualised as a row in a table, whose each successive block can be thought of as memory bytes
containing one element. Look at the figure below:
+===================================================+
| elem1 | elem2 | elem3 | elem4 |
+===================================================+
The number of 8 bit bytes that each element occupies depends on the type of array. If type of array is
‘char’ then it means the array stores character elements. Since each character occupies one byte so
elements of a character array occupy one byte each.
char arr[5];
An array can be initialized in many ways as shown in the code -snippets below.
int arr[10];
int i = 0;
for(i=0;i<sizeof(arr);i++)
48
Lab Manual for C Programming
Strings in C language are nothing but a series of characters followed by a null byte. So to store a string,
we need an array of characters followed by a null byte. This makes the initialization of strings a bit
different. Let us take a look:
Since strings are nothing but a series of characters so the array containing a string will be containing
characters
In the above declaration/initialization, we have initialized array with a series of character followed by a
‘\0′ (null) byte. The null byte is required as a terminating byte when string is read as a whole.
Now we know how to declare and initialize an array. Let's understand, how to access array elements. An
array element is accessed as:
int arr[10];
int i = 0;
for(i=0;i<sizeof(arr);i++)
int j = arr[5]; // Accessing the 6th element of integer array arr and assigning
its value to integer 'j'.
Note that for an array declared as int arr[5]. The five values are represented as: arr[0] arr[1] arr[2] arr[3]
arr[4] and not arr[1] arr[2] arr[3] arr[4] arr[5]
49
Lab Manual for C Programming
Task 1: Write a program that declares an array of 5 integers and displays the elements of the
array using a loop.
Flowchart:
START
Int arr[5] =
{1,2,3,4,5}
DISPLAY
"Element I of array is
arr[i]"
END
Task 2: Write a C program that uses array and for loop and does the following jobs:
Takes the size of the array
50
Lab Manual for C Programming
Task 3: Read 3 subject marks of 4 students. Write a program to calculate and display the
total marks of each student. Use a 2D (two-dimensional) array to
Algorithm:
1. Define main Function.
2. Declare all variables in specified data type.
3. Get the details for 4 students. R.no & Name of the students using a
single dimensional array.
4. And a inner for loop is to be used to get 3 marks of each students.
5. Calculate the total marks and store it in a 2-D array variable marks[i][j];
6. Display all the details of 4 students.
51
Lab Manual for C Programming
Name : abc
Sub0 89
Sub1 78
Sub2 82
Total Marks :249
Average :83.00
Student No 1
Rno : 1002
Name : xyz
Sub0 76
Sub1 80
Sub2 83
Total Marks :239
Average :79.66
Student No 2
Rno : 1003
Name : rst
Sub0 89
Sub1 90
Sub2 91
Total Marks :270
Average :90.00
Student No 3
Rno : 1004
Name : pqr
Sub0 86
Sub1 56
Sub2 73
Total Marks :215
Average :71.66
Flowchart:
52
Lab Manual for C Programming
START
For i=0 to 3
Sum[1] = 0
READ regno[i],
name[i]
For j= 0 to 3
READ mark[i][j]
Avg = sum/10
For i=0 to 3
DISPLAY regno[i]
A
C B
53
Lab Manual for C Programming
C A B
For j= 0 to 3
PRINT mark[i][j]
END
54
Lab Manual for C Programming
Lab Exercise # 13
Title: Array Search Algorithms
Introduction:
Linear Search:
is used to find whether a given number is present in an array and if it is present then at what
location it occurs. It is also known as sequential search. It is very simple and works as follows:
We keep on comparing each element with the element to search until the desired element is
found or list ends.
Linear Search:
Binary Search:
A binary search or half-interval search algorithm finds the position of a specified input value (the
search "key") within an array sorted by key value. For binary search, the array should be
arranged in ascending or descending order. In each step, the algorithm compares the search key
value with the key value of the middle element of the array. If the keys match, then a matching
element has been found and its index, or position, is returned. Otherwise, if the search key is
less than the middle element's key, then the algorithm repeats its action on the sub-array to the
left of the middle element or, if the search key is greater, on the sub-array to the right. If the
remaining array to be searched is empty, then the key cannot be found in the array and a special
"not found" indication is returned.
55
Lab Manual for C Programming
START
B
Int arr[20], int i=0, size = 0,
key = 0, flag =0
Is NO PRINT
"ELEMENT
Flag NOT
READ ARRAY SIZE
== 1 ? FOUND"
FOR I = 0 to size
NO YES
Is Flag = 1
Key == arr[i] ?
56
Lab Manual for C Programming
Binary Search:
Implement the Binary Search technique on an array using the following steps:
START
B
IS
SHOW THE ELEMENTS
KEY == FLAG = 1
READ ELEMENT TO
ARR[MID] ?
SEARCH: KEY
END
57
Lab Manual for C Programming
Lab Exercise # 14
Title: Strings in C Programming
Introduction:
Algorithm:
1. Begin a program with a comment line.
2. Include Header Files for standard input output function.
3. Define main Function & Declare all variables required.
4. Assign the vowels to an array variable A* + = “aeiouAEIOU”
5. Get the String and store it in a variable in a nested for Loop
6. Check the given string is equal to the value assigned in the array variable.
7. This is done until the string becomes NULL(\o)
8. If the character in a string is equal increment the COUNT variable by 1.
9. Print the Count variable which gives the result.
Flowchart:
58
Lab Manual for C Programming
START
a[] = {"aeiouAEIOU"}
count = 0
FALSE
For j =0 to 9
TRUE
FALSE
IS
Str[1] = a[j]
?
TRUE
Count ++
A
PRINT THE
COUNT
END
59
Lab Manual for C Programming
Task 2: Write a program that finds out whether a string is a palindrome or not.
A string is said to be a palindrome if the string read from left to right is equal to the string read from
right to left. For example, ignoring the difference between uppercase and lowercase letters, the
string"iTopiNonAvevanoNipoti" is a palindrome, while the string "iGattiNonAvevanoCugini" is not so.
Algorithm:
1. Define main Function & Declare all variables required.
2. Let flag =0
3. Read a String and Find the Length of the String as n.
4. Using a for loop check the character str[i] and str[n-1-i].
5. if equal continue the for loop until i=n/2
6. else set flag=1 and break the for loop.
7. If flag =0, Print “The string is Palindrome”
8. Else, Print “The string is not palindrome”
9. Stop
60
Lab Manual for C Programming
Flowchart:
START
Flag = 0
READ STRING
N = length (str)
FALSE
IS
Str{i] !=
str[n-1-i]
TRUE
Flag = 1
FALSE PRINT
IS "NOT
Flag = 0? PALINDROME"
TRUE
PRINT
"PALINDROME
"
END
61
Lab Manual for C Programming
Task 3: Read a string, which consists of both lower case characters and upper case
characters. Convert the lowercase character into upper case and vice versa. Display the new
string
Algorithm:
1. Define main Function & Declare all variables required.
2. Read a String and Find the Length of the String.
3. Check the characters ASCII value whether it lies between 97 and 122.
4. If the Condition is true
5. Change the ASCII value of the character by subtracting 32
6. Else check the ASCII value lies between 65 and 90
7. If the condition becomes true
8. Add 32 to the value for the character.
9. Repeat the step 4 & step 5 until the length of the string becomes NULL.
10. Print the result.
11. Stop.
Flowchart:
62
Lab Manual for C Programming
START
Len = strlen(str)
FALSE
For i=0 to len-1
TRUE
IS
FALSE
Str[i] >= 65
&&
Str[i] <= 90
TRUE
IS FALSE
Str[i] = str[i] + 32 Str[i] >= 97
A &&
Str[i] <= 122
TRUE
Str[i] = str[i] - 32
PRINT THE
STTRING
END
63
Lab Manual for C Programming
Lab Exercise # 15
Title: Pointer Basics
Introduction:
To better understand pointers, it sometimes helps to compare a “normal variable” with a pointer.
When a “normal variable” is declared, memory is claimed for that variable. Let’s say you declare an
integer variable MYVAR. Four bytes of memory is set aside for that variable. The location in memory is
known by the name MYVAR. At the machine level that location has a memory address.
A pointer differs in the way that a pointer is a variable that points to another variable. A pointer holds
the memory address of that variable. That variable contains a value. Pointers are also called address
variables because they contain the addresses of other variables.
Example: We have a piece of memory with a start address of 0×2000. That piece of memory contains a
value and is named MYEXAMPLE.
(This is in fact a variable). We also have a pointer MYPOINT. In this case, our pointer MYPOINT contains
the address 0×2000. This is the address of MYEXAMPLE so we say MYPOINT points to MYEXAMPLE. So
there is the pointer and the value pointed to. (You can use a pointer in a certain way to get the value at
the address to which the pointer points). Many novice programmers get pointers and their contents
confused.
So from now on it's advisable that you start every pointer name with the extension ptr_ . (for example:
ptr_MYPOINT).
int x;
int *ptr_p;
64
Lab Manual for C Programming
x =5;
ptr_p = &x;
Note: The integer x contains the value 5 on a specific address. The address of the integer x is copied in
the pointer ptr_p. So ptr_p points to the address of x. In short: ptr_p = &x; means, “Assign to ptr_p the
address of x.”
Pointer Dereferencing:
To access the value of the integer that is being pointed to, you have to dereference the pointer. The *
is used to dereference a pointer.
// Pointer Dereferencing
x = 5;
ptr_p = &x;
y = *ptr_p;
printf("%d\n", y);
Note: The integer x has a value of five. The pointer ptr_p gets the address of integer x.
The value pointed to is *ptr_p. (in this case five). So the integer y now contains the value of five.
Task 1:
Write a program to illustrate use of pointers in expressions.
#include<stdio.h>
#include<conio.h>
void main()
{
int *p, *q;
int m, n;
int res, res1;
clrscr();
printf("\nEnter two numbers");
scanf("%d%d",&m,&n);
p = &m;
q = &n;
res = (m + n) * (m * n);
printf("Result (using numbers) : %d\n",res);
res1 = (*p + *q) * (*p * *q);
printf("Result (using pointers) : %d\n",res1);
getch();
}
Output:
65
Lab Manual for C Programming
Task 2: Write a program that uses an int pointer and an int variable and displays the
variable's address.
Task 3: Write a program that takes user input into a variable and displays what the user
entered, via the variable's address.
66