Captain
Am a beginner
Write a for loop which will add 5% of previous year fees to previous fees 🙂
Captain
Can you make it more easy and understandable?
Are u being sarcastic here 👄
Anonymous
Are u being sarcastic here 👄
No no I not understand that question properly , that's why I'm telling
Captain
No no I not understand that question properly , that's why I'm telling
He is asking to write a program that calculates fees for University after 10 yrs, each yr adding 5% of previous yr's fees
Dima
no begging
Ariel
*The tuition fee for Data link institute is $2000 per year. Suppose the university financial committee recommends that tuition should be increased at an annual rate of 5%. Write a program that uses a loop to compute the tuition in ten years.* Please can someone help me with this
//A proposed solution #include <stdio.h> int main() { int year,fee=2000; printf ("Year 1: 2000$\n"); for (year=2;year <=10;year ++) { fee+=fee*0.05; printf ("Year %d: %d$\n",year,fee); } return 0; }
Aztec
strlen(arr2) on assigner is O(n), you could just insert logic to find NULL character and place it into the loop, or place strlen(arr2) into another temp variable so it wouldn't be O(n).
Don’t actually get what O(n) is Googled on how it’d help but couldn’t understand a thing Also I’ve tried breaking the loop once arr2 == ‘\0’ Still not working
Anonymous
Don’t actually get what O(n) is Googled on how it’d help but couldn’t understand a thing Also I’ve tried breaking the loop once arr2 == ‘\0’ Still not working
What he means is that you have to loop through the whole string to get the length, and then loop through it again to set the characters for temp. If your for loop was something like this : for (size_t i = 0; arr2[i] != '\0'; i++) You're essentially doing the same thing but taking less time.
Anonymous
Thanks a lot this worked
Did you understand why?
Aztec
Did you understand why?
Yes i understand how that worked. I’m trying to understand how O(n) is related to the first error i was getting
Anonymous
This what I did using Java package simpleinterest; import java.util.*;   public class SimpleInterest {        public static void main(String[] args) {        //Declare and Initialize the Principle, Rate and Time Period        float P = 2000, R = 5,        for(float T = 1; T<=10; T++){            System.out.println("The entered principle amount is = " + P);            System.out.println("The entered rate is = " + R);            System.out.println("The entered time period is " + T);                         // Calculate simple interest        float SI = (P * T * R) / 100;        //Print the simple interest        }        System.out.println("total is  = " + SI);    }     }
Anonymous
The indicative breakdown of marks for each part of the assignment is as follows: ipc_jobqueue.c - 10 marks job.c - 15 marks joblog.c - 15 marks jobqueue.c - 20 marks mutex_peterson.c - 10 marks sem_ipc_jobqueue.c - 20 marks shobject_name.c - 10 marks For full marks your solution must: Pass tests for the above files (some of which may be more comprehensive than the tests provided with the project), and Comply with instructions given in this specification and related material (including in relevant .h files, .c files and README files), and Demonstrate good programming practice particularly with respect to non-functional aspects. Good practice includes (but is not restricted to): Not overcomplicating solutions Guarding against memory leaks Safe use and choice of system and C library functions Where appropriate, programming defensively with respect to input parameters to functions and return values of functions you use. "Where appropriate" means that there is a trade-off between programming defensively and not over-complicating your solutions. However, you should guard against propagation of errors to the underlying system. The specification of functions will give some indication of what is expected in terms of managing erroneous input.
Jenny
is there a C# language?
𝓓𝓪𝓻𝓴 𝓟𝓱𝓮𝓸𝓷𝓲𝔁
Jenny
Yeah
where?
𝓓𝓪𝓻𝓴 𝓟𝓱𝓮𝓸𝓷𝓲𝔁
where?
Where what?
Jenny
Where what?
C# language, it seems like all codes are for C and C++
coal
but probably you can ask for C# and someone will answer
Jenny
yes, actually
coal
!report
Anonymous
!report
Hey I'm sorry about that, don't get mad at me
Daniel
Hello guys, can someone tell me what i need learn tô understand this code?
Daniel
( ( void (*)( ) ) ValidateFns[0] )( );
Daniel
I know pointers and arrays
Daniel
But this is very confuse
coal
function pointers
Daniel
function pointers
We can do a pointer that have function as address?
Daniel
Will It call the function?
coal
We can do a pointer that have function as address?
a pointer that points to a function yeah
Daniel
Great! Thank you man!
Alviro Iskandar
But this is very confuse
Pay attention to the part that's marked by ^^^ below. ( ( void (*)( ) ) ValidateFns[0] )( ); ^^^^^^^^^^^^^^^ This part is a cast to a function pointer that has unspecified number of arguments and returns void (or doesn't return any value). ( ( void (*)( ) ) ValidateFns[0] )( ); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This whole part results in a function pointer, and the () after that means invoke the function, so you call that function. For example: void test() { printf("test"); } int main(void) { void *arr[10]; // fill this with the address of a function arr[0] = &test; // cast to a function pointer and call it ((void (*)())arr[0])(); return 0; } The above code effectively calls test(). It's simply like: void test() { printf("test"); } int main(void) { test(); return 0; }
coal
for example, curl library needs you to specify a function pointer as the write_callback method of a response
coal
so it calls your custom function
coal
it's the C closest resemblance of C++ lambdas
coal
but not the same thing, as lambdas dont necessarily have names
Daniel
Nice tips! I will read more about this with those new knowledge
Daniel
Before I forget... sorry for my bad english! I am begin in C language and in english language too!
coal
also, i recommend you to translate all sentences you write, to practice english you write a sentence and check how the proper version looks like
UrCodeBuddy️ 💻
Can someone plz explain to me how shell sorting work ?some notes or examples ...I tried it online but it's going over my head. Thanks in advance
Krishnaa
Anyone attempted last night's LeetCode's Weekly contest???? If not so, can u guys please look at the "Append K Integers With Minimal Sum".
Krishnaa
class Solution { public: long long minimalKSum(vector<int>& nums, int k) { sort(nums.begin(), nums.end()); long int i=1; long long sum=0; for(int j=0; j<nums.size(); j++){ if(k==0) break; else if(i<nums[j]){ sum+=i; i++; k--; j--; } else if(i==nums[j]){ i++; } } while(k--){ sum+=i; i++; } return sum; } };
Krishnaa
Please optimize the above code. It passed 77/107 test cases. and shows TLE.
Anonymous
🤗thanks for the welcome
Nomid Íkorni-Sciurus
How do you organize your CMake project? I'll make my question more clear. I have a build/ dir from conan and a src/ dir where the sources of the main executable are located. I plan to have some sub projects, but this way I'll have to write all the dependent *.c files in the cmake file. I'm not very fluent about cmake; is this the correct way?
Pavel
How do you organize your CMake project? I'll make my question more clear. I have a build/ dir from conan and a src/ dir where the sources of the main executable are located. I plan to have some sub projects, but this way I'll have to write all the dependent *.c files in the cmake file. I'm not very fluent about cmake; is this the correct way?
There are ways to recursively add c/cpp files to cmake that I use to create libraries (I know it's not really by cmake design, but at least it works with one cmake file). Example I have here, note add_folder_as_library: https://github.com/gameraccoon/hide-and-seek/blob/develop/CMakeLists.txt
Nomid Íkorni-Sciurus
and adding them as static libraries for each folder
Prince Of Persia
Is there any ide lighter than vscode and handier than vim(even with extensions)?
Nomid Íkorni-Sciurus
not quite an "ide" but can become one very easily
Mr
Thanks a lot for it
-
Hello guys. Could you help me please
-
#include <stdio.h> #include <string.h> void main(){ char aaa[8]; printf("Write smth: "); fgets(aaa,8,stdin); int result = strlen(aaa); printf("%d\n",result); }
-
I entered Hello , it returns 6 instead of 5. I know it's because of fgets. Then I entered 12345678 and it returns 7 instead of 8
Nomid Íkorni-Sciurus
Is there any ide lighter than vscode and handier than vim(even with extensions)?
I can't send you an example because this group doesn't allow to send images if you want I can send you how my setup looks like
-
I entered Hello , it returns 6 instead of 5. I know it's because of fgets. Then I entered 12345678 and it returns 7 instead of 8
So it returned 6 because fgets always puts \n at the end of a string. But why it returned 7 after second execution? I wrote char aaa[8] and entered 8 characters. What does fgets do in this case?
ʙʀʜᴏᴏᴍ ⑇
What is the difference between int main main void main.
klimi
What is the difference between int main main void main.
in int main you return int, in void main you don't return value
Anonymous
Hi
Anonymous
Bot
Shrivatsa
#include <stdio.h> void main() { int a, b, c; printf("enter a,b \n"); scanf("%d,", &a); scanf("%d,", &b); c = a + b; printf(" the result is %d", c); } PS E:\c notes\1 c programs\clg assignment> gcc .\simply.c PS E:\c notes\1 c programs\clg assignment> .\a.exe enter a,b 5 5 the result is 698 #include <stdio.h> void main() { int a, b, c; printf("enter a,b \n"); scanf("%d,%d", &a, &b); c = a + b; printf(" the result is %d", c); } PS E:\c notes\1 c programs\clg assignment> gcc .\simply1.c PS E:\c notes\1 c programs\clg assignment> .\a.exe enter a,b 5 10 the result is 15
Shrivatsa
Hey anyone in the first program when I use scanf to take 2 values at once result is not coming properly, why is it so in second when I take scanf separately I am getting correct answer. Help out