Question

c programming What is the output, to the console, once the following code has been executed?...

c programming

What is the output, to the console, once the following code has been executed?

int collatz(int value)

{

if(value % 2 == 0)

return value / 2;

else

return value * 3 + 1;

}

int main()

{

int currentValue = 1:

int 1;

for (i = 0; i < 5; i++)

{

printf("%d\n", currentValue);

currentValue = collatz(currentValue);

}

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//Code after correcting syntax errors

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int collatz(int value)

{

if(value % 2 == 0)

return value / 2;

else

return value * 3 + 1;

}

int main()

{

int currentValue = 1;

int i;

for (i = 0; i < 5; i++)

{

printf("%d\n", currentValue);

currentValue = collatz(currentValue);

}

return 0;

}

===============================

Output:
-----------
1
4
2
1
4
Add a comment
Know the answer?
Add Answer to:
c programming What is the output, to the console, once the following code has been executed?...
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
  • Q4) what is the output after the code below is executed? #include <stdio.h> #1 nclude<string.h> int...

    Q4) what is the output after the code below is executed? #include <stdio.h> #1 nclude<string.h> int main) char abc[100]-"Good Luck in Your Programming Final" int i, ; while(abc[i]!= '\0'){ if(abc[i]' if(abc[i+1]-'&&abci+1] -'0' else printf"c", abcli-1]) printf("\n w = %d return 0; \n", w); Place you answer here 4 l Page

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • Please answer the above queston (in terms of C programming) and explain answer Semester 2 &...

    Please answer the above queston (in terms of C programming) and explain answer Semester 2 & Trimester 3B, 2015 COMP1004 Engineering Programming Question 3 - Repetition (20 marks) Q3(a) What will be printed when the following code is executed? (5 marks] #include <stdio.h> int main() int i, j; for(i=1;i<17;i=i+2) { printf("%d==", i); for(j=i; j>0;j--) printf("#"); printf("\n"); return 0; == # 3 = = # # # 5 == ### ## 7 #### #

  • C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure...

    C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure you test your code. Supplied code #include <stdio.h> int main(void) { char ch; int countA = 0; int countE = 0; int countI = 0; printf("Enter in a letter A, E, or I.\n"); scanf(" %c", &ch); //Replace the following block with your switch if(ch == 'E' || ch == 'e') countE++; else if(ch == 'A' || ch == 'a') countA++; else if(ch == 'I'...

  • C Programming What is the output of the following code? int x=5: x * = 3:...

    C Programming What is the output of the following code? int x=5: x * = 3: printf("%d\n", x): x++: ++x: x = x/2: printf("%d\n", x): printf("%d\n", x++): printf("%d\n", ++x);

  • should be in C language What is the output of the following segment of C code:...

    should be in C language What is the output of the following segment of C code: void CapsLetter (char* x, charl); int main() { char* text; text="This is some sample text."; CapsLetter(text, 'e'); printf("%s", text); return 0; سی void Caps Letter (char* x, char 1) { int i=0; while (x[i]!='\0') { if (x[i]==1) x[i]=1-32; } 1. This is som sample text. 2. THIS IS SOME SAMPLE TEXT. 3. This is some sample text. 4. this is some sample text. What...

  • What is printed when the following code is executed? #include <stdio.h> int main() { for (int...

    What is printed when the following code is executed? #include <stdio.h> int main() { for (int i=3, j=5; i>=0; i-=2, j+=j*i) { printf("%d", j); منم }

  • Programming C....... function code is clear but compile is wrong .. I input 8 and compiled...

    Programming C....... function code is clear but compile is wrong .. I input 8 and compiled 2 0 1 1 2 3 5 8 13.. look first number 2 is wrong. The correct answer 8 is 0 1 1 2 3 5 8 13 21.. Need fix code to compile correctly.. Here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[1000]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for (...

  • I am trying to write C programming code and output will be as below but I...

    I am trying to write C programming code and output will be as below but I donno how to get the result analysis part. help me to add the 2nd part with my code: here is my code below: #include <stdio.h> #define MAX 100 struct studentMarkVariable{ int id; float marks; }; void getData(struct studentMarkVariable arrs[]); void show(struct studentMarkVariable arrs[]); int main() { printf ("####### Marks Analyzer V3.0 ####### \n");       struct studentMarkVariable arrs[MAX];     getData(arrs);     show(arrs); return 0; }...

  • C Programming I was given this code to display the following as the output but it...

    C Programming I was given this code to display the following as the output but it does not seem to work. what is wrong? or can someone guide me through the steps? thanks! I have created the txt file named myfile.txt but the program will not compile. please help. I am forced to use Microsoft visual studio. This program makes a duplicate copy of a file (reads input from a file and write output to another file) 1 #include <stdio.h>...

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