answersLogoWhite

0


Best Answer

So is it 8 or 15?

printf ("%-15u", state); or

printf ("%-8u", state);

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

So is it 8 or 15?

printf ("%-15u", state); or printf ("%-8u", state);

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write printf state for unsigned integer 40000 left justified in a 15-digit field with 8 digit field?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can you declare printf for integer variable?

printf is declared in stdio.hFormat specifier for an integer value is %d.


How do you write a c program which accepts a positive integer and displays the number of digits?

#include#includevoid main(){unsigned long int num;int i=0;clrscr();printf("Enter the digit\n");scanf("%lu",&num);while(num!=0){num=num/10;++i;}printf("Length=%d",i);getch();}


How do you write a program to find magic numbers?

#include<stdio.h> unsigned sum_row (unsigned* sq, const unsigned width, const unsigned row) { unsigned sum, col; sum = 0; for (col=0; col<width; ++col) sum += sq[row*width+col]; return sum; } unsigned sum_col (unsigned* sq, const unsigned width, const unsigned col) { unsigned sum, row; sum = 0; for (row=0; row<width; ++row) sum += sq[row*width+col]; return sum; } unsigned sum_diag (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=0; row<width; ++row, ++col) sum += sq[row*width+col]; return sum; } unsigned sum_anti (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=width-1; row<width; ++row, --col) sum += sq[row*width+col]; return sum; } bool is_magic (unsigned* sq, const unsigned width) { unsigned magic, row, col; magic = sum_row (sq, width, 0); for (row=1; row<width; ++row) if (magic!=sum_row(sq, width, row)) return false; for (col=0; col<width; ++col) if (magic!=sum_col(sq, width, col)) return false; if (magic!=sum_diag(sq, width)) return false; if (magic!=sum_anti(sq, width)) return false; return true; } int main () { const unsigned width = 3; unsigned a[width][width] {{2,7,6},{9,5,1},{4,3,8}}; unsigned row, col; printf ("Square:\n\n"); for (row=0; row<width; ++row) { for (col=0; col<width; ++col) { printf ("%d ", a[row][col]); } printf ("\n"); } printf ("\n"); if (is_magic((unsigned*)&a, width)) printf ("The square is magic with a magic constant of %d\n", sum_row((unsigned*)&a, 3,0)); else printf ("The square is not magic\n"); return 0; }


How do write a program to output prime numbers between 1-1000 using c?

main() { int i,n,p,v; printf("enter the number of terms"); scanf("%d",&n); for(i=2;i<=n;i++) { for(j=1;j<i;j++) { if(i%j==0) v=v+1; else p=p+1; } } printf("%d is a prime",i); } check this out


How do you write a C program to check whether a number is prime or not and to find the nth prime number?

int number; int i=2; while (i<number) { if(number%i==0) { printf("Not a prime no."); break; } else printf("number entered is prime"); getch(); }

Related questions

Why we use percent you in c language?

%u is a printf format specifier that says to take the next argument and display it as an unsigned decimal number, assuming standard integer length.


Can you declare printf for integer variable?

printf is declared in stdio.hFormat specifier for an integer value is %d.


How do you write a simple program in c to check whether a number is a palindrome or not?

unsigned reverse (unsigned n) { unsigned r = 0; while (n) { r *= 10; r += (n%10); n /= 10; } return r; } bool is_palindrome (unsigned n) { return n == reverse (n); } int main () { unsigned num; printf ("Enter a number: "); scanf ("%d", num); if (is_palindrome (num)) printf ("%d is a palindrome\n"); else printf ("%d is not a palindrome\n"); return 0; }


How do you write a c program which accepts a positive integer and displays the number of digits?

#include#includevoid main(){unsigned long int num;int i=0;clrscr();printf("Enter the digit\n");scanf("%lu",&num);while(num!=0){num=num/10;++i;}printf("Length=%d",i);getch();}


How do you write a C program that inputs an integer and identify whether it is prime or composite?

#include<stdio.h> #include<math.h> bool is_prime (unsigned num) { if (num<2) // 0 and 1 are composite return false; if (!(num%2)) // 2 is the only even prime return num==2; const unsigned max_div = sqrt (num) + 1; for (unsigned div=3; div<max_div; div+=2) { if (!(num%div)) // the number is composite return false; } // if we get this far, the number is prime return true; } int main (void) { unsigned num; printf ("Enter a positive integer: "); scanf ("%u", &num); printf ("\n%u is %s\n", num, is_prime (num) ? "prime" : "composite"); return 0; }


What is the use of percent in printf statement in c?

It is a flag character that precedes the variable type place holder. %d %i Decimal signed integer. %o Octal integer. %x %X Hex integer. %u Unsigned integer. %c Character. %s String. See below. %f double %e %E double. %g %G double. %p pointer. %% %. No argument expected.


How do you write a program to find magic numbers?

#include<stdio.h> unsigned sum_row (unsigned* sq, const unsigned width, const unsigned row) { unsigned sum, col; sum = 0; for (col=0; col<width; ++col) sum += sq[row*width+col]; return sum; } unsigned sum_col (unsigned* sq, const unsigned width, const unsigned col) { unsigned sum, row; sum = 0; for (row=0; row<width; ++row) sum += sq[row*width+col]; return sum; } unsigned sum_diag (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=0; row<width; ++row, ++col) sum += sq[row*width+col]; return sum; } unsigned sum_anti (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=width-1; row<width; ++row, --col) sum += sq[row*width+col]; return sum; } bool is_magic (unsigned* sq, const unsigned width) { unsigned magic, row, col; magic = sum_row (sq, width, 0); for (row=1; row<width; ++row) if (magic!=sum_row(sq, width, row)) return false; for (col=0; col<width; ++col) if (magic!=sum_col(sq, width, col)) return false; if (magic!=sum_diag(sq, width)) return false; if (magic!=sum_anti(sq, width)) return false; return true; } int main () { const unsigned width = 3; unsigned a[width][width] {{2,7,6},{9,5,1},{4,3,8}}; unsigned row, col; printf ("Square:\n\n"); for (row=0; row<width; ++row) { for (col=0; col<width; ++col) { printf ("%d ", a[row][col]); } printf ("\n"); } printf ("\n"); if (is_magic((unsigned*)&a, width)) printf ("The square is magic with a magic constant of %d\n", sum_row((unsigned*)&a, 3,0)); else printf ("The square is not magic\n"); return 0; }


How do write a program to output prime numbers between 1-1000 using c?

main() { int i,n,p,v; printf("enter the number of terms"); scanf("%d",&n); for(i=2;i<=n;i++) { for(j=1;j<i;j++) { if(i%j==0) v=v+1; else p=p+1; } } printf("%d is a prime",i); } check this out


How do you write a c program to print words when numbers are given?

void print_num_as_word (unsigned num) { switch (num) { case 0: printf ("zero"); break; case 1: printf ("one"); break; case 2: printf ("two"); break; case 3: printf ("three"); break; case 4: printf ("four"); break; case 5: printf ("five"); break; case 6: printf ("six"); break; case 7: printf ("seven"); break; case 8: printf ("eight"); break; case 9: printf ("nine"); break; } }


How do you write a C program to check whether a number is prime or not and to find the nth prime number?

int number; int i=2; while (i<number) { if(number%i==0) { printf("Not a prime no."); break; } else printf("number entered is prime"); getch(); }


How do you write a program in C to find prime numbers between two given numbers?

i ll give you the logic and if u know a lil bit of c u can make it.. accept the two no's from user==> use scanf if the 1st no is 2 print that using printf like>>1st no is prime then put a nested for loop i.e. for (int i = 1st no ;i <=2nd no; i ++) { for (int j= 2 ; j <i; j++) now check for condition if i/j==0 then printf not prime else printf prime so its over u see.....


How do you display 1 2-3 4-...n in c?

main() { int i, n; printf("Enter a positive integer\n"); scanf("%d", &n); for(i=1;i<=n;i++) printf("%d-",i); printf("\b\n"); }