Question

Please explain the following so I can do them for myself, thank you very much If...

Please explain the following so I can do them for myself, thank you very much

If the following C program were to be compiled, linked, and executed, it would print the value of x . How many zeros would appear to the left of the 1 ?

#include <stdio.h>
int main()
   {
    int x = 1234 ;
    printf ( "%15.6d\n", x ) ;
    return 0 ;
    }

The answer is 2

If the following C program were to be compiled, linked, and executed, it would print the value of  x . How many digits would appear to the right of the decimal point?

#include <stdio.h>
int main()
  {
  double x = 123.456789 ;
  printf ( "%20.4f\n", x ) ;
  return 0 ;
  }
Answer is 4
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If the following C program were to be compiled, linked, and executed, it would print the value of x . How many zeros would appear to the left of the 1 ?

#include <stdio.h>
int main()
   {
    int x = 1234 ;
    printf ( "%15.6d\n", x ) ;
    return 0 ;
    }

Explanatioon:-

here %15.6d in prntf statement, 15 represent the number of space before the integer value and the .6 represent the what should bbe the total integer length. here x have 4 digits, so it will add 2 zero before the integer so the final value will be 001234

If the following C program were to be compiled, linked, and executed, it would print the value of  x. How many digits would appear to the right of the decimal point?

#include <stdio.h>
int main()
  {
  double x = 123.456789 ;
  printf ( "%20.4f\n", x ) ;
  return 0 ;
  }

Explanation:-

here .4f represent the number of decimal point you want after the decimal places, so here .4 is mentioned so, it will print up to 4 decimal places.

Add a comment
Know the answer?
Add Answer to:
Please explain the following so I can do them for myself, thank you very much If...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PART FOUR:(20 points) Predict the output that would be shown in the terminal window when the...

    PART FOUR:(20 points) Predict the output that would be shown in the terminal window when the following program fragments are executed 1. Assume that an int variable takes 4 bytes and a char variable takes 1 byte #include<stdio.h> int main() int A[]-{10, 20, 30, 40); int *ptrl - A; int ptr2 = A +5; printf("The Resull: %d\n".(ptr2-ptrl)); printf("The Resul2: %d\n".(char*)ptr2-(char*)ptr); return 0; 2. What does the following program print? #include <stdio.h> int main(void) unsigned int x 1: unsigned int total...

  • What is the output of the following c program. Why, Can you tell me how do...

    What is the output of the following c program. Why, Can you tell me how do you solve it? #include <stdio.h> int fun(int n) { if(n==0) { return 1; } else return 7 + fun(n-2); } int main() { printf("%d", fun (4)); return 0; | }

  • Suppose that you have three programs that are suppose to print a house diagram in a...

    Suppose that you have three programs that are suppose to print a house diagram in a collaborative manner. (i) prog1.c #include <stdio.h>      /* Input/Output */ #include <stdlib.h>     /* General Utilities */ int main() {     printf(“                      ^^^^^^^^^^^^                       \n”);     printf(“           ^^^^^^^^^^^            ^^^^^^^^^^^            \n”);     printf(“^^^^^^^^^^^                                  ^^^^^^^^^^^ \n”);     printf(“     |                                            |      \n”);     printf(“     |                                            |      \n”);     exit(1); } (i) prog2.c #include <stdio.h>      /* Input/Output */ #include <stdlib.h>     /* General Utilities */ int main() {     printf(“     |                                             |    ...

  • 2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo...

    2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo (int x) 1 return (x+a); void ba r () { printf("%d, %d\n",a,b); void foobar) } printf("%d, %d\n", a, b) ; int a -4; bar bfoo (b); bar int main)( int b 8; foobar printf ("%d, %d\n", a, b) ; return 0; (a) What does the program print under static scoping? (b) What does the program print under dynamic scoping?

  • In C language 5. What is the OUTPUT of each of these programs? If you aren't...

    In C language 5. What is the OUTPUT of each of these programs? If you aren't confident of an answer, type mpile and run the program to test it. (a) <stdio.h> #include int main main int count; int sum0; for (count 1; count10; count++) sum sum+ count; for count printf("sum= %d\n", return 0; sum); )main (b) #include int main ) <stdio.h> main/ int count; int sum -0 for (count 1 count10; count 2) sum sum + count; for count print...

  • C programming problem please help my computer crashed what is the output of each program ?...

    C programming problem please help my computer crashed what is the output of each program ? (c) #include <stdio.h> int main() { /* main */ int f3, t = 9; int func3 (int x); printf("Inside main, t = $d\n", t); f3 - func3(t); printf("Inside main, f3 = %d\n", f3); return 0; } /* main */ int func3 (int x) { /* func3 */ printf("Inside func3, X = %d\n", x); return x; } /* func3 */ (d) #include <stdio.h> int main()...

  • I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a...

    I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = @; for (int i = 0; i < SIZE; i++) { if (arr1[1] > arr2[i]) count++; return count; } Task 1: (10...

  • Q1) Including the initial parent process, how many processes are created by the program shown in...

    Q1) Including the initial parent process, how many processes are created by the program shown in Figure 1? Give an explanation for your answer. You can include an output statement to test and run the program. A sample output statement could be: printf("Testing......"); #include <stdio.h> #include <unistd.h> int main() { /*fork a child process*/ fork(); /*fork another child process*/ fork(); /*fork another child process*/ fork(); return 0; } Figure 1a - How many processes are created? Another version, now displaying...

  • C linux please write it by only using “if and else” conditions, thanks so much this...

    C linux please write it by only using “if and else” conditions, thanks so much this is my task 3 Requirements 1. Copy your solution for Task 3 t3.c to a new file t4.c. 2. The input is guaranteed to contain at least one non-whitespace character. 3. If the input is well-formed, i.e., can be parsed to a number, the program should behave identically to Task 3. All the requirements of Task 3 still apply except the file name. 4....

  • can u please solve it in c++ format,,,, general format which is #include<stdio.h> .......printf and scanf...

    can u please solve it in c++ format,,,, general format which is #include<stdio.h> .......printf and scanf format dont worry about the answers i have down Q3, What is the output of the program shown below and explain why. #include #include <stdio.h> <string.h> int main(void) ( char str[ 39764 int N strlen(str) int nunj for (int i-0; i t Nǐ.de+ printf(") num (str[] 'e); I/ digits range in the ASCII code is 48-57 if (nue > e) f 9 printf( Xdin,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT