Deepak Chaurasia
Variable is for storing value
Anonymous
What are you trying to do
Umm it's a program to know if a number is greater than 9 and less than 100
Anonymous
what do you thing your scanf string should do?
I want it to scan and give me answer 1 and 0 True and false
klimi
well i am asking about the scanf string
klimi
"%d \n"
klimi
%d - input number space - eat all white-space characters \n - eat all white-space characters so... you have to enter a number and then non white-space character
klimi
so your program is working exactly as it is written, it stops because it waits for more input
Anonymous
"%d \n"
Yes whats the matter it's correct right??
Deepak Chaurasia
#include <stdio.h> #include <math.h> int main ( ) { int a; printf("enter number : "); scanf("%d \n", &a ); printf("%d \n ", a>9 && a<100); int sum = a>9 && a<100; return 0; What's the error in it? OUTPUT: I ENTER THE NUMBER BUT IT IS NOT GOING FORWARD ⏩⏩ IT JUST STOPPED WHYY?
// Online C compiler to run C program online #include <stdio.h> #include <math.h> int main ( ) { int a; printf("enter number : "); scanf(" %d", &a ); printf("%d \n ", a>9 && a<100); int sum = a>9 && a<100; return 0; }
klimi
Yes whats the matter it's correct right??
well... it's syntactically correct
klimi
it doesn't do what you want it to do (which you have failed to explain)
Anonymous
it doesn't do what you want it to do (which you have failed to explain)
Oh noo sorry actually i am a beginner in this field
Anonymous
Btw here you go
Thanks let me try this....
klimi
Oh noo sorry actually i am a beginner in this field
well then this should be your first step in learning. If you want help, you will need to describe your problem and your code
klimi
You got it working? :)
Anonymous
You got it working? :)
Yes thanks for the help you all
Deepak Chaurasia
You got it working? :)
Sir help me upgrade my skills and get a intern😅
klimi
Sir help me upgrade my skills and get a intern😅
I think that is kinda offtopic to this group :D
klimi
#ot come offtopic if you want to continue c:
Deepak Chaurasia
I think that is kinda offtopic to this group :D
Yeah ,sorry but half of question is not offtopic
Deepak Chaurasia
How to upgrade skills in c/c++
klimi
How to upgrade skills in c/c++
exercise/practice or just learn (but actively)
Anonymous
.
Oh so so space and \n are technically same
Anonymous
Read books
That's kinda boring but profitable
Deepak Chaurasia
// Online C compiler to run C program online #include <stdio.h> #include <math.h> int main ( ) { int a; printf("enter number : "); ("\n %d", &a ); printf("%d \n ", a>9 && a<100); int sum = a>9 && a<100; return 0; }
Deepak Chaurasia
Ig it will clear more
Deepak Chaurasia
Btw int sum ... Is just grabage as for now
Mahmoud
Hello
Mahmoud
Take in 20x random 2d coordinates and work out the shortest path for a person to visit each point.
Talula
Take in 20x random 2d coordinates and work out the shortest path for a person to visit each point.
Brute force... should work the best, but combinations are just too many.
Deepak Chaurasia
Anonymous
Take in 20x random 2d coordinates and work out the shortest path for a person to visit each point.
That is the travelling salesman problem. It is a NP Hard problem meaning there is no known polynomial complexity algorithm for this. The only known ways to solve this are using exponential complexity algorithms. For TSP, brute force will be O(n!) which means you can't use brute force even if you have just 20 points to visit. You have to solve such problems using heuristic algorithms (sub optimal). One such algorithm that is used for TSP is Held-Karp algorithm which has a complexity of O(2^n). You can read about it here : Held-Karp
Rakesh
#include<stdio.h> void main() { int n,sum=0; printf("Enter array size: "); scanf("%d",&n); int a[n],i,min=a[0],max=a[0]; printf("Enter the array values: "); for(i=0; i<n; i++) { scanf("%d",&a[i]); sum=sum+a[i]; if(min>a[i]) { min=a[i]; } if(max<a[i]) { max=a[i]; } } What's wrong with minimum here I am getting a wrong output
neovstan
It causes undefined behavior
Rakesh
Do not use void return type in main
Can you please elaborate. What is the solution for it.
neovstan
Do not use void return type in main
Use int return type. Also you don’t have to return any value
Rakesh
It causes undefined behavior
But why it is happening only with minimum?
neovstan
Size of an array should be const or literal value
Rakesh
But I entered a constant value for n
neovstan
But I entered a constant value for n
Your n gets a value from user’s input in runtime
Anatolii
Hi guys! There are 2 books recommended in the channel with resources: "C programming A modern approach" and "Effective C". Which one I should start from? Thank you
neovstan
If you want to create an array with non-const size in runtime, you should to use std::vector in C++ or malloc in C
Rakesh
#include<stdio.h> void main() {     int n,sum=0;     int a[5],i,min=a[0],max=a[0];     printf("Enter the array values: ");     for(i=0; i<n; i++)     {         scanf("%d",&a[i]);         sum=sum+a[i];         if(min>a[i])         {             min=a[i];         }         if(max<a[i])         {             max=a[i];         }     } Still getting wrong minimum output
Ilya
Okay, it's initialized with zeroes
Rakesh
Can you please modify the program for me for a better understanding
neovstan
a[5] = {0}
Straight in declaration
Rakesh
But why it works with max
neovstan
int a[5]={0}, …
neovstan
But why it works with max
UB, it can be any value
Ilya
Because you are entering only positive numbers i assume
Ilya
this is why
Ilya
min = 0 and max = 0 before the start of the loop
neovstan
Your max and min in your code can be any values (-inf, +inf)
Ilya
depends on compiler may be?
neovstan
Uninitialized array can contain itself any values
Rakesh
min = 0 and max = 0 before the start of the loop
If so then I should get correct output right