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;
}
//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
c programming What is the output, to the console, once the following code has been executed?...
What is the output, to the console, once the following code has executed? 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; }
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* 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 & 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 #### #
QUESTION 6 What is the output of following C code? struct numbers { int x = 2; int y = 3; } int main() { struct numbers nums; nums.x = 110; nums.y = 100; printf("%d\n%d", nums.x, nums.y); return 0; } A. Compile-time Error B. 110 100 C. 2 3 D. Run-time Error 2 points QUESTION 7 What is the output of following C code? typedef struct student { char *stud; }s1; int main() { s1 s; s.stud...
What is the output of the following code: void forkexample() { int x = 1; if (fork==0) printf(“ Child has x = %d\n”, ++x); Else printf(“ Parent has x = %d\n”, - - x); } int main () { forkexample(); Return 0; }
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: 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: 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 i=3, j=5; i>=0; i-=2, j+=j*i) { printf("%d", j); منم }