LJ
This is have to input for score and number of items. For the output is tg/transmuted grade and equivalent grade
Anonymous
The result is wrong, means the value of c is coming wrong
Then please explain what are you try to do what output you expect etc.
Papa
Then please explain what are you try to do what output you expect etc.
I am adding the matrices A and B in C but the result is wrong
LJ
Then please explain what are you try to do what output you expect etc.
I need to write a program that accepts the score and number of items. Output the tg/transmuted and its quivalent. I have no idea for formula and how to print tg with equivalent
LJ
Using c++
Papa
Nothing wrong in code or logic.
Yeah sorry, the elements were not seprated by comma that's why it creates the problem, i am sorry bro
Ahmed
/
Anonymous
add return 0
and isn't it against the rules to post code like this?
Anonymous
at least use a code block
Hanz
Code::Block??
Hanz
mhm yes
Anonymous
Code::Block??
#include <iostream> int main(){ std::cout << "Hello, World!" << std::endl; return 0; } this is a code block.
Hanz
oh that is understandable
Anonymous
You mean monospace ?
yes, but no. I mean, telegram also calls it codeblock
LJ
I need to write a program that accepts the score and number of items. Output the tg/transmuted and its quivalent. I have no idea for formula and how to print tg with equivalent
#include<stdio.h> #include<conio.h> main() { float s, n, tg, eq; printf("Score : ", s); //input scanf("%f",&score); printf("\nNumber of items : ",n); \\input scanf("%f",&n); printf("\nTG : %d"); \\Output printf("\nEquivalent : " );\\Output tg=score *50/n + 50; }
LJ
I have no idea for formula😅 to print tg and eq of grade
Liang
hi
Liang
can someone help me solve the problem, I am stuck
Anonymous
can someone help me solve the problem, I am stuck
You want someone to write the whole code for you?
Liang
no
Liang
I write all the code ady, but the output is not expected
Liang
can you help me?
Satish
Hi Folks, anyone familiar with REGEX ( regular expressions) operation in C++ ? I want to know how I can generate Group 1 from Regex and test string?
Satish
For example, if someone visit regex101.com and if we enter regular expression and test string there, we will see result on right side whether its matches or not
Satish
if it matches, it gives additional information like " Match 1" and " Group 1" . I want to know how this Group 1 is getting calculated and want to develop its logic in C++..Anyone familiar please help🙏
Satish
you can use the standard library regex
Please share the regex library name you are familiar with.
Anonymous
Please share the regex library name you are familiar with.
the standard library regex > the name is regex
Satish
Ok.Thanks for the help.Let me try that.
Soham
Hey, I was just wondering how this website works? https://howsecureismypassword.net/ Is there any specific algorithm?
Adarsh
Can anyone tell algo to find factorial of large number?
Adarsh
long long int fact(int n) { if(n==0||n==1)return 1; return n*fact(n-1); } int main() { cout<<fact(50); return 0; }
Adarsh
Not getting output from this😅
B121065_Swoyam Siddharth Nayak
i guess you will have to use the string multiplication method
B121065_Swoyam Siddharth Nayak
https://www.geeksforgeeks.org/multiply-large-numbers-represented-as-strings/ refer this
B121065_Swoyam Siddharth Nayak
bro, if you get it, please tell me too
olli
Can anyone tell algo to find factorial of large number?
use an arbitrary-precision library, e.g. gmp void fact(int n){ int i; mpz_t p; mpz_init_set_ui(p,1); /* p = 1 */ for (i=1; i <= n ; ++i){ mpz_mul_ui(p,p,i); /* p = p * i */ } printf ("%d! = ", n); mpz_out_str(stdout,10,p); mpz_clear(p); }
meis
/get cbook
meis
/get ide
meis
/get money
Suka
Actually I'm not at your level 😶😶🙄🙄
its not about level but whatever you able to use gmp library in your project or not. if you're take c/cpp programming very serious then soon or later you will have to use this kind of library, rather then reinventing the wheel. gmp or boost for large integer (float perhaps?) storage or armandillo for linear algebra. sorry for my bad english.
Suka
Bro that's why i am here to know can i go step by step
and iam considered gmp is one of first step hehe. goodluck
Jan
I'm still *very much* a beginner though I'm aware that libs like those will be mandatory sooner or later if I want to actually do it properly
Anonymous
Useless flooding
Engineer
A compiler optimization does that mean it works on 64 bits of data at a time or does it mean it knows that a 32bit operations can be squeezed together?
Engineer
@thanks - I wanted to store some data in binary using a custom encryption to organise 16 bits for certain bits of information. Then the remaining 48 bits + 16 bits= to make the total 64bits.
Engineer
The 48 bits would initially be just a reference to a hash table
Engineer
It depends, do you have some specific case in mind?
Have you done this before? What use case would you recommend please?
.
/fuk
.
/Fukushima
.
/
Engineer
#include <stdint.h> #include <stdio.h> #include <string.h> #include <stdlib.h> uint64_t matching_bytes_in_word(uint64_t x, uint64_t y) { uint64_t xor_xy = x ^ y; // credit: mula // 7th bit set if lower 7 bits are zero const uint64_t t0 = (~xor_xy & 0x7f7f7f7f7f7f7f7fllu) + 0x0101010101010101llu; // 7th bit set if 7th bit is zero const uint64_t t1 = (~xor_xy & 0x8080808080808080llu); uint64_t zeros = t0 & t1; return ((zeros >> 7) * 0x0101010101010101ULL) >> 56; } uint64_t matching_bytes(const char * c1, const char * c2, size_t n) { size_t count = 0; size_t i = 0; uint64_t x, y; for(; i + sizeof(uint64_t) <= n; i+= sizeof(uint64_t)) { memcpy(&x, c1 + i, sizeof(uint64_t) ); memcpy(&y, c2 + i, sizeof(uint64_t) ); count += matching_bytes_in_word(x,y); } for(; i < n; i++) { if(c1[i] == c2[i]) { count++; } } return count; } uint64_t standard_matching_bytes(const char * c1, const char * c2, size_t n) { size_t count = 0; size_t i = 0; for(; i < n; i++) { if(c1[i] == c2[i]) { count++; } } return count; } void test() { size_t N = 100; char c1[N]; char c2[N]; for(size_t i = 0; i < 100000; i++) { for(size_t j = 0; j < N; j++) { c1[j] = (3*j + 7*j*i + 2 * i) %3; c2[j] = (5*j + 2 * i) %4; } if(matching_bytes(c1, c2, N) != standard_matching_bytes(c1, c2, N)) { abort(); } } } int main() { test(); }
Engineer
#include <stdint.h> #include <stdio.h> #include <string.h> #include <stdlib.h> uint64_t matching_bytes_in_word(uint64_t x, uint64_t y) { uint64_t xor_xy = x ^ y; // credit: mula // 7th bit set if lower 7 bits are zero const uint64_t t0 = (~xor_xy & 0x7f7f7f7f7f7f7f7fllu) + 0x0101010101010101llu; // 7th bit set if 7th bit is zero const uint64_t t1 = (~xor_xy & 0x8080808080808080llu); uint64_t zeros = t0 & t1; return ((zeros >> 7) * 0x0101010101010101ULL) >> 56; } uint64_t matching_bytes(const char * c1, const char * c2, size_t n) { size_t count = 0; size_t i = 0; uint64_t x, y; for(; i + sizeof(uint64_t) <= n; i+= sizeof(uint64_t)) { memcpy(&x, c1 + i, sizeof(uint64_t) ); memcpy(&y, c2 + i, sizeof(uint64_t) ); count += matching_bytes_in_word(x,y); } for(; i < n; i++) { if(c1[i] == c2[i]) { count++; } } return count; } uint64_t standard_matching_bytes(const char * c1, const char * c2, size_t n) { size_t count = 0; size_t i = 0; for(; i < n; i++) { if(c1[i] == c2[i]) { count++; } } return count; } void test() { size_t N = 100; char c1[N]; char c2[N]; for(size_t i = 0; i < 100000; i++) { for(size_t j = 0; j < N; j++) { c1[j] = (3*j + 7*j*i + 2 * i) %3; c2[j] = (5*j + 2 * i) %4; } if(matching_bytes(c1, c2, N) != standard_matching_bytes(c1, c2, N)) { abort(); } } } int main() { test(); }
Suppose that you give me two ASCII strings having the same number of characters. I wish to compute efficiently the number of matching characters (same position, same character). E.g., the strings ‘012c’ and ‘021c’ have two matching characters (‘0’ and ‘c’).
olli
Suppose that you give me two ASCII strings having the same number of characters. I wish to compute efficiently the number of matching characters (same position, same character). E.g., the strings ‘012c’ and ‘021c’ have two matching characters (‘0’ and ‘c’).
why not take a look at the generated assembly? For your standard_matching_bytes, both GCC and Clang are able to perform decent optimization to make use of SSE instructions and operate on up to 128 bit at once. It's probably worth benchmarking against the compiler optimized version. standard_matching_bytes(char const*, char const*, unsigned long): mov rcx, rsi mov rsi, rdx test rdx, rdx je .L23 lea rax, [rdx-1] cmp rax, 14 jbe .L24 and rdx, -16 pxor xmm4, xmm4 pxor xmm6, xmm6 xor eax, eax movdqa xmm7, XMMWORD PTR .LC0[rip] pxor xmm5, xmm5 pxor xmm3, xmm3 .L4: movdqu xmm2, XMMWORD PTR [rcx+rax] movdqu xmm0, XMMWORD PTR [rdi+rax] add rax, 16 pcmpeqb xmm0, xmm2 pand xmm0, xmm7 movdqa xmm1, xmm0 punpckhbw xmm0, xmm6 punpcklbw xmm1, xmm6 movdqa xmm2, xmm0 punpckhwd xmm0, xmm5 movdqa xmm8, xmm1 punpckhwd xmm1, xmm5 punpcklwd xmm2, xmm5 movdqa xmm9, xmm1 punpcklwd xmm8, xmm5 punpckhdq xmm1, xmm3 punpckldq xmm9, xmm3 ...
olli
How did you get that generated please?
passing -S to gcc/clang outputs <file>.s containing the generated assembly e.g. gcc -O3 -S file.c
Anonymous
hey guys, I've been working on a small program in C and I need to output some statistics if the program is stopped with CTRL + C, kinda like what the ping command does, how can I do that?
z
#include <signal.h> void handle_sig(int sig) { // Handle interrupt here } int main() { signal(SIGINT, handle_sig); // Do the work here }
z
See: man 2 signal
Anonymous
thank you very much
mito
Is there offtopic group?