it's
Ok
Anonymous
/* C program to demonstrate example of floor and ceil functions.*/ #include <stdio.h> #include <math.h> int main() { float val; float fVal,cVal; printf("Enter a float value: "); scanf("%f",&val); fVal=floor(val); cVal =ceil(val); printf("floor value:%f \nceil value:%f\n",fVal,cVal); return 0; }
Anonymous
Pls my code doesn't run
Anonymous
The output is 0.00 for all inputs
Otumian
The output is 0.00 for all inputs
Did you enter a value for val?
Anonymous
Yesss...I entered 24.5 it gave 0.00
Balig
Hi
Anonymous
Let's say you are given a string. You can get many strings (combination) out of the given original string if you rearrange characters of original string. String is Palindromable if any one combination is palindrome.   Example 1: Original String: NINIT Combinations: NINIT, NNIIT,IINNT,ININT,IITNN,NITIN,INTIN,INTNI,NTNII,NNTII and so on
Anonymous
Any one know answers
Pavel
Any one know answers
What is the question?
Anonymous
Write a program to check it given string is Palindromable or not. (please note this is not a question to check if string is palindrome or not). Complexity of the program should be less then O(n) that is using no or one loop (IMPORTANT) (Hint: Do not write a program to find the permutation and combination or use any permutation() function. Again we are NOT looking you to write the permutation combination program or use any recursion and then check each string if it is palindrome or not of original string and then check combination. Program is much simpler than finding permutation and combination. )
Pavel
So when you see an element you check if it's in the set: if it is not, you add it there. If it is in the set, you remove it. At the end you check how many items are in the set, should be 0 or 1 if the string is palindromable
Anonymous
A string is palindromable if there is only one symbol that has an odd count of occurrences in it
Anonymous
If that is valid, which i think it is, then it is a pretty simple o(n)
Anonymous
You want us to write code you?
Anonymous
Yes to compare
/warn assignment
caesar
I don't get it
Anonymous
I don't get it
No one will write code for you
caesar
Only question
Anonymous
Only question
What question?
caesar
What question?
U meant I'm supposed to ask only question
Anonymous
U meant I'm supposed to ask only question
You're supposed to write code yourself and when you face problems and difficulties, you write here describing them in full details with samples of your code so we can help you
lol
/warn
carlos
Pls what's the difference btw arduino c++ code and regular c++ code.Thanks
Ehsan
other than that it’s about the same
Hariyana Grande
#include <stdio.h> #include <stdlib.h> #define MONTHS 12 #define YEARS 5 int main() { // initialize rainfall data for 2011-2015 float rain[YEARS][MONTHS] = { {4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6}, {8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3}, {9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4}, {7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2}, {7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2} }; int year, month; float subtot, total; printf("YEAR\t\tRAINFALL (inches)\n"); for (year = 0, total = 0; year < YEARS; year++) { for(month = 0, subtot = 0; month < MONTHS; month++) { subtot += rain[year][month]; } printf("%5d \t%15.1f\n", 2010 + year, subtot); total += subtot; } printf("\nThe yearly average is %.1f inches.\n\n",total/YEARS); printf("MONTHLY AVERAGES:\n\n"); printf(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n"); for (month = 0; month < MONTHS; month++) { for (year = 0, subtot = 0; year < YEARS; year++) subtot += rain[year][month]; printf("%4.1f ", subtot/YEARS); } printf("\n"); return 0; } could somebody please explain the program from "for loop" ? just short explaination will suffice. im confused about loop control variable "year, month"
Amu
_new_node: pushq %rbp movq %rsp,%rbp # IMPORANT: THE ALIGNMENT RULE FOR MALLOC AND OTHER C FUNCTIONS IS THAT THE STACK HAS # TO BE 16-BYTE ALIGNED. SO, AFTER THE PUSH TO %RBP, THE STACK POINTER %RSP, SHOULD # BE INCREMENTED OR DECREMENTED IN MULTIPLES OF 16. # So, two 8-byte pushes is fine. # the string to write into the new node is pointed to by %rdi # NOTE: sizeof(NODE) is 216. # Offsets within NODE are: question_or_animal = 0, left = 200, right = 208 # NULL is 0. # We'll move s to a callee-saved register, %rbx, so we don't have to repeatedly # push and pop it when we make calls to malloc and strcpy. # Similarly, we'll put p in %r12, another callee-saved register. # first save %rbx and %r12 on the stack. # FILL THIS IN push %rbx push %r12 # then move s to %rbx # FILL THIS IN movq %rdi, %rbx // NODE *p = (NODE *) malloc(sizeof(NODE)); // where sizeof(NODE) is 216 # FILL THIS IN call _malloc # put the result of malloc into p (%r12) # FILL THIS IN movq %rax, %r12 // p->left = NULL; // p->right = NULL; # FILL THIS IN movq $0, 200(%rax) movq $0, 208(%rax) // strcpy(p->question_or_animal, s); # call strcpy, passing the address of p->question_or_animal and the pointer s (which is in %rbx) # FILL THIS IN callq _strcpy movq %rbx, %rax // return p; # restore the callee-saved registers %r12, %rbx #FILL THIS IN popq %r12 popq %rbx popq %rbp retq .section __TEXT,__text,regular,pure_instructions .globl _guess_animal .p2align 4, 0x90
Amu
I have this assembly code to translate from a c file, can anyone help?
Amu
How do you malloc in assembly?
Amu
call _malloc # put the result of malloc into p (%r12)
Ammar
call _malloc # put the result of malloc into p (%r12)
Yeah like this. The return value will be in %rax.
Amu
so my solution makes sense?
Ammar
So you have just need to move %rax to %r12
Ammar
so my solution makes sense?
Yeah, that part makes sense.
Amu
# In this function, we're going to save registers at fixed offsets from %ebp (as local variables). # We're using two callee-saved registers (that's 16 bytes) and have a 200-byte array, for a total of # of 216 bytes. The next 16-byte boundary is at 224, so we'll decrement %rsp by 224 and save/restore # %rbx and %r12 as offsets from %rbp (as if they were local variables) # %rbx: -8(%rbp) # %r12: -16(%rbp) # new_question_or_animal: -216(%rbp) # We'll use %rbx for p and %r12 for new_n (see below). # make space on the stack for the array and the two callee-saved registers # FILL THIS IN subq $224, %rsp
Amu
another part im having trouble with is how do we make space on the stack? i tried subq but im not sure
Ammar
Yes, it is subq on %rsp. Just make sure you subtract it with amount multiple of 16.
Amu
so subq $224, %rsp makes space for the two callee registers as well as the array?
Hariyana Grande
my question went up how will i get ans now?
Ammar
so subq $224, %rsp makes space for the two callee registers as well as the array?
No, it is just uninitialized space for local variable. You need to pushq the callee saved.
Amu
oh man im so confused, assembly really sucks lol
Amu
alright thanks for the help @ammarfaizi2
Hariyana Grande
"%s specifier treats pointer given in an argument as an array". what does it mean?
Ammar
"%s specifier treats pointer given in an argument as an array". what does it mean?
Yeah, it's actually array of chars, it ends when it finds a null terminator '\0'.
Hariyana Grande
Ammar
could u please elaborate a little bit in laymans term
Let's use an example to make it clear. char my_str[] = "Hello World!"; Now, you see an array of chars, right? If you don't, then find that out first before going to the *printf* format. The expression my_str yields a pointer to the first member of the array. And this call will print "Hello World!": printf("%s", my_str); At the end of string literal, it puts null terminator char '\0'. So that the array actually consists of 13 chars including null terminator.
Ammar
Another example: This is an array of chars too. char my_str[] = {'a', 'b', 'c', '\0', '1', '2', '3'}; See the null terminator here? At index 3. And this call will print "abc" printf("%s", my_str); Why 1, 2 and 3 don't get printed? Because %s stops reading when it finds null terminator.
Hamid
hey, i'm a little confused int *s1_ptr = new Student(); s1_ptr = new Student[3]; // <-- is it a pointer to array or just an array? why does this code compile? i mean, s1_ptr is an pointer and new Student[3]; is a pointer to an array an array is a pointer but the following code doesn't compile at all Student s1_ptr = new Student[3]; ```
Anonymous
Thanks
Ammar
hey, i'm a little confused int *s1_ptr = new Student(); s1_ptr = new Student[3]; // <-- is it a pointer to array or just an array? why does this code compile? i mean, s1_ptr is an pointer and new Student[3]; is a pointer to an array an array is a pointer but the following code doesn't compile at all Student s1_ptr = new Student[3]; ```
Array is not a pointer. Well new Student[3] will allocate array of Student(s) and the expression will yield a pointer to the first member of the array. You have memory leak here Student *s1_ptr = new Student(); s1_ptr = new Student[3]; new Student() will allocate memory independently with new Student[3]. And you throw away the pointer without deleting it by assign another value to it, so it is memory leak. You could have used this: Student *s1_ptr = new Student[3];
Hamid
Oh it is a = new Student[3] I thought st_ptr, or it was just edited?
sorry, my bad, i edited it and i forgot to rename that
Ammar
It should be Student *s1_ptr = new Student[3];
Ammar
ok so expression my_str yeild a pointer to the first member of the array. like zero'th element but why not other elements?
Because it is what it is. It is how array expression in C works, there is no specific reason for that. It is simply because C language has this semantic rule.
Hariyana Grande
Because it is what it is. It is how array expression in C works, there is no specific reason for that. It is simply because C language has this semantic rule.
so if i write my_str[2] does that mean "my_str" array is pointer to 3rd element? this is last question i swear.
Hariyana Grande
i mean in printf and scanf funcs
Ammar
so if i write my_str[2] does that mean "my_str" array is pointer to 3rd element? this is last question i swear.
You can ask more of course. —————————————— my_str[2] is not a pointer, it yields the char. For example: char my_str[] = "Hello World!"; // my_str[2] here is the third element, so it is 'l' // my_str + 2 is the pointer to the third element // &my_str[2] is the pointer to the third element, same as my_str + 2
Hariyana Grande
wow now i got the complete picture thank you so much
Язиля
Hello everyone! Is there a job channel to post vacancy for C++ Embedded developer for Berlin?
Anonymous
Hello everyone! Is there a job channel to post vacancy for C++ Embedded developer for Berlin?
We don't have any You can try use Russian C++ job posting channel https://t.me/ProCxxJobs
Язиля
Anonymous
Thanks! Actially I need German and English speaker 🙂
For example think-cell likes to relocate Russian developers to Germany, so that's why I told you about the channel
Anonymous
Hello everyone! Is there a job channel to post vacancy for C++ Embedded developer for Berlin?
You can post it here but if you have a lot of text, please post it, for example, to gist.github.com (or somewhere else) and provide here the link with short description