Anonymous
Using a do…while() loop, continuously scan for characters (one per line) and print it out afterwards. The loop shall terminate due to either of the following reasons: The inputted character is a vowel The number of inputted characters has already reached 5. It must also be guaranteed that if the number of inputted characters is less than 5, then there must be a vowel from among the inputted characters.
Anonymous
Just that last sentence
Anonymous
I don t know it seems that if string is less than 5 output message or continue till u hit a vowel
Anonymous
In case u reach 5 with no wovel u repeat last input until vowel
Anonymous
E. X. Thhhh h h h e
ברני
Hey...I need help..need to find the small num in a hole num..
ברני
https://onlinegdb.com/ry_V8U0WJ
ברני
I know the if(digit>num) is a mistake becasue it brings me every num that less then the biggest... I got stuck..
Stephen
Hi
Alion🦁
Hi
Hi
Stephen
Hi
I'm a beginner in c
Guh
Anyone Can Help Me please, I have a school assignment Making a calculator with function commands in C code, the calculator calculates the perimeter of a square, rectangle and circle Then I use the switc case to siwtch the calculator menu, Is the switch case included in the function command, or am I doing it wrong?
Pavel
if with a function, what command do I use?
If you need a function, you can create some and put some of your functionality to be executed in these functions https://www.tutorialspoint.com/cprogramming/c_functions.htm
Mariia
Hi! What should I do to avoid time limit? #include <stdio.h> long long int number; long long int rax = 2; int main() { scanf("%lld", &number); if (number != 1) { while (number % rax != 0) { rax++; } } else { rax = 1; } printf("%lld", rax); return 0; } Print the smallest divisor of the number n, other than 1.
Mar!o
rax = score
What language is that?
Mariia
ukrainian
Mariia
Why is one variable called "rax"?
so, do u know how I can speed up the process of program?)
Mar!o
Execution speed?
☬ੴ Bassi
so, do u know how I can speed up the process of program?)
add a if statement to exit the code after testing 50% of the numbers
☬ੴ Bassi
if the number say is 50 you would only need to check up to 25
Mariia
add a if statement to exit the code after testing 50% of the numbers
check for parity or what do you mean? All the necessary conditions have already been entered into the program
Mar!o
Try to remove branching
Mariia
in order to create "for"?
Mar!o
Try to replace all if's/loops with a bitwise calculation
Mar!o
Use multithreading and split the work
Mar!o
Also modulo is slow find a workaround
Andrew
so, do u know how I can speed up the process of program?)
if a number is even , return 2, if its odd, count only odd numbers
Aleksei
Hi! What should I do to avoid time limit? #include <stdio.h> long long int number; long long int rax = 2; int main() { scanf("%lld", &number); if (number != 1) { while (number % rax != 0) { rax++; } } else { rax = 1; } printf("%lld", rax); return 0; } Print the smallest divisor of the number n, other than 1.
You can do something like Eratosthene sieve. Array of bools of size - number / 2 representing if given index is a divisor, then for-loop from 2 to number /2, if current index not a divisor, set in loop all multiple values in bool array to false not to check them in future. It's purely algorithmic task, so don't listen to "multithreading" advices
mov $22, %rax
ukrainian
assembly
Aleksei
Why not a even an excellent algorithm can be much faster if parallelized with threads and SIMD that's why there are concurrent and vectorized sort algorithms
Parallelized bad algo still worse then good algo in 1 thread. And i doubt if this c-like lab work dedicated to teach multithreading. It's overkill for her current knowledge
☬ੴ Bassi
i am puzzled on why you would use multi threading for such a simple operation
Anonymous
You can do different types of approach. Maybe calculate differently The rax
☬ੴ Bassi
and any function that carry's out a operation is a algorithm because its a blue print to the operation
☬ੴ Bassi
i would of simply %2 != 0 then kicked of a for loop starting at 3 and incrementing by 2 but only checking at 50% of the numbers value rax < (number /2) so if user entered 100 only numbers up to 50 would be tested.
☬ੴ Bassi
if it hits 50% of the number value then it can only be a prime number. There is no point checking if 101 is divisible by 51
☬ੴ Bassi
the smallest divisor is never greater than the sqrt of the number
that is true can she use maths.c? I am guessing the question has strains applied to it by what ever the lecture is.
Lleshi
hi
☬ੴ Bassi
hi
Aakash
Hi! What should I do to avoid time limit? #include <stdio.h> long long int number; long long int rax = 2; int main() { scanf("%lld", &number); if (number != 1) { while (number % rax != 0) { rax++; } } else { rax = 1; } printf("%lld", rax); return 0; } Print the smallest divisor of the number n, other than 1.
What time-limit are you looking for??!! — #include <stdio.h> #include <time.h> long long int num =0; long long int rax =2; int main() { clock_t tx; scanf("%lld", &num); if(num <2) return 1; tx = clock(); while ((num % rax) != 0) rax++; tx = clock() - tx; float tt = (float)tx/CLOCKS_PER_SEC; printf("raxCount:%lld -- timeTaken:%f", rax, tt); return 0; }
Igor🇺🇦
At very least you can run while upto sqrt (n). No need to check for number above anyway
And you can check that number is odd and make each starting from 3 like rax +=2, you don't need other odd numbers
Aakash
And you can check that number is odd and make each starting from 3 like rax +=2, you don't need other odd numbers
@Marisichka — Probably she’s finding time-load to find those numbers which are self divisible! Using smallest divisor method with “rax”😄 — #include <stdio.h> #include <time.h> long long int num =0; long long int rax =2; int main() { clock_t tx; scanf("%lld", &num); if(num <2) return 1; for(int i=2; i<=num; i++) { rax=2; tx = clock(); while ((i % rax) != 0) rax++; tx = clock() - tx; if (i==rax) printf("rax[%5.d]:%2.lld |timeTaken:%5.5f\n", i, rax, ((float)tx/CLOCKS_PER_SEC)); } return 0; }
Aakash
and which problem have you solved here? this is still far from optimal
It’s called idea! Unless you are too clear on question😄
Edries hashiesh
write a programe that addition two of matrices transpose matrix
Edries hashiesh
What? 🤔
do this programe please
Dima
read the rules
Aakash
I have no idea what you're talking about.
If you comment //if(i==rax) This will display the number of iterations “rax” has performed; though I added the for-loop instead of single/single entry!; instead take number for loop and check time limit. She didn’t clear anything on “time limit” question?
Igor🇺🇦
do this programe please
No one is going to write you full program, and even any help is problematic because the question is unclear
Aakash
From my understanding @Marisichka wanted to calculate minimum using better algorithm because this was timing out.
As original single while without ifs & breaks are best optimized; no improvements needed, unless parallels/openmp required on heavy number crunching! I will leave this to her to answer; as I don’t understand her “time-limit” point correctly; so I played with the program😄
Aakash
Calculating up to 0.5* sqrt(n) values instead of up to n numbers is even more efficient without any parallelism or vectorisation
Well you are correct to your point & perspectives, but what’s “time-limit” related to?? No clear!🙃
olli
Well you are correct to your point & perspectives, but what’s “time-limit” related to?? No clear!🙃
e.g. test with 2147483647, how long does your algorithm take to get the result? more than 10 seconds? that's too slow
olli
your snippets don't even compile
olli
timeTaken:18.879131 that's way above 10seconds
Aakash
Warning for what?
olli
1. Can you put the code which is faster! 2. Is that high prime number?
you can get the result for a 15 digit faster so taking 18s for 2147483647 is way to long
Aakash
you can get the result for a 15 digit faster so taking 18s for 2147483647 is way to long
I understand well about digits; ..but I don’t understand what you are trying! Put your code. It will describe clearly what you are doing!