Printing last 5 digits in C (Octal base) [closed] - c

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I was wondering how could I print just the last 5 digits of an octal number in C programming language?
Tricky part: the number is unsigned in definition, so after some procedures it outputs something like 3777777464. What I want to print is just 77464.
I tried to look around in C formatting guides, but I only found out how to write the first 5 digits/characters, not the last 5 ones in regards to the tricky part mentioned.
It is only needed to be displayed in output (printf/fprintf in a file).
EDIT and emphasize: The code is too long to post here, It consists of many c files and headers. To make it concise: I need printf("%05o\n",arr[i]); to print only last 5 digits. It prints something like 3777777464. The numbers are correct, I just need the last 5 digits
Thank you very much for helping me

print just the last 5 (octal) digits of a number
Derive the last 5 octal digits by anding with a mask of the 077777.
#define MASK_LAST_5_OCTAL_DIGITS 077777u
// vv print at least 5 characters, pad with 0 as needed
printf("%05o\n", (unsigned) (number & MASK_LAST_5_OCTAL_DIGITS));

Related

How do I add spaces in front of integer array parameters? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have an array like this
int numbers[]={5,6,5,8,9,1,-6516,8,811,981,981};
and I need to print them to screen with spaces in front of them so the total number of characters printed will be 4. si the number 5 will be printed as 3 spaces and 5 5 the number 811 will be 811 and so on.
As was previously mentioned in comments, this is something you can do with printf. I'm reluctant to write the code because a) it looks like homework and b) you'll have this nailed once you've read up on printf. (You'll need to put that printf in a for-loop to go thru the array, for sure, so read up on for as well if you need to.)
Some good resources for printf are whatever textbook you're using, plus
https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm
https://www.dummies.com/programming/c/how-to-format-with-printf-in-c-programming/
http://www.cplusplus.com/reference/cstdio/printf/ (a reference, not a tutorial)

What exactly does '%Id' mean? (uppercase I, lowercase d) [closed]

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 6 years ago.
Improve this question
I'm asking about %Id, not %ld.
Can anyone please explain to me what does "I" exactly do:
I For decimal integer conversion (i, d, u) the output uses the
locale's alternative output digits, if any. For
example, since glibc 2.2.3 this will give Arabic-Indic digits in the Persian ("fa_IR") locale.
As an example:
printf("%Id",1);
In other words what is the difference between %d and %Id ?
can anyone please explain it with simple words and simple example stating the difference ?
printf format option I is a glibC extension to select a locale representation for numbers. It is not defined by the C Standard and should not be used in portable code.
If the locale is properly selected and supported by your C library, calling printf("%Id", 1); might produce a string encoding the Unicode code point U+0661 ١ that is the representation of the digit one in arabic.
See http://www.fileformat.info/info/unicode/char/0661/index.htm
Conversely, printf("%d", 1); always prints 1, the western representation of number one.
To make matters even more confusing, 1 is called an arabic numeral, as opposed to roman numeral I... unrelated to the I in %Id.

Which datatype is used for 10^500 in c language [closed]

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
Problem Statement
Addition is a very basic operation in mathematics. Jimmy was very weak in addition, so his father decided to teach him. Jimmy is given a number and has to perform addition on all the digits of that number till that the large number gets converted into a single digit. Your task is to prepare a program for him so that he can easily find out the final number.
Input Format
First line contains T (1<=T<=100) the number of test cases.
Each test case contains integer N (1<=N<=10^100).
Output Format
For each test case, output the one digit number by repeatedly adding the digits.
Constraints
1<=T<=100
1<=N<=10^500
I'd represent the very large input number as char, and the total of the digits (first pass) will easily fit in an int. You'll need a little more than simple arithmetic, but it shouldn't be difficult (case seems a likely way to manage the job).

Addition of 2 numbers and give corresponding outputs depending on the number of digits got from the addition using C [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
The Question goes this way :
Add two numbers and if the addition of two numbers gives the result in single digit print YES and if the result of the two numbers is in double digit print NO
As an idea. It is enough to check whether the result of the addition is less than 10 and greater than -10 if the numbers are signed.:)

Printing range of number upward or backward according to users first input [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to print a range of integers (all the positive integers that to be found between the user's 2 input integers) and I need to do it by the order the user typed it.
for example:
for the input: 4,9 output would be: 4 5 6 7 8 9
and for the input: 9,4 the output would be: 9 8 7 6 5 4
I'm not allowed to use any array/strings/functions, just basic C commands.
Anybody have any ideas?
Since this is most likely a learning exercise, here are some points to think about:
You need a loop.
The loop starts at the first number the user enters, and ends upon reaching the second number
The step of the loop depends on the order of the numbers entered by the user
If the first number is smaller than the second one, the step of the loop is one
If the first number is larger than the second one, the step of the loop is negative one
Therefore, the structure of your program is going to be as follows:
Prompt the user for the two numbers
Read numbers one and two
Compute the step using an if
Print out the range using a loop (for, while, or do/while, it's up to you).
This should be enough to complete your assignment. Good luck!

Resources