DS QP
DS QP
Questions
Documentation Section
Preprocessor Directive Section
Link Section
Definition Section
Global Declaration Section
Main() Function Section
{
Declaration Part
Executable Part
}
Sub Program Section
Function 1
Function 2 User Defined Functions
Function N
Documentation Section:
The documentation section consists of a set of comment lines giving the name
of the program, the author, and other details.
This will help other programmers to understand your program code quickly. The
Documentation section contains the following information.
@Project Name
@Author Name
@Created Date
@Program Description, etc.
/* some comments */ – Whatever is inside /*——-*/ are not compiled and executed;
they are only written for user understanding or for making the program interactive by
inserting a comment line. These are known as multiline comments. Single line
comments are represented with the help of 2 forward slashes “//——”.
Preprocessor directives:
In a C program, the statements which are starting with the “#” symbol are
called preprocessor directives. The C program provides a lot of inbuilt preprocessor
directives that are handled by the pre-processor before the compiler starts execution.
Definition section:
The definition section defines all symbolic constants.
Subprogram Section:
The subprogram section contains all the user-defined functions that are called
in the main () function. User-defined functions are generally placed immediately after
the main () function, although they may appear in any order. All sections, except the
main () function section, may be absent when they are not required.
Statement: A statement is a line of code in a c program and every statement
should end with a semicolon “;”.
Return statement: The return statement is basically used in the c program to return
a value from a function. In C programming, we use functions to achieve modularity.
The basic organization of a computer involves several key components and their
interactions to perform various tasks. Here's an overview of the primary components
and their functions in a typical computer organization:
Storage Devices:
Storage devices, such as hard drives (HDDs) and solid-state drives (SSDs),
provide long-term, non-volatile storage for data and programs.
Unlike RAM, data on storage devices persists even when the computer is
powered off.
These devices typically use secondary storage media, like magnetic disks or
flash memory.
Input Devices:
Input devices, like keyboards, mice, touchscreens, and microphones, allow users
to interact with the computer by providing input data.
They convert user actions or data into digital signals that the computer can
process.
Output Devices:
Output devices, such as monitors, speakers, and printers, present
information to the user in a human-readable form.
They convert digital data generated by the computer into a format that can
be perceived by humans.
Motherboard:
The motherboard is the main circuit board that houses and connects all the
computer's components.
It contains the CPU socket, memory slots, expansion slots, and various
connectors for peripheral devices.
Expansion Cards:
Expansion cards are additional circuit boards that can be installed on the
motherboard to enhance a computer's capabilities.
Common examples include graphics cards, sound cards, and network interface
cards (NICs)
Bus System:
Buses are communication pathways that allow data and instructions to flow
between different components of the computer.
The system bus connects the CPU to memory and peripheral devices,
facilitating data transfer.
Program Counter:
Program Counter is a register in a computer processor that contains the
address (location) of the instruction being executed at the current time. As each
instruction gets fetched, the program counter increases its stored value by 1. After
each instruction is fetched, the program counter points to the next instruction in the
sequence. When the computer restarts or is reset, the program counter normally
reverts to 0.
Instruction Fetch:
During the execution of a program, the CPU needs to retrieve instructions from
memory to execute them. The PC is responsible for pointing to the memory location
(address) of the next instruction to be fetched.
Incrementing:
After an instruction is fetched, the PC is typically incremented to point to the
next memory address where the subsequent instruction is stored. In most computer
architectures, instructions are stored sequentially in memory, so incrementing the PC
by the appropriate number of bytes ensures that the CPU fetches the next instruction.
Branching:
The PC can also be modified by certain control instructions, such as branch
instructions. Branch instructions allow the CPU to change the value of the PC,
effectively altering the flow of program execution. This is how conditional statements,
loops, and function calls are implemented in a program. When a branch instruction is
encountered, the PC is set to a new address specified by the instruction.
Program Execution:
The CPU fetches the instruction at the memory address pointed to by the PC,
decodes the instruction, and executes it. This process repeats in a cycle, with the PC
continually advancing to the next instruction until the program's termination condition
is met.
There are many ways to solve most problems and also many solutions to
most problems.
Algorithm to add two numbers.
Step 1: Read two numbers n1 and
n2. Step 2: sum = n1 + n2
Step 3:
Print sum
Step 4:
Stop
Algorithm to find largest number from two numbers.
Step 1: Read two numbers n1 and
n2. Step 2: If n1 > n2 then
Big = n1
else
Big = n2
Step 3:
Print Big
Step 4:
Stop
Algorithm to find largest number from three numbers
Step 1: Read three numbers n1, n2
and n3. Step 2: If n1 > n2 and n1 >
n3 then
Big = n1
Else
If n2 > n1 and n2 >
n3 then Big = n2
else
Big = n3
Step 3: Print Big Step 4: Stop
Algorithm to find smallest number from three numbers.
Step 1: Read three numbers n1, n2
and n3 Step 2: If n1 < n2 and n1 < n3
then
Small = n1
Else If n2 < n1 and n2 < n3
then Small = n2
else
Small = n3
Step 3: Print Small Step 4: Stop
4. Explain the basic Data Types in “C”.
Data type is a special keyword used to allocate sufficient memory space for the
data, in other words Data type is used for representing the data in main memory
(RAM) of the computer.
In general every programming language is containing three categories of data
types. They are
Fundamental or primitive data types
Derived data types
User defined data types.
int a; // valid
a=10; // valid
a=10, 20, 30; // invalid
Here "a" store only one value at a time because it is primitive type variable.
Example
Here derived data type store only same type of data at a time not store
integer, character and string at same time.
Float 4 8
Double 8 16
Boolean category data types
Boolean category data type is used for representing or storing logical
values is true or false. In java programming to represent Boolean values or
logical values, we use a data type called Boolean.
In the above declaration, we define the enum named as flag containing 'N' integer
constants. The default value of integer_const1 is 0, integer_const2 is 1, and so on. We
can also change the default value of the integer constants at the time of the
declaration.
For example:
enum fruits{mango, apple, strawberry, papaya};
The default value of mango is 0, apple is 1, strawberry is 2, and papaya is 3.
If we want to change these default values, then we can do as given below:
enum
fruits{ ma
ngo=2,
apple=1,
strawberr
y=5,
papaya=7
,
};
Top-Down Approach:
Modularization: In the top-down approach, you start by defining the main function
or the high-level structure of your program. Then, you decompose the problem into
smaller functions or modules that each address a specific part of the problem.
Function Hierarchy: You create a hierarchy of functions, with the main function at
the top and lower-level functions at the bottom. The main function typically calls these
lower-level functions to accomplish the overall task.
Stepwise Refinement: You gradually refine each function, filling in the details and
implementing the logic for that particular part of the problem.
Testing: You can test each function independently to ensure that it works correctly.
This top-down approach makes it easier to isolate and fix issues in smaller, more
manageable pieces of code.
Integration: Finally, you integrate all the functions together to create the complete
program.
Bottom-Up Approach:
Start with Details: In the bottom-up approach, you begin by implementing small,
individual functions or components that perform specific tasks or calculations. These
functions are often created without a clear idea of how they will fit into the larger
program.
Emergent Structure: As you implement these individual functions, you begin to
identify common patterns or needs for coordination. The overall program structure
starts to emerge from the aggregation of these smaller components.
Testing: You test each individual function as you create it, ensuring that it works
correctly in isolation.
Assembly: You gradually assemble these functions into a coherent program
structure, creating the main function or control flow that utilizes the individual
components.
Refinement: As you integrate the components, you may need to refine and adapt
them to work together seamlessly.
Syntax:
if (conditional expression)
{
<statements>;
...;
...;
}
Example:
If n%2 evaluates to 0 then the "if" block is executed. Here it evaluates to 0 so
if block is executed. Hence "This is even number" is printed on the screen.
int n = 10;
if(n%2 = =
0){
printf("This is even number");
}
If-else Statement:
Syntax:
if (conditional expression) {
<statements>;
...;
...;
}
else{
<statements>;
....;
....;
}
Example:
If n%2 doesn't evaluate to 0 then else block is executed. Here n%2 evaluates to
1 that is not equal to 0 so else block is executed. So "This is not even number" is
printed on the screen.
int n = 11;
if(n%2 = =
0){
printf ("This is even number");
}
else{
printf ("This is not even number");
}
Else-if ladder
Statements which will be executed always as you can see in this else-if ladder,
conditions are evaluated from top. First condition-1 will be evaluated and if this is
true, the code inside the if block will be executed. If condition-1 is false, condition-2
will be evaluated. If condition-2 is true, the code inside that else if block will be
executed. If condition-2 is false, condition-3 will be evaluated. This will go on like this.
If none of the conditions are true, the code inside the else block will be executed.
Syntax:
If (condition-1) {
Statements which will be executed if condition-1 is true
}
else if (condition-2) {
Statements which will be executed if condition-2 is true
}
.
.
else if (condition-n)
{
Statements which will be executed if condition-n is true
}
else
{
Statements which will be executed if none of the conditions in condition-1,
condition2,…condition-n are true.
}
Syntax:
If(condition1)
{ If(conditio
n2) {
If(condition
3) {
Statements in condition3:
}
else
Statements in else;
}}
Example:
// Sample program to display the text by using NestedIf
int a=10,b=5,c=11;
if(a>0)
{
if(b>0)
{
if(c%2==0)
printf (" C value is
even"); else
printf (" C value is odd");
}
}
Switch Statement
This is an easier implementation to the if-else statements. The keyword
"switch" is followed by an expression that should evaluates to byte, short, char or int
primitive data types only. In a switch block there can be one or more labeled cases.
The expression that creates labels for the case must be unique. The switch expression
is matched with each case label.
Only the matched case is executed, if no case matches then the default statement (if
present) is executed.
Syntax:
switch (control expression)
{
case expression 1:
<stateme
nt>;
break
;
case expression 2:
<statement>;
break;
...
...
case expression n:
<statement>;
break;
default:
<statement>;
}//end switch
int day =
5; switch
(day)
{ case 1:
printf
("Monday");
break;
case 2:
printf ("Tuesday");
break;
case 3:
printf
("Wednesday");
break;
case 4:
printf ("Thursday");
break;
case 5:
printf
("Friday");
break;
case 6:
printf ("Saturday");
break;
case 7:
printf
("Sunday");
break;
default:
printf ("Invalid entry");
break;
}
Looping statements are the statements execute one or more statement repeatedly
several number of times. In C programming language there are three types of loops;
while, do-while and for loop.
while loop:
This is a looping or repeating statement. It executes a block of code or a
statement till the given condition is true. The expression must be evaluated to a
Boolean value. It continues testing the condition and executes the block of code.
When the expression results to false control comes out of loop.
Syntax:
while (test condition)
{
body of the loop
}
Example:
Here expression i<=10 is the condition which is checked before entering into
the loop statements. When i is greater than value 10 control comes out of loop and
next statement is executed. So here i contain value "1" which is less than number
"10" so control goes inside of the loop and prints current value of i and increments
value of i. Now again control comes back to the loop and condition is checked. This
procedure continues until i become greater than value "10". So this loop prints values
1 to 10 on the screen.
int i = 1;
//print 1 to 10
while (i <= 10)
{
printf("%d:",
i); i++;
}
Do-while loop:
This is another looping statement that tests the given condition past so you can say
that the do-while looping statement is a past-test loop statement. First they do block
statements are executed then the condition given in while statement is checked. So
in this case, even the condition is false in the first attempt, do block of code is
executed at least once.
Syntax:
do
{
<statement>;
...;
...;
}while (expression);
Example:
Here first do block of code is executed and current value "1" is printed then the
condition i<=10 is checked. Here "1" is less than number "10" so the control comes
back to do block. This process continues till value of i becomes greater than 10.
int
i =
1;
do
{
printf("%d:",
i); i++;
}while(i <= 10);
For loop:
This is also a loop statement that provides a compact way to iterate over a
range of values. From a user point of view, this is reliable because it executes the
statements within this block repeatedly till the specified conditions are true.
Syntax:
for (initialization; condition; increment or decrement)
{
<statement>;
...;
...;
}
Example:
Here num is initialized to value "1", condition is checked whether num<=10. If
it is so then control goes into the loop and current value of num is printed. Now num is
incremented and checked again whether num<=10.If it is so then again it enters into
the loop. This process continues till num>10. It prints values 1 to10 on the screen.
For Example −
double salary = balance[9];
The above statement will take the 10th element from the array and assign the
value to salary variable.
#include<st
dio.h> int
main()
{
int n[5]={0, 1, 2, 3, 4};
printf("%d", n[0]);
printf("%d", n[1]);
printf("%d", n[2]);
printf("%d", n[3]);
printf("%d", n[4]);
}
#include<st
dio.h> int
main()
{
int a[5],i;
printf("Enter Array Elements");
for(i=0;i<5;i++);
{
scanf("%d",&a[i]);
}
printf("The Elements are");
{
for(i=0;i<5;i++);
{
printf("%d",a[i]);
}
}}
Output:
strcat( ) Function :
strcat() function in C language concatenates two given strings. It concatenates
source string at the end of destination string.
Syntax: char * strcat (char * destination, const char * source);
Example:
strcat( str2, str1 ); - str1 is concatenated at the end of str2.
strcat( str1, str2 ); - str2 is concatenated at the end of str1.
strlen( ) Function :
strlen( ) function is used to find the length of a character string.
Example: int n;
char st[20] = “Seshu”;
n = strlen(st);
This will return the length of the string 5 which is assigned to an integer variable n.
Note that the null character “\0‟ available at the end of a string is not counted.
strcmp( ) Function :
strcmp( ) function in C compares two given strings and returns zero if they are
same. If length of string1 < string2, it returns < 0 value. If length of string1 >
string2, it returns > 0 value.
Syntax: int strcmp (const char * str1, const char * str2);
strcmp( ) function is case sensitive. i.e., “A” and “a” are treated as different
characters.
Example:
char name[20] =
“Seshu”; char
town[20] =
“Guntur”;
strcmp(name, town);
int n;
n = strcmp(name, town);
strlwr() function :
strlwr() function converts a given string into lowercase.
Syntax : char *strlwr(char *string);
strlwr() function is non standard function which may not available in standard library
in C
Example:
#include<stdio.h>
#include<string.h> int main()
{
char str[ ] = “HI to all”; printf(“%s\n”,
strlwr (str)); return 0;
}
Output:
hi to all
strupr() function :
strupr() function converts a given string into uppercase.
Syntax : char *strupr(char *string);
strupr() function is nonstandard function which may not available in standard
library in C.
Example:
#include<stdio.h>
#include<string.h> int main()
{
char str[ ] = “hi to all”; printf(“%s\n”,
strupr(str)); return 0;
}
Output:
HI TO ALL
strrev() function :
strrev() function reverses a given string in C language.
Syntax : char *strrev(char *string);
strrev() function is non standard function which may not available in standard
library in C.
Example :
char name[20]=”ftl”; then
strrev(name)= ltf
Example:
#include<stdio.h>
#include<string.h> int main()
{
char name[30] = “Hello”;
printf(“String before strrev( ) : %s\n”, name); printf(“String after strrev( ) :
%s”, strrev(name)); return 0;
}
Output:
String before strrev( ) : Hello
String after strrev( ) : olleH
The pointer in C language is a variable which stores the address of another variable.
This variable can be of type int, char, array, function or any other pointer. The size of
the pointer depends on the architecture. However, in 32-bit architecture the size of a
pointer is 2 bytes.
Consider the following example to define a pointer which stores the address of an
integer.
int n = 10;
int* p = &n; // Variable p of type pointer is pointing to the address of the variable n
of type integer.
Declaring a Pointer:
The pointer in c language can be declared using * (asterisk symbol). It is also
known as indirection pointer used to dereference a pointer.
Here the pointer variable stores the address of number variable, i.e., fff4. The value of
number variable is 50. But the address of pointer variable p is aaa3.
By the help of * (indirection operator), we can print the value of pointer variable p.
In this example, &x retrieves the memory address where the variable x is stored,
and the address is assigned to the pointer variable ptr.
For example:
int x = 10;
int *ptr = &x; // ptr holds the address of x
int value = *ptr; // *ptr dereferences the pointer to get the value stored at
that address (value will be 10)
Here, *ptr retrieves the value stored at the memory address held by the pointer
ptr.
Combined Use:
The address and dereference operators are often used together when working
with pointers.
For Example:
int x = 10;
int *ptr = &x; // ptr holds the address of x
*ptr = 20; // *ptr dereferences the pointer to access the value at
that address and assigns it a new value (x is now 20)
In this case, *ptr is used to access the value at the memory address held by the
pointer, allowing you to modify the value stored at that address.
Pointer Arithmetic:
In C, you can perform arithmetic operations on pointers. This is particularly
useful when working with arrays or dynamically allocated memory.
For Example:
int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr; // ptr points to the beginning of the array.
// Incrementing the pointer moves to the next element in the array.
ptr++; // Now, ptr points to the second element of the
array.
// Decrementing the pointer moves to the previous
element ptr--; // Now, ptr is back to the first element.
// Adding an integer to a pointer moves it forward by that many elements
ptr = ptr + 2; // Now, ptr points to the third element of the array.
The actual size of the increment or decrement depends on the data type the
pointer is pointing to. For instance, if ptr is a pointer to an int, incrementing ptr moves
it by the size of an int.
Address Arithmetic:
Address arithmetic involves performing arithmetic operations directly on
memory addresses.
For Example:
int x = 10;
int *ptr = &x; // ptr holds the address of x
malloc()
The name "malloc" stands for memory allocation.
The malloc() function reserves a block of memory of the specified number of
bytes.
Syntax of malloc()
ptr = (castType*) malloc(size);
Example
ptr = (float*) malloc(100 * sizeof(float));
The above statement allocates 400 bytes of memory. It's because the size of
float is 4 bytes. And, the pointer ptr holds the address of the first byte in the allocated
memory.
calloc()
The name "calloc" stands for contiguous allocation.
The malloc() function allocates memory and leaves the memory uninitialized,
whereas the calloc() function allocates memory and initializes all bits to zero.
Syntax of calloc()
ptr = (castType*)calloc(n, size);
Example:
ptr = (float*) calloc(25, sizeof(float));
The above statement allocates contiguous space in memory for 25 elements of
type float.
realloc()
If the dynamically allocated memory is insufficient or more than required, you
can change the size of previously allocated memory using the realloc() function.
Syntax of realloc()
ptr = realloc(ptr, x);
Here, ptr is reallocated with a new size x.
free()
Syntax of free()
free(ptr);
This statement frees the space allocated in the memory pointed by ptr.
Drawbacks of pointers in C:
Uninitialized pointers might cause segmentation(division) fault.
Dynamically allocated block needs to be freed explicitly. Otherwise, it
would lead to memory leak.
Pointers are slower than normal variables.
If pointers are updated with incorrect values, it might lead to memory
corruption.
Structure Union
You can use a struct keyword to You can use a union keyword to
define a structure. define a union.
Every member within structure is In union, a memory location is
assigned a unique memory location. shared by all the data members.
Changing the value of one data Changing the value of one data
member will not affect other data members member will change the value of other
in structure. data members in union.
It enables you to initialize several It enables you to initialize only the
members at once. first member of union.
The total size of the structure is the The total size of the union is the size of
sum of the size of every data member. the largest data member.
It is mainly used for storing various It is mainly used for storing one of
data types. the many data types that are available.
It occupies space for each and every It occupies space for a member
member written in inner parameters. having the highest size written in inner
parameters.
You can retrieve any member at a You can access one member at a
time. time in the union.
It supports flexible array. It does not support a flexible array.
A function is a group of statements that together perform a task. Every C program has
at least one function, which is main ().
In C, we can divide a large program into the basic building blocks known as function.
The function contains the set of programming statements enclosed by { }. A function
can be called multiple times to provide reusability and modularity to the C program. In
other words, we can say that the collection of functions creates a program.
Advantage of functions in C
By using functions, we can avoid rewriting same logic/code again and again in a
program.
We can call C functions any number of times in a program and from any place in
a program.
We can track a large C program easily when it is divided into multiple functions.
Reusability is the main achievement of C functions.
Function Aspects:
There are three aspects of a C function.
Function declarations A function must be declared globally in a C program to
tell the compiler about the function name, function parameters, and return
type.
Function call Function can be called from anywhere in the program. The
parameter list must not be different in function calling and function declaration.
Function definition It contains the actual statements which are to be
executed. It is the most important aspect to which the control comes when the
function is called. Here, we must notice that only one value can be returned
from the function.
Return Value:
A C function may or may not return a value from the function. If you don't
have to return any value from the function, use void for the return type.
Let's see a simple example of C function that doesn't return any value from the
function.
void hello()
{ printf("hello
c");
}
If you want to return any value from the function, you need to use any data
type such as int, long, char, etc. The return type depends on the value to be returned
from the function.
Let's see a simple example of C function that returns int value from the function.
int get(){
return 10;
}
In the above example, we have to return 10 as a value, so the return type is int.
If you want to return floating-point value (e.g., 10.2, 3.1, 54.5, etc), you need to use
float as the return type of the method.
float get(){
return 10.2;
}
Now, you need to call the function, to get the value of the function.
Different aspects of function calling:
A function may or may not accept any argument. It may or may not return any
value. Based on these facts, there are four different aspects of function calls.
#include<stdio.h>
void sum();
void main()
{
printf("\n Calculating the sum of two numbers:");
sum();
}
void sum() // Function without arguments and without return value.
{
int a,b;
printf("\nEnter two
numbers"); scanf("%d
%d",&a,&b); printf("The
sum is %d",a+b);
}
#include<stdio
.h> int
sum(int, int);
void main() {
int a,b,result;
printf("\n Calculating the sum of two numbers:");
printf("\nEnter two numbers:");
scanf("%d
%d",&a,&b); result =
sum(a,b);
printf("\nThe sum is : %d",result);
}
int sum(int a, int b) // Function with arguments and with return value
{
return a+b;
}
Functions can be invoked in two ways: Call by Value or Call by Reference. These
two ways are generally differentiated by the type of values passed to them as
parameters.
The parameters passed to the function are called actual parameters whereas
the parameters received by the function are called formal parameters.
Call by Value
In call by value method of parameter passing, the values of actual parameters
are copied to the function’s formal parameters.
There are two copies of parameters stored in different memory locations. One is the
original copy and the other is the function copy. Any changes made inside functions
are not reflected in the actual parameters of the caller.
Example:
The following example demonstrates the call-by-value method of parameter passing
// C program to illustrate call by
value #include <stdio.h>
// Function
Prototype void
swapx(int x, int y);
// Main
function int
main(){
int a = 10, b = 20;
// Pass by Values
swapx(a, b); // Actual Parameters
printf("In the Caller:\na = %d b = %d\n", a, b);
return 0;
}
// Swap functions that swaps
// two values
void swapx(int x, int y) // Formal Parameters
{
int
tem
p;
tem
p=
x; x
= y;
y = temp;
printf("Inside Function:\nx = %d y = %d\n", x, y);
}
Call by Reference
In call by reference method of parameter passing, the address of the actual
parameters is passed to the function as the formal parameters.Both the actual and
formal parameters refer to the same locations.
Any changes made inside the function are actually reflected in the actual
parameters of the caller.
Example:
The following C program is an example of a call-by-reference method.
// C program to illustrate Call by Reference
#include <stdio.h>
// Function
Prototype void
swap(int*, int*);
// Main
function int
main(){
int a = 10, b = 20;
// Pass reference
swap(&a, &b); // Actual Parameters
printf("Inside the Caller:\na = %d b = %d\n", a, b);
return 0;
}
// Function to swap two variables
// by references
void swap(int* x, int* y) // Formal Parameters
{
int
temp;
temp
= *x;
*x = *y;
*y = temp;
printf("Inside the Function:\nx = %d y = %d\n", *x, *y);
}
16. Define File. Explain File Operations and File Handling Functions in
C.
We may require some specific input data to be generated several numbers of times.
Sometimes, it is not enough to only display the data on the console.
The data to be displayed may be very large, and only a limited amount of data can be
displayed on the console, and since the memory is volatile, it is impossible to recover
the programmatically generated data again and again.
However, if we need to do so, we may store it onto the local file system which is
volatile and can be accessed every time. Here, comes the need of file handling in C.
File handling in C enables us to create, update, read, and delete the files stored
on the local file system through our C program.
Function Description
fopen() opens new or existing file
fprintf() write data into the file
fscanf() reads data from the file
fputc() writes a character into the file
fgetc() reads a character from file
fclose() closes the file
fseek() sets the file pointer to given position
fopen()
We must open a file before it can be read, write, or update. The fopen()
function is used to open a file. The syntax of the fopen() is given below.
fclose()
The fclose() function is used to close a file. The file must be closed after
performing all the operations on it.
Mode Description
fseek() function
The fseek() function is used to set the file pointer to the specified offset. It is
used to write data into file at desired location.
Syntax:
int fseek(FILE *stream, long int offset, int whence)
#include
<stdio.h> void
main()
{
FILE *fp;
fp =
fopen(“sss.txt","w+");
fputs("This is Seshu",
fp); fseek( fp, 7,
SEEK_SET );
fputs(“Harshitha", fp);
fclose(fp);
getch();
}
int main() {
int num, i, isPrime = 1;
if (num <= 1) {
isPrime = 0;
} else {
for (i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
isPrime = 0;
break;
}
}
}
if (isPrime)
printf("%d is a prime number.\n", num);
else
printf("%d is not a prime number.\n", num);
return 0;
}
int main() {
FILE *sourceFile, *targetFile;
char source[100], target[100];
char ch;
fclose(sourceFile);
fclose(targetFile);
return 0;
}