Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to print out each integer of an int individually using a for loop. I am doing this because I want to print things in between some of the single ints. So if the number was 4564, I want to print out 4 5 6 4. Is there a quick way to do this?
I know how to do it in java but I am new to C and am not sure.
Something like this shall help
while(num!=0) {
printf("%d", num%10); //your last digit, you can store it in an array of characters as well
num = num/10 ;
}
Note : you've got to reverse the order while using the digits
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
An array of integer is given of size n. We have to make all the equal. For this we can add 1, 2 or 5 to the array element any time and to any element. We have to find minimum no of operation to do so?
For example
Array. 2 2 3 7
Output should be 2
Explanation
In first operation we add 1 to 2,2,7
After that array will be as 3 3 3 8
Now in 2nd operation we add 5 to 3,3,3
After that array will be as 8,8,8,8
You could first think about how many operations it would cost to get all values to the highest value in the list.
In a second step you can think if there could be a better solution if you try to reach highest-value+1, highest-value+2, highest-value+3, highest-value+4 .
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to display the contents of an array with type double that has a length of 5 without using the [ ] indexing . I can only use a for loop and pointer techniques.
How can you achieve that ?
Can anyone give me a brief explanation of pointers as I have no idea how to use them exactly ?
The array indexing operator is a shorthand for hiding pointer arithmetic.
So if you have an array like this:
double a[5];
Instead of using this expression:
a[1]
You can use this:
*(a + 1)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
When using C programming language, I have no idea how to put a user input to an array.
I need to get integers from the user in from of:
printf("Enter numbers. Separate each by a comma: ");
How can I put each number into an array?
This is a very helpful link
Also look up this too for clarification on Console.Read & Console.Readline
Difference between Console.Read() and Console.ReadLine()?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to split a string i have "msg 10 2" into different strings & ints. so instead of having
msg 10 2
I can take each as a seperate parameter can print:
msg
10
2
I use the variable to define a message:
char msg[30] = "msg 10 2";
I then want to take each field as seperate values/parameters.
Thanks
If you know your string will always follow the format string int int, then you could also use sscanf.
Use strtok (which you already tagged) and atoi.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
For example, let's say I have the decimal number 10.
I want to be able to go form an integer of 10 to a string of "0a".
How do I do that?
Note: I don't want anything printed out.
You can use sprintf to represent a numeric value in hexadecimal format:
sprintf(buff, "%0.2x\n", 10)
Take also a look at dmckee's comment on int/hexadecimal misunderstanding.