Write the following functions that can be called by a C program:
Write a function to populate an array with random integers between 0 and 99. Use the following functions of which the prototypes are to be found in stdlib.h
• randomize() – use once to initialize the randomization process
• rand() – generates a random number between 0 and the maximum value for an integer. You can scale the values down by means of the modulus.
Write a function to remove duplicates from an array of integers.
Write a function to sort an array in ascending order .The following is a simple sorting algorithm -
. int arr[n];
-
int i, j, n, temp;
-
-
/* populate the array*/
-
-
for (i = 0; i < n-1; i++)
-
for (j = i+1; j < n; j++)
-
if (arr[i] > arr[j]) {
-
temp = arr[i];
-
arr[i] = arr[j];
-
arr[j] = temp;
-
}
-
Write a function that will merge the contents of two sorted (ascending order) arrays of type integer values, storing the results in an array output parameter (still in ascending order). The function should not assume that both its input parameter arrays are the same length, but can assume that one array does not contain two copies of the same value. The result array should also contain no duplicate values. Write a function to execute a binary search algorithm to search for a value in an array. Use the following algorithm -
int arr[n];
-
int low = 0, high = n, mid, value;
-
-
while (low < high) {
-
mid = (low + high) / 2;
-
if (arr[mid] < value)
-
low = mid + 1;
-
else
-
high = mid;
-
}
-
low will now be the index where value can be found.
Mar 14 '07
11 4173
i want a c coding for find a time complexity in sorting method?please help me.
Ganon11 3,652
Recognized Expert Specialist
Please ask your question in your own thread, rather than tacking it onto the end of another user's thread.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Johnny Meredith |
last post by:
Is there a function in VBA to convert a string to an array of characters. I'm
looking for the exact same functionality as the ToCharArray() method in C#.
If this functionality does not exist, do y'all have any pre-written code to
do this?
Psuedo-Hopeless Request-
Dear Microsoft: It would be cool if VBA had more robust string manipulation
functions like those in C#, which kick a*s.
TIA
|
by: Nadav |
last post by:
Hi All,
- I am working on a tool that manipulate managed assemblies, some of the
functionality provided by the tool require manipulating the metadata sections
of the managed assembly in a way it could still be loaded by the consuming
application ( concerning the manipulated assembly is a DLL ), The tool uses
the unmanaged profiling API to monitor the application being executed ( and
actively effect it ), for each assembly being loaded an...
|
by: Peter |
last post by:
Is there a fast way to move data from DataTable into double array, or do I have to spin through every record and column?
I have five tables and I need to merge these tables column wise, each table will have to same amount of records but might have different amount of columns.
So I need the first record form table1 and table2 and table3 and table4 and table5 to be in record 1 in my merged array or table.
Second record form table1 and...
|
by: Sheldon |
last post by:
Hi,
I have two arrays that are of the same dimension but having 3 different
values: 255, 1 or 2.
I would like to set all the positions in both arrays having 255 to be
equal, i.e., where one array has 255, I set the same elements in the
other array to 255 and visa versa. Does anyone know how to do this
without using for loops?
Sincerely,
|
by: rkk |
last post by:
Hi,
I have written a generic mergesort program which is as below:
---------------------------------------------------------
mergesort.h
-----------------------
void
MergeSort(void *array,int p,int r,int elemSize,int(*Compare)(const
void *keyA,const void *keyB));
| |
by: vssp |
last post by:
hai friends
I need one solution for multidimentional array merging option using php
Please send me any samples multidimensional array merging
__________________
Thanks
Vssp
|
by: Akhenaten |
last post by:
I have the following query I run to pull some data from the db. The
sql (when run on the db) returns 2 elements. However, if I var dump my
variable ($aidlook) then the first element in the array does not show
up.
$getaid = mysql_query("SELECT a_uid FROM `answers` WHERE `qid` =
$qid", $db);
$aidlook = mysql_fetch_array($getaid,MYSQL_NUM);
Doing a var dump returns: array(1) { = string(1) "4" }
|
by: Nathan Sokalski |
last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action
that I want to perform on each of the Array values is:
Private Function AddQuotes(ByVal value As String) As String
Return String.Format("'{0}'", value)
End Function
Basically, I just want to surround each value with single quotes. However, I
am having trouble getting this to work using the System.Array.ForEach
method. This may be partially because I am not very...
|
by: chiefychf |
last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge a,b,c into another array f.. I can do two arrays, but I have issues when trying to do all three and when I do the even/odd compare I only get 2 numbers processed.
here is some of the code...
//*******************Function...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |