Anonymous
Where are you from?
knowing my place can't going to help u with anything bro
Anonymous
🤞
GHAMDAN_NSHWAN
😶
Aryan
is this a valid array declaration? int matrix[5] = {1, 2, 3, 4, 5, 6, 7}
Aryan
ok
Sachin
int count = 0; for (int i = N; i > 0; i /= 2) for (int j = 0; j < i; j++) count++;
Sachin
time comlexity of this code?
Anonymous
time comlexity of this code?
Quickly looking it over... O( n.log(n) )
佳辉
s u can
#include <stdio.h> float add(float a, float b); float sub(float a, float b); float mult(float a, float b); float div(float a, float b); int main() { float a,b,res; char choice; do { printf("1.Addition\n"); printf("2.Subtraction\n"); printf("3.Multiplication\n"); printf("4.Division\n"); printf("5.Exit\n\n"); printf("Enter Your Choice : "); scanf("%d",&choice); printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); switch(choice) { case 1: res = add(a, b); break; case 2: res = sub(a, b); break; case 3: res =mult(a, b); break; case 4: res = div(a, b); break; case 5: return 0; break; default : printf("Wrong Choice..!!"); break; } printf("Result=%f",res); printf("\n------------------------------------\n"); } while(choice<=5); /*Function to add two numbers*/ float add(float a, float b); { return b + a; } /* Function to subtract two numbers*/ float sub(float a, float b); { return a - b; } /* Function to multiply two numbers*/ float mult(float a, float b); { return a * b; } /* Function to divide two numbers*/ float div(float a, float b); { return a / b; } }
佳辉
where did i wrong,i very confuse now😢
Sachin
where did i wrong,i very confuse now😢
Are you talking about above program
Sachin
What is the problem you are facing
佳辉
I am trying to build a simple calculator by using switch,function and while
Pavel
Ya
What is the problem with it? Compilation error? If yes, what error? Logical error? If yes, what the expected behavior and the behavior you see?
佳辉
Undefined reference to add(float,float)
Pavel
Undefined reference to add(float,float)
You probably need to define your functions in the global scope because you have the declaration outside your main function. Or define them above the code that uses it.
Dumb
You put ; on func implementation
Pavel
Undefined reference to add(float,float)
Note: undefined reference error mean that the linker didn't find the definition (e.g. code compiled but some names are not resolved after that).
Dumb
Example: You wrote float add(...); {...} It must be float add(...) {...}
Dumb
What should i put inside{ }
The code of your function
Dumb
I used ... just to be fast with my explanation
佳辉
😢
Dumb
😢
It happens, but the most important thing is never give up 💪 Practice makes strong
佳辉
The code of your function
Can u tell me whats is the code of my function?...
Dumb
I amm seeing your code again and maybe I found something else
Dumb
Can u tell me whats is the code of my function?...
Just asking, is it possible to declare functions inside a main code? If I am not wrong, functions and procedures are declared and described outside of your main code, or better, they should be defined in your global scope (or in a user library, but this is not our case)
Sachin
no
Sachin
it is not working because defination of function are in side main
佳辉
So complicated
Dumb
Furthermore, after the while the program should stop, so you missed the return 0 statement After that statement you should close the main scope
Dumb
no
Ok so I saw well
佳辉
I am only learned function last week😭
Sachin
#include <stdio.h> float add(float a, float b) { return a+b; } float sub(float a, float b) { return a-b; } float mult(float a, float b) { return a*b; } float di(float a, float b) { return a/b; } int main() { float a,b,res; char choice; do { printf("1.Addition\n"); printf("2.Subtraction\n"); printf("3.Multiplication\n"); printf("4.Division\n"); printf("5.Exit\n\n"); printf("Enter Your Choice : "); scanf("%c",&choice); printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); switch(choice) { case 1: res = add(a, b); break; case 2: res = sub(a, b); break; case 3: res = mult(a, b); break; case 4: res = di(a, b); break; case 5: return 0; break; default : printf("Wrong Choice..!!"); break; } printf("Result=%f",res); printf("\n------------------------------------\n"); } while(choice<=5); }
Dumb
I am only learned function last week😭
Take your time, everyone passed by this
Sachin
I am only learned function last week😭
you can not define a function inside main function
Sachin
Dumb
I am only learned function last week😭
Next time you have to ask something, pls use pastebin.com, it will help us to understand better and faster the code
Dumb
Italy
Sachin
👍
佳辉
#include <stdio.h> float add(float a, float b) { return a+b; } float sub(float a, float b) { return a-b; } float mult(float a, float b) { return a*b; } float div(float a, float b) { return a/b; } int main() { float a,b,res; char choice; do { printf("1.Addition\n"); printf("2.Subtraction\n"); printf("3.Multiplication\n"); printf("4.Division\n"); printf("5.Exit\n\n"); printf("Enter Your Choice : "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); res = add(a, b); printf("Result:%f",res); break; case 2: printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); res = sub(a, b); printf("Result:%f",res); break; case 3: printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); res = mult(a, b); printf("Result:%f",res); break; case 4: printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); res = div(a, b); printf("Result:%f",res); break; case 5: return 0; break; default : printf("Wrong Choice..!!"); break; } printf("\n------------------------------------\n"); } while(choice<=5); }
佳辉
#include <stdio.h> float add(float a, float b) { return a+b; } float sub(float a, float b) { return a-b; } float mult(float a, float b) { return a*b; } float div(float a, float b) { return a/b; } int main() { float a,b,res; char choice; do { printf("1.Addition\n"); printf("2.Subtraction\n"); printf("3.Multiplication\n"); printf("4.Division\n"); printf("5.Exit\n\n"); printf("Enter Your Choice : "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); res = add(a, b); printf("Result:%f",res); break; case 2: printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); res = sub(a, b); printf("Result:%f",res); break; case 3: printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); res = mult(a, b); printf("Result:%f",res); break; case 4: printf("Enter first number : "); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); res = div(a, b); printf("Result:%f",res); break; case 5: return 0; break; default : printf("Wrong Choice..!!"); break; } printf("\n------------------------------------\n"); } while(choice<=5); }
Finally done
佳辉
Students find their own project based on criteria / scope of the project.The scope of the project to be carried out MUST BE using control structures AND Function: i. At least using MORE THAN TWO (2) Arithmetic Operations AND ii. Using Selection statement (if -else/switch case) AND iii. Looping Statement (while/do-while/for) AND iv. At least using ONE (1) function
佳辉
This is my question.Does my coding meet the requirement of the question?
佳辉
Tq u all for helping me🥰
Anonymous
Hello :) I want to develope some type of SAAS tool, a instagram Marketing Tool
Anonymous
Can anyone answear some question about that?
Hamidou
/get cbook
Yasas
/get cpp-vscode
Anonymous
Tq u all for helping me🥰
If you want to understand the concept of C , then send me msg directly..... I'll give you a book in which the concept is very easily explained ...... Ok...
Anonymous
But ans is coming O(n)
IThe outer loop executes log n times. The inner loop executes n/2 + n/4 + n/8 + ... times. If you sum this to infinity it becomes n. Even if you don't, it becomes closer to n with every additional outer loop run. The inner loop is a geometric progression with first term n/2, common ratio 1/2 and number of terms is log n. Suppose say log n is 3 then the sum will be n/2 + n/4 + n/8 = 7n/8. If log n = 4, the sum will be 15n/16 which is bigger than 7n/8.
Anonymous
So the answer is O(n)
David
hello, everyone I want to implement a simple function, which can print the content of memory specified address and size. like this: void print(void* addr, size size){ ... } char ch = 'a'; print(&ch, sizeof(ch)); // print: 0x61 you know, character 'a' ascii, DEC: 97, HEX: 0x61 Can anyone tell me how to implement this?😭
GHAMDAN_NSHWAN
Hii
Anonymous
hello, everyone I want to implement a simple function, which can print the content of memory specified address and size. like this: void print(void* addr, size size){ ... } char ch = 'a'; print(&ch, sizeof(ch)); // print: 0x61 you know, character 'a' ascii, DEC: 97, HEX: 0x61 Can anyone tell me how to implement this?😭
Instead of void* pointer use an unsigned char* pointer and while calling this function you will have to manually cast the argument. You will also have to take into account architectural details like big endian etc etc. In other words it is a pain and you might end up invoking UB. It is better to instead use a debugger.
Anshul
int numberOfSteps(int n) { if(n==0) { return 0; } if(n==1) { return 1; } if(__builtin_popcount(n)==1) { return 1; } int temp=n; int pos=0; while(temp>0) { pos++; temp=temp>>1; } int remaining=(n-(1<<pos)); int ans=1; ans+=numberOfSteps(remaining); return ans; }
Anshul
this gives me segmentation fault but i can't find it why?
Pavel
It seems that the inner loop body will be called about N*2 - log(N)/2 times. So it looks like O(n) yes
Anonymous
int numberOfSteps(int n) { if(n==0) { return 0; } if(n==1) { return 1; } if(__builtin_popcount(n)==1) { return 1; } int temp=n; int pos=0; while(temp>0) { pos++; temp=temp>>1; } int remaining=(n-(1<<pos)); int ans=1; ans+=numberOfSteps(remaining); return ans; }
I guess it is because you dont handle the case when n becomes negative in the course of runs of your code. Think what happens when n is 3 and the code where you determine pos makes pos 2 and then you subtract 1<<2 from 3. You should be subtracting 2 instead of 4.
Anonymous
Ya it is O(n)
Alvin
Hello friends, I would like to ask you for a clubhouse invitation code, thanks
Anonymous
Hi guys I need a suggestion Recently i got a paid internship from verzeo via Quiz on google forms I am not sure abt that whthwr it was worth Can anybody guide me so that i can dm them