Question
In C language

5. What is the OUTPUT of each of these programs? If you arent 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 f ( sum %d\n, return 0; sum); main/ (c) <stdio.h> #include int main ) main int count; int product 1; for (count1; count<15; count + 5) product-product count; for count printf(product return 0 main / %d\n, product);
0 0
Add a comment Improve this question Transcribed image text
Answer #1

5) a)

Output: 25

Explanation: Here the program is doing the summation of all the numbers from 1 to 10

We have for loop from count = 1 to count = 10 and with everytime count increasing as count = count + 2

So the loop will iterate for i = 1,3,5,7,9

i = 1

sum = sum + count

sum = 0+ 1;

sum = 1

i=3

sum = sum + count

sum = 1+ 3;

sum = 4

.....

similarly it will go till count =9

and we get sum = 25.

5) b)

Output: 66

Explanation: Here the program is doing the summation of all the numbers from 1 to 15

We have for loop from 1 to 15 and with counter increasing as count = count +5 so the loop will iterate for i =1, 6, 11

i = 1

product = product * count

product = 1*1;

product = 1

i=6

product = product * count

product = 1*6;

product = 11

product = product * count

product = 6*11;

product = 66

and we get product = 66.

Add a comment
Know the answer?
Add Answer to:
In C language 5. What is the OUTPUT of each of these programs? If you aren't...
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
  • 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...

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • 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()...

  • 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...

  • /* •   The following code consists of 5 parts. •   Find the errors for each part...

    /* •   The following code consists of 5 parts. •   Find the errors for each part and fix them. •   Explain the errors using comments on top of each part. */ #include <stdio.h> #include <string.h> int main( ) { ////////////////////////////////////////////////////////////////////////// //////////////        Part A. (5 points)                ////////////////// int g(void) { printf("%s", Inside function g\ n " ); int h(void) {       printf(" % s ", Inside function h\ n "); } } printf("Part A: \n "); g(); printf(" \n"); ////////////////////////////////////////////////////////////////////////// //////////////       ...

  • 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?

  • 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(“     |                                             |    ...

  • What is the output of the following program? Show each step  to get to the output #include...

    What is the output of the following program? Show each step  to get to the output #include <stdio.h> int f(int* a, int* b); int main() {        int a = 6, b = 7, c = 8;        b = f(&c, &a);        printf("a = %d, b = %d, c = %d\n", a, b, c);           return 0; } int f(int* a, int* b) {        *a = *a + *b;        *b = *a - *b;        printf("a = %d,...

  • C program. Using do-while loop for this question. Question: write a program to calculate the average...

    C program. Using do-while loop for this question. Question: write a program to calculate the average of first n numbers. output: Enter the value of n : 18 The sum of first 18 numbers =171 The average of first 18 numbers = 9.00 my code couldn't give me the right avg and sum. Please help. #include<stdio.h> int main() {     int num;     int count =0;     int sum=0;     float avg;      printf("Enter the value of n: ");    ...

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