Question

Need help with these questions in C programming:

9. What is the output of the following code? int X[10]={0}; int N=4; for(int k=0; k<N:k++) X[k] = k*2: printf(%d, X[N/2]; 1

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

9. This program will generate a compilation error.
because in the statement
printf("%d",X[N/2];
There is no closing bracket. so there will be an error

but if we solve the error the output generated for the program is:
0,0,4,4

The array is initially initialized to 0. at every iteration the value of k*2 is getting inserted into the array
In the print statement it is printing X[N/2]
N=4
so X[N/2]=X[4/2]=X[2]
in the first 2 iterations X[2] is not initialized yet hence X[2] is given 0
in the last 2 iterations X[2] is generated as 4, so it will be printed.

program:

#include<stdio.h> int main() int X[10]={@}; int N=4; for(int k=0; k<N;k++) X[k]=k*2; printf(%d,,X[N/2]);

Output:

0,4,4, Process exited after 0.01832 seconds with return value @ Press any key to continue . . .

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

10.
a.
ofPtr = fopen("oldmast.dat","r");

opening the file oldmast.dat using fopen function in read mode ("r"). Assigning to file pointer ofPtr

b.
tfPtr = fopen("trans.dat","w");

opening the file trans.dat using fopen funtion in write mode ("w")

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

11.

value of
i1 = 11
i2 = 23
f1 = 79.0
c1 = A
c2 = B

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

12.
After the execution of the given code, the value of x,y and z will be:
x=0
y=1
z=5

Add a comment
Know the answer?
Add Answer to:
Need help with these questions in C programming: 9. What is the output of 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
  • Need help in c++ programming to output the lines in my code: if word if found:...

    Need help in c++ programming to output the lines in my code: if word if found:            cout << "'" << word << "' was found in the grid" << endl;            cout << "'" << word << "' was not found in the grid" << endl; The words can be touching if they are horizontally, vertically, or diagonally adjacent. For example, the board: Q W E R T A S D F G Z X C V B Y U A...

  • C programming Question1 (a) Write a C program that will print out all command line arguments,...

    C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...

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

  • C program take values to 9 and the second can take values to 12 if (x...

    C program take values to 9 and the second can take values to 12 if (x > 2^3) printf("d", x); Int s-e; 21. LOST) Write a statement that declare an array of doubles with two indices, such that the first index can 22 (LOL) The following code will print out: 23. (L02.) The following code will print out: PART 2 Fill in the banks questions 3 marts x + 5; else x -- 2; char "stri - "abcd"; char str2[]...

  • Output all combinations of character variables a, b, and c. If a x,b-y, and c z, then the output ...

    write solution to the program above in C please and thank you. Output all combinations of character variables a, b, and c. If a x,b-y, and c z, then the output is Your code will be tested in three different programs, with a, b, c assigned with Χ. 'y', 'z', then with #. 'S. %, then with T, 23 1 #include 3 int main(void) { char a char b; char c; 4. 7 scanf(" scanf(" scanf(" %c %c %c ",...

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

  • What is the output of the following. Explain why this output was obtained. int k[3] =...

    What is the output of the following. Explain why this output was obtained. int k[3] = { 10, 20, 30 }; int *kp; kp = k; printf("%d\n", *kp + 2); printf("%d\n", *(kp + 2)); Find the output of the following: double z = 56.4; double *p; p = &z; printf("%lf\n", *p / 2); Suppose the following array has already been declared. Declare a pointer to this array and then use the pointer in a loop to multiply each array value...

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

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • URGENT. Need help editing some C code. I have done most of the code it just...

    URGENT. Need help editing some C code. I have done most of the code it just needs the following added: takes an input file name from the command line; opens that file if possible; declares a C struct with three variables; these will have data types that correspond to the data types read from the file (i.e. string, int, float); declares an array of C structs (i.e. the same struct type declared in point c); reads a record from 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
ADVERTISEMENT