I need to write a code (in C99). The programe receives an input number (integer) 'n' and then a matrix sized n*n (matrix[n][n]), all numbers are integers. We're supposed to define the matrix's size with malloc. Now the program needs to sort the lines of the matrix (the number in each line), in a single function (!) this way:
even line index (0,2,4,6...): from small to big.
odds line index (1,3,5...): from big to small.
and then print it.
*note: first line is indexed 0, second line is 1, etc.
I was thinking to sort it with bubblesort function with the following if:
if(i%2==1)
do odds sorting.
else
do even sorting.
when i is the index of the row.
my problem is defining the malloc and how do I send the matrix to sorting.If needed I will attach my current (not so good (completly awful)) code and functions as well as an example of what the prog. supposed to do.
I am trying to simulate the logical circuits having NAND gates. I am reading the structure from .bench file. The structure of a circuit looks like below:
It can be seen that the inputs for Gate 22 are 10 and 16 which are also NAND gates. On the other hand, for gate 10, the inputs are 1 and 3 which are simple inputs. So, i need to sort the gates topologically. Although topological sort will not affect the output for this particular example but i have big circuits also in which topological sort is required. But we can use this simple example to do the topological sort.
My effort:I thought to create a map which will keep the information about the gate name and its indegree. But i am unable to proceed further.
Code: void Circuit::topologicalSort()//topological sorting (for the mixed circuits) { int counter = 0; std::map<string, int> unsortTopoList; //this list keeps a track of gate name and its Indegree for(int i=0; i<gates.size(); i++) {
Example radix sort function to sort an array of 64 bit unsigned integers. To allow for variable bin sizes, the array is scanned one time to create a matrix of 8 histograms of 256 counts each, corresponding to the number of instances of each possible 8 bit value in the 8 bytes of each integer, and the histograms are then converted into indices by summing the histograms counts. Then a radix sort is performed using the matrix of indices, post incrementing each index as it is used.
Code: typedef unsigned long long UI64; typedef unsigned long long *PUI64; PUI64 RadixSort(PUI64 pData, PUI64 pTemp, size_t count) { size_t mIndex[8][256] = {0}; /* index matrix */ PUI64 pDst, pSrc, pTmp; size_t i,j,m,n; UI64 u;
I've got the program for the most part except one part because it's basically wanting me to return 3 values from a single function and I'm unsure how to do this the way it wants me to. The rules:
Call the user-defined function to read in x in the series to be used for calculating the results. Pass a prompt for x as an input parameter, and return the validated x value to main.
After a valid x has been entered, call the same user defined function a second time, to read in y. Pass the prompt for y as an input parameter, and return the validated number of terms value to main.
After a valid y has been entered, call the same user-defined function a third time, to read in z. Pass the prompt for z as an input parameter, and return the validated z value to main.
So basically it consists of implementing a single turn for the game called 'pig' and printing out scores and probabilities of those scores. So this is what I have thus far :
int randomNum (int min, int max) { return min + rand () % (max - min + 1); } int singleTurn (int holdValue) { int totalRoll = 0; int score = 0; do { score = randomNum(1,6);
i need a function that will work for both dynamic and static implementations of a function to get the transverse of a matrix. so far, i have this
Code:
matrix transpose(matrix m) { int row, col; row = m.com_dim; col= m.row_dim; }
[code]....
this works well with my static implementation, but when i try it in dynamic it gives me errors. the function has to be the same for both dynamic and static implementation
I am doing a written lab in my programming class in which we must write the output for three lines in a function. However, when I enter the code in my compiler I only get error messages. I was just wondering what the outputs under snap, crackle and pop should be and why.
#include <iostream> using namespace std; void snap (int i, int j); void crackle (int &a, int &B)/>; void pop (int &e, int f); int main () { int i = 1, j = 2;
I'm doing an exercise that prints all input lines that are longer than 80 characters. I rather not use any libraries so I decided to write my own function that counts characters to use it in my main program. However when integrate things my function returns zero all the time.
Here is my full code:
/* Exercise 1-17 Write a program to print all input lines that are longer than 80 characters */
#include<stdio.h> /* Declarations*/ #define MAX_STRING_LEN 1000 int count_characters(char S1[]); int main() {
[Code] .....
So I was trying to debug my count_characters() function and this is the code if I was to run it seperately:
Code: #include <stdio.h> /* counts character of a string*/ main() { int nc = 0; int c; for (nc = 0; (c = getchar()) != ' '; ++nc); printf("Number of characters = %d ", nc); }
It is getting more and more annoying, everytime i progress the next hurdle is just bigger. The problem is i want to calculate inverse of a matrix but using .inv gives a matrix full of -1.#QNAN values so i decided to write one my self
a function which returns the inverse matrix but something strange happens.
when i debug through the function code it works well and check the matrix that will be returned and the elements are correct.
when the function is called and output matrix is resulted. the element of the matrix is different.
I am looking for function capable of converting square matrix of integers.Where to find such function? I know the algorythm but have no time to implemnt it.
I have the following void function devised to assign "+1" or "-1" to each element of a matrix at random. While the function does what I want, when I print the values of the matrix all are set to zero:
#include <vector> #include "aRand.h" #include <iostream> void initConfig(std::vector<std::vector<int> > premat, int nL, int nN) { int * pnRand; pnRand = 0;
[Code]...
The function pnRand_plus returns a pointer to an array of random numbers from 1 to 100, with seed time(NULL) + i. The values printed in main are zero, despite the values printed during the function run are fine (-1s and +1s).
Im suppose to make a "poor mans" variation to the Sort function built into unix. The program is suppose to read in a file and sort the contents of the file. So its a variation of the Unix Sort feature. I have remade the readLine function we were provided so that it doesnt use fgets. where to go from here, Not sure on how to make a sort function. Here are the reqirements of the program:
Code:
• Re-implement the readLine() function so that it no longer makes use of fgets(). Instead, process the input on a given line character-by-character.
• Provide code which will create a data structure similar to argv to hold all of the words to be sorted. Use malloc() to ensure that each entry has just the required number of bytes needed to store the words. The final entry in your array should be the NULL pointer.
• Implement a sort() function which will rearrange the words in sorted order. To swap two words in your array, note that only a pair of pointers need to move. The strings themselves, once established, will never move. Heres what i have:
Code:
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINES 1000 /* maximum number of reminders */ #define WORD_LENGTH 10 /* max length of reminder message */
I have a matrix that contains zero and nonzero elements. I want to do a function that return 3 arrays.
The first one is for nonzero elements the second array contains the corresponding row numbers of each nonzero element the third array contains the corresponding column numbers of each nonzero element.
I've been trying to get my matrix multiplication program to run a few different ways. My assignments wants me to run it statically using chunks, but we're not supposed to use OpenMPs scheduler. So I'm not sure how that's possible. And secondly, we have to run it dynamically using locks/unlocks.
I just want to know the code of the program: Write code to accept matrix as aurgument and display its multiplication matrix which return its multiplication matrix.
I need to write a standalone sort function, which will take a linked list parameter and sorts it. The function is included in the main list class as friend class: Code: friend void sort (UList<T>&) I need to submit separate SortIS.h file for insertion sort. Here is my code:
Code:
#include <iostream> template <class T> void SortIS(UList<T>& list) { T temp; for (int i=1; i<list.size(); i++) { temp = list[i];
[Code]...
But the teacher said it didn't compile returning an error: "undefined reference to `void". What I am missing here?
I have this code(homework) i've been working on for several days i couldn't fix this error.
Question is: to write a sort program in c . Ineed to ask user for how many numbers to be sorted(n) ask again for values. The approach of sort is this:
1- store n in temporary var (temp) 2- search for largest number in array (0 until temp-1) 3- switch the fied that store largest with field indexed by (temp-1) 4- temp-- (decrement) 5- repeat steps 2 to 4 until temp is 1
the program then prints the numbers of array on screen in one line. I also should use a function getMax(int *list , int n) that determines largest value and returns its location in that array
list : is the array n: number of elements
Code: #include<stdio.h> int getMax(int *list, int n); //definition of getMax function int main(void) { int n,i;
[Code] .....
so i tried to sort this array
Code: input 2 7 9 4 3 1 6 5 The out put should be : 9 7 6 5 4 3 2 1 instead it prints : 7 9 2 4 3 1 6
i am currently using a comparator function in STL map for sorting date of string data type in ascending value. My dates are in this format for e.g. 15OCT1990, 13SEP1980 and etc. I am using substring to split up the string so that i can compare day, month, year separately. Right now i have problem comparing the month portion because alphabetically "FEB" comes before "JAN".How can I make a fixed substring position of (2,3) which is my month value to accept that string value of JAN comes before FEB,AUG,DEC for e.g?