Question

Exercise 7.1 A friend of yours shows you the following method and explains that if number is any two-digit number, the prograQuestion with explanation . C program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

No it's wrong. Because it just prints 8 which addition of two digits. What he did is, just identified two digits and added them while printing. So it will print 8. For clarification see below screenshot.

main.c clang-7 -pthread -lm -o main main.c ./main 1 #include <stdio.h> #include<stdlib.h> 8 2 3 4 int main (void) { 6 7 8 int

To rectify it what I did is, I multiplied the lastDigit with 10(because we divided "number" in the line 7 to find the digit in 10's place). So now we will get 10 into lastDigit and adding first digit which 7 will give 17 as the output. For clarification check out the screenshot below.

main.c > clang-7 -pthread -lm -o main main.c ./main 17 1 #include <stdio.h> #include <stdlib.h> 2 3 4 int main( void ) 5 6 7

Modified code to copy:

#include <stdio.h>
#include <stdlib.h>

int main ( void )
{
   int number = 17;
   int lastDigit = number % 10;
   int firstDigit = number / 10;
lastDigit=lastDigit*10;
   printf ( "%i\n", lastDigit+firstDigit );
   return EXIT_SUCCESS;
}

Hope it helps, if you like the answer give it a thumbs up. Thank you.

Add a comment
Know the answer?
Add Answer to:
Question with explanation . C program Exercise 7.1 A friend of yours shows you the following...
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
  • Modify the program q1.c by adding calls to uthread_join (and making no other changes) so that...

    Modify the program q1.c by adding calls to uthread_join (and making no other changes) so that it always prints the lines “zero” to “three” in order; i.e., its output must always be the following. q1.c code as below: #include <stdlib.h> #include <stdio.h> #include "uthread.h" uthread_t t0, t1, t2; void randomStall() { int i, r = random() >> 16; while (i++<r); } void* p0(void* v) { randomStall(); printf("zero\n"); return NULL; } void* p1(void* v) { randomStall(); printf("one\n"); return NULL; } void*...

  • a) The following program is supposed to convert a binary number to its decimal equivalent. Modify...

    a) The following program is supposed to convert a binary number to its decimal equivalent. Modify the program so that it does the job.(15 points) b) How would you create the executable file of the program (file name: b2d.c) in Linux? (5 points) #include <stdio.h> int main (void) int binary: printf("Enter a binary number:\n"); scanf("%d", &binary): int nofDigit = 0, remain = binary: while (remain > 0) - remain = remain/10; nofDigit++; int digit, dval = 0, bx = binary:...

  • OPERATING SYSTWM Question 31 What is the output of this C program? #include #include void main()...

    OPERATING SYSTWM Question 31 What is the output of this C program? #include #include void main() int mptr, *cptr mptr = (int*)malloc(sizeof(int)); printf("%d", "mptr); cptr = (int)calloc(sizeof(int),1); printf("%d","cptr); garbage 0 000 O garbage segmentation fault Question 8 1 pts If this program "Hello" is run from the command line as "Hello 12 3" what is the output? (char '1'is ascii value 49. char '2' is ascii value 50 char'3' is ascii value 51): #include<stdio.h> int main (int argc, char*argv[]) int...

  • In C programming language: This program will output a right triangle based on user specified height...

    In C programming language: This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or *....

  • In C Once you're certain that you understand what the program is doing, modify it so...

    In C Once you're certain that you understand what the program is doing, modify it so that it: asks for the number of faculty in addition to the number of students. prints the ratio of students to faculty (truncated at 1 decimal place). Test your modified program with several different inputs. Ensure that it works even if the ratio of students to faculty is not a whole number! #include <stdio.h> int main(void) { int nStudents = 0; /* Initialization, required...

  • Question 3 Predict the output of the following C program: #include <stdio.h> void main() { int...

    Question 3 Predict the output of the following C program: #include <stdio.h> void main() { int i = 0; for(; 1; i++){ printf("%d",i); if(i==7) break; } 12pt Paragraph 1 Β Ι Ο Αν και Ta

  • Question 8 Predict the output of the following C program: 5 #include <stdio.h> void binaryCode(int n)...

    Question 8 Predict the output of the following C program: 5 #include <stdio.h> void binaryCode(int n) printf("1"); if(n=2) return; binaryCode(n-1); int i = 0; for(; i<n;i++) printf("O"); binaryCode(n-2); } void main() { binaryCode(3); 12pt v Paragraph Β Ι Ο Avor T²v ...

  • ANSWER ASAP PLEASE IN C Duplicate the program below to a new Program 2, and modify...

    ANSWER ASAP PLEASE IN C Duplicate the program below to a new Program 2, and modify Program 2 such that it generates n random virtual addresses between 0 and 232-1 and computes the page number and offset for each address. Here, do not write to the console. Instead, run your program with n = 1000000 random virtual addresses and compute the total CPU time of the task. Report your findings, as well as how you ran your program. Provide commentary...

  • Modify the program q4.c to use a mutex and one or more condition variables to order the threads to produce the same output as your solution to the first question, where you ordered threads using uthread_join. Your solution must use condition variables to

    #include <stdlib.h>#include <stdio.h>#include "uthread.h"#include "uthread_mutex_cond.h"uthread_t t0, t1, t2;void randomStall() {int i, r = random() >> 16;while (i++<r);}void* p0(void* v) {randomStall();printf("zero\n");return NULL;}void* p1(void* v) {randomStall();printf("one\n");return NULL;}void* p2(void* v) {randomStall();printf("two\n");return NULL;}int main(int arg, char** arv) {uthread_init(4);t0 = uthread_create(p0, NULL);t1 = uthread_create(p1, NULL);t2 = uthread_create(p2, NULL);randomStall();uthread_join (t0, NULL);uthread_join (t1, NULL);uthread_join (t2, NULL);printf("three\n");printf("------\n");}

  • C PROGRAM The following is code prints the current activation record number, the memory address of...

    C PROGRAM The following is code prints the current activation record number, the memory address of the current array, followed by the estimated size of the current activation record as a distance between the current array address and the array address from the previous activation record. I need it to run until a segmentation fault occurs and also it must print the estimated size of the runtime stack as a product of the size of current activation record and the...

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