I want to display items as follows,
<td1> <td2> <td3> <td4>
1 7 13 19
2 8 14 20
3 9 15 21
4 10 16 22
5 11 17 23
6 12 18
I am getting data (from 1......23) in a single column from database. Now I want to run a loop which will display my single columns data in the above format.
Please tell me the for loop code using which I can display data in above format. Data can be more that 23 in production environment, So the logic should be as that it can handle any amount of data. I am using ASP.NET(C#).
Thanks
I think you could use asp:DataList and bind the data to it.
Here is an example of using datalist with RepeatDirection and RepeatColumns properties.
OK, here's a corrected version of Riho's loop:
int records = ... ; /* the number of records */
int cols = 4; /* the number of columns */
int rows = (records + cols - 1) / cols; /* nb: assumes integer math */
for (int row = 0; row < rows; ++row) {
print "<tr>";
for (int col = 0; col < cols; ++col) {
print "<td>";
int offset = col * rows + row;
if (offset < records) {
print data[offset];
} else {
print "nbsp;" /* nb: should have an & but markdown doesn't work */
}
print "</td>";
}
print "</tr>";
}
The cell is often necessary to ensure that the rendered HTML cell has the correct background. Missing cells or cells with no data in them aren't rendered the same as normal cells.
In pseudocode (didn't test it):
int recordnum=....; //get the total number of records
int col_length=recordnum/4;
for(int i=0;i<col_length;i++)
{ for(int j=0;j<4;j++)
print data[i+j*col_length] ;
print "\n";
}
Related
I'm trying to add items from a csv into a vector. Some of the items have 2 elements, some 3, some 4. The code is working fine for the first 3 elements, but when I try to add the fourth I get an out of range error.
int i = 1;
while (i < temp.size()) {
Course course;
course.courseId = temp[i][0];
course.name = temp[i][1];
if (!temp[i][2].empty()) {
course.prereq = temp[i][2];
/*if (!temp[i][3].empty()) {
course.prereq2 = temp[i][3];
}*/
}
courses.push_back(course);
i++;
cout << i;
}
Thank you.
I'm trying to write a trimmed mean kernel that takes as input a set of frames (~100). I'm thinking of using an insertion sort (of size ~8). This means that I'll need to read one float/ uint/ushort at a time from the input images and compare it against an 8-wide vector, shifting the elements up and inserting the new value at the correct spot (if necessary), with the largest value added to the mean.
I'm having difficulties finding a portable way of shifting the elements in the vector and inserting the new one at the correct spot. I know that AMD GPUs have ds_permute for example, but those are not portable, and I can't figure out a clever way of using arithmetic and relational operators to do it (since those operate only on their lane and AFAIK unaligned vector accesses are UB in OpenCL).
If you only have 8 items in your list then you could add some indirection and have an index table uchar[8]. You assign the pre-sorted elements values 0-7. As you perform the sort you don't rearrange those items, instead you insert their indices into the table.
To get the speedup you then need to store each index using 4 bits to that all 8 fit into a 32-bit word. Honestly, I don't think this will be faster in your case though.
float elements[8];
uint index_table = 0;
uint sorted_size = 0;
// insert elements[i]
void insert(uint i)
{
uint temp = index_table
for (j = 0; j < sorted_size ; ++j)
{
if (elements[i] < elements[temp & 0xf])
{
// Insert i
temp = (temp << 4) | i;
index_table = (index_table & (4 * j - 1)) | (temp << (4 * j));
return;
}
temp >>= 4;
}
// Insert at end
index_table |= i << 4 * sorted_size ;
}
void insertion_sort()
{
// We can skip the first iteration since the 1st element is always inserted at the start
for (sorted_size = 1; sorted_size < 8; ++sorted_size)
{
insert(sorted_size);
}
}
float ith_smallest(uint i)
{
return elements[(index_table >> 4 * i) & 0xf];
}
i want help with making a grid that have 10 rows across the screen and 20 down the screen using while and other loops.
The number range is from 1 - 50 this is my process so far
i tried doing this and it will print numbers from 1 to 50 down ths screen
this is my process so far:
for (int num=1; num <=50; num++) {
System.out.println(num);
}
Something like this?
String retval= "";
for (int num=1; num <=50; num++) {
retval +=num+"|";
if(num%10 == 0){
System.out.println(retval);
retval = "";
}
}
So I want to use Google spreadsheet to find how many times does five consecutive cells have a value greater than a given value in a row,but one cell cant be a part of two set of consecutive cells.For example i want to count the number of times a particular item was bought in a month for consecutive five days but if it was bought for 7 days at a stretch it will only be counted as one whereas if it is multiple of five it will be counted as many multiples of five.
For Ex:If cells 1-5 have a value greater than the given value it should give me a count of 1, but if cells 1-9 also are greater than the given value even then it should give me count of 1 but if 1-10 have a value greater than the given value then it should give me a count of 2.I hope this was clear.
I want to write this code in Google Drive using custom function, I tried writing a code in C.
*
int x; //no. of rows
int y; //no. of columns
int arr[x][y]; //array to store numbers
int count[x];
int i,j,k; //for loops
for(i=0;i<x;i++) //set count to 0 for all rows
count[x]=0;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
for(k=1;k<=5, j<y;k++, j++)
{
if(!arr[i][j]>0)
{
break;
}
else if(k==5 && arr[i][j]!<1)
{
count[i]++;
j--;
}
}
}
}
//display the count array now to see result.
*
You can do this without writing code. That's kinda the purpose of a spreadsheet.
You have one column, say column A, with the values.
In the next column, start a counter that increments each row if the value in the first column is >= your preset value, and reset the counter if not. The formula would be something like (for cell B2)
=IF(A2>=$E$1,B1+1,0)
In the next column, calculate the multiples of 5. For cell C2:
=IF(MOD(B2,5)=0,C1+1,C1)
Copy those cells down to the bottom of the list in column A, and the last value will be the count of values that exceeded cell $e1 a multiple of 5 consecutive times.
Another way using native Sheets functions:
=ArrayFormula((ROWS(A:A)-LEN(REGEXREPLACE(CONCATENATE(LEFT(A:A>=1)),"TTTTT","")))/5)
and using a custom function:
function countGroups(range, comparisonValue, groupSize) {
var v = comparisonValue || 1; // default to comparing to 1 if not specified
var n = groupSize || 5; // default to groups of 5 if not specified
var count = 0, counter = 0;
for (var i = 0, length = range.length; i < length; i++) {
if (range[i][0] >= v) {
counter++;
if (counter == n) {
counter = 0;
count++;
}
}
else
counter = 0;
}
return count;
}
enter code here![I'm using Turbo c++....whenever I assign values for a 2d array and try to display them....atleast one of the rows (or all of them) of the array won't be allocated with the proper values the user has entered. I ignored this because when the program was made to run for the 2nd time, it worked fine! But now array allocation itself isnt working properly. compiler error?
PROGRAM.... i've entered 5 rows and 2 column values....
for eg.
1 2
2 5
3 6
5 8
4 7
the above are inputs...
the output should be same as well...but it shows...
1 2
2 5
4 7
4 7
4 7
p.s. I know only to work with Turbo c++...so please dont suggest Dev c++
As a newbie, I could use some help. thanks!
THE CODE IS AS FOLLOWS
` #include
#include
void main()
{
float **arr;
cout<<"rows : ";
cin>>SIZE;
cout<<"col : ";
cin>>n;
arr=new float *[SIZE];
for(int Di=0;Di<n;Di++)
{
arr[Di]=new float[n];
}
cout<<"enter...";
for(int i=0;i<(SIZE);i++)
{
cout<<"\n";
for(int j=0;j<n;j++)
{
cout<<"\t";
cin>>arr[i][j];
}
}
for(int ii=0;ii<SIZE;ii++)
{
cout<<"\n";
for(int jj=0;jj<n;jj++)
{
cout<<"\t";
cout<<arr[ii][jj];
}
}
getch();
}`
The program allocates n rows instead of SIZE rows.
You want the loop
for (int Di = 0; Di < n; Di++)
to read
for (int Di = 0; Di < SIZE; Di++)