Alex
how does it effect my code?
to include header file only one time in one compilation unit
Alex
actually i was learning SPOOLING technique.
probably its about swap(you don`t have enough memory to store everything in RAM) so you use persistent storage
Anonymous
How to know that weather we have to use pragma or ": :"
they are two different things. https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html https://docs.microsoft.com/en-us/cpp/preprocessor/pragma-directives-and-the-pragma-keyword https://en.wikipedia.org/wiki/Pragma_once
@unchanted
to include header file only one time in one compilation unit
ok and if we use fork inside the code then ? will the clone again read the header file
Nils
That's why you have man pages preinstalled on most distros 🙃
Alex
man fork
this is not related to pragma once
PO
someone can tell me how can I sum each 3 element of an array in c?
Anonymous
ok and if we use fork inside the code then ? will the clone again read the header file
fork is a runtime thing. including a header file is a compile time thing
piggyho
(Thanks for the reply but I eventually ditched ncurses as I got my C snippet working)
ncurses is much harder to do and documentation could be better
@unchanted
#include<stdio.h> #include<unistd.h> int main() { if(fork()&&fork()) {fork();} printf("hello"); return 0; } what if i use pragma once here?
@unchanted
so the child will again read the header file
Anonymous
so the child will again read the header file
the very concept of a child (child process) is runtime
Nils
someone can tell me how can I sum each 3 element of an array in c?
int res = 0; for (int *element = numarray; element != numarray + 3; element++) { res += *element; }
piggyho
almost always you should use pragma once. however its compiler extension
goes at top of header. non standard. not a problem just beware
Alex
so the child will again read the header file
forget about child process, fork and clone consider: header.h void foo(); header2.h #include "header.h" header3.h #include "header.h" main.cpp #include "header2.h" #include "header3.h" int main() { } Problem: header.h is included two times in main.cpp. to fix this we add #pragma once to header.h
PO
int res = 0; for (int *element = numarray; element != numarray + 3; element++) { res += *element; }
[1][2][3] [4][5][6] [7][8][9] , they are all element of an array I have to sum each 3 element for example and divide per 3
@unchanted
this would be off-topic but can someone tell me a group where I can ask questions regarding computer architecture, OS, DBMS?
Anonymous
PO
It's not hard, find it out yourself 😉
I'm trying, It's a 2 dimensional array for (i = 0; i < raw; i++) for(j = 0; j < column; j++ ) matrix[i][j] = matrix[i][j] + matrix[i][j+1] + matrix[i][j+2] but It works just for first 3 elements not others.
PO
yes, because you add indices 0,1,2, then 1,2,3, then 2,3,4 and so on
I tried replace 1 and 2 with a=0, b=1 and c=2. And c +=3; a +=3; b+=3; after each time of loop but doesn't work
olli
I tried replace 1 and 2 with a=0, b=1 and c=2. And c +=3; a +=3; b+=3; after each time of loop but doesn't work
that's one option to solve it, have you changed your condition in the for loop? you're reading three times the elements now
olli
yep I've put j < column /3;
then it should work, can you share the code?
olli
where is the += 3 ? you basically haven't changed anything since you don't change a, b and c
Anonymous
Hi
Anonymous
I need halpe
Anonymous
nope, I'have to sum first 3 element and then second 3 element . . . in each raw
okay so if there is an extra element left in the row we should just discard it and proceed to next row?
Anonymous
okay
olli
but now you're accessing 3, 4, 5, 7, 8, 9, 11, 12, 13 (you don't want j + b you only want b)
Anonymous
It is required to write a program that will receive N և K non-negative integers at the input, then a sequence of N elements. The program must output "YES" as a result if the correct K of N numbers are greater than or equal to 123 և ‘NO’ otherwise. It is forbidden to use mass.
olli
and you should move the a += 3 after you access the field
PO
for example I have to sum 255+0+0 and 0+255+0 and 0+0+255 in first raw and in second 255+255+0 and 255+255+255 and 0+0+0
Anonymous
#include <iostream> int main() { unsigned N,K; std::cin >> N>> K; int i = 1; int count = 0; while ( i <= N){ int x; std::cin >> x; if( x>=123){ count ++; } if (cout== K) std::cout <<"YES"; else std::cout << "NO"; } }
Anonymous
Someting wrong
Anonymous
for example I have to sum 255+0+0 and 0+255+0 and 0+0+255 in first raw and in second 255+255+0 and 255+255+255 and 0+0+0
for (size_t i = 0; i != ROW; ++i) { for (size_t j = 0; j < COL; j += 3) { a[i][j] = a[i][j] + a[i][j + 1] + a[i][j + 2]; } }
Anonymous
Maximum Run Time Exceeded
Anonymous
Wrong
Anonymous
#include <iostream> int main() { unsigned N,K; std::cin >> N>> K; int i = 1; int count = 0; while ( i <= N){ int x; std::cin >> x; if( x>=123){ count ++; } if (count == K) std::cout <<"YES"; else std::cout << "NO"; } }
Anonymous
It is required to write a program that will receive an integer in the entry until 0 is entered. And the sum of the imported numbers will be displayed. It is forbidden to use mass.
Anonymous
#include <iostream> int main() { int i; std::cin >> i; do { std::cin >>i; i+=1; } while (i!=0); }
Pavel
#include <iostream> int main() { int i; std::cin >> i; do { std::cin >>i; i+=1; } while (i!=0); }
why you do i+1? you can have 2 variables here, one for sum and one for value, and I guess you don't need the first std::cin>>i; line
Anonymous
Yes
Anonymous
but everything that I write goes wrong. if you can write please
Anonymous
Correct code
Anonymous
It is required to write a program that will receive an integer in the entry until 0 is entered. And the sum of the imported numbers will be displayed. It is forbidden to use mass.
#include <iostream> auto main() -> int { long i=0; int input=-1; for(;input!=0;) { std::cin >>input; i+=input; } std::cout << i; }
Pavel
#include <iostream> int main() { int value; int sum = 0; do { std::cin >> value; sum += value; } while (value!=0); }
Anonymous
Maximum run time exceeded
Show the question
Anonymous
Not your interpretation of it
Anonymous
The actual question
Anonymous
Show the question
It is required to write a program that will receive an integer in the entry until 0 is entered. And the sum of the imported numbers will be displayed. It is forbidden to use mass.
Anonymous
Send a screenshot
Anonymous
I'm definitely aware of a site that says maximum runtime exceeded
Anonymous
Anonymous
Thanks
Anonymous
So
Mp
hello can any one help me with a code regarding the monte carlo method to integrate