C programming how to set fill to printf? [duplicate] - c

This question already has answers here:
Pad with asterisks in printf?
(3 answers)
Is there any setfill() alternative for C?
(5 answers)
Closed 5 years ago.
In the C programming language, I can specify spaces before the arguments to print out columns.
printf("%10i", 50);
How can I set the fill to be underscores or dashes instead?
________50

Related

How to make an intermediate printf()? [duplicate]

This question already has answers here:
How to pass variable number of arguments to printf/sprintf
(7 answers)
C: Passing variable number of arguments from one function to another
(5 answers)
Closed 2 years ago.
Suppose I have a function name my_print(int flag_1, /* what goes here? */).
Its objective is the same as printf(), but it should only print when flag_1 is "true".
How would I write the function's header and body?
Note: I know I can just write if (flag_1) printf(/*something*/);, but how would I put that into a function?

Computational error of pow function in calculation of mathematical expression in language c [duplicate]

This question already has answers here:
Why does pow(n,2) return 24 when n=5, with my compiler and OS?
(4 answers)
Why does pow(5,2) become 24? [closed]
(3 answers)
Closed 2 years ago.
This code is part of an original code
Why the output of this code displays the number 24?
The output of this Code should be number 25!
Where's the problem with this code?
The compiler used is CodeBlocks
Thanks
int A=7;
A = pow((((A+1)/2)+1),2);
printf("%d", A);

usage of !!, __warned and __ret_warn_once as int in WARN_ON_ONCE macro definition [duplicate]

This question already has answers here:
What is "!!" in C? [duplicate]
(7 answers)
!! c operator, is a two NOT?
(4 answers)
Closed 3 years ago.
I was going through the WARN_ON_ONCE macro definition. I have doubt regarding the following line, what is the use of !! before condition. If we remove !! then also same will be stored in __ret_warn_once.
int __ret_warn_once = !!(condition);
What will happen when compiler executing the following source line.
static bool __section(.data.unlikely) __warned;

C Preprocessor Instructions (SQR-Funktion) [duplicate]

This question already has answers here:
The need for parentheses in macros in C [duplicate]
(8 answers)
Closed 6 years ago.
Want to know how "11" is the answer of this c preprocessor instruction:
#define SQR(x) x*x
int main()
{
SQR(2+3);
}
Try expanding the macro manually.
It will be 2+3*2+3 and this is evaluated as 11.

How to randomize numbers with no repeat in C? [duplicate]

This question already has answers here:
Unique (non-repeating) random numbers in O(1)?
(22 answers)
Unique random number generation in an integer array [duplicate]
(9 answers)
Closed 8 years ago.
I want to randomize number in each element of array in a variabel. I currently use srand() function. But, with this function i could get a same number in two or more element of array.
the output of my program is
number[0]=6
number[1]=3
number[2]=8
number[3]=3
See, number[1] and number[3] has same value. How to prevent this thing happen?

Resources