PART A: Predict how many lines of output will be displayed by the following program fragment:
i = 0
do
{
for (j = 0; j < 4; j = j + 1)
printf("%d\n", i + j);
i = i + 1;
}
while (i < 5);
PART B: Then write either a C or a C++ program to verify your prediction.
I know it will output 20 lines, the full C++ code is what I need.
Following is a full code written in c++
#include<iostream>
using namespace std;
int main()
{
int i = 0, j;
do
{
for(j = 0;j < 4 ;j = j+1)
cout<<i+j<<endl;
i = i + 1;
}while(i < 5);
return 0;
}
OutPut :-
PART A: Predict how many lines of output will be displayed by the following program fragment:...
6. First try to predict how many times will the following for loops execute? What is the output for (i = 17; i>1; i = i/2) for (i = 2; j <i; j = 1 + 3) cout <<j«<i+j << endl; Then create a main program to include this code, compile and run to check your prediction -7. Write a program to show the first two passes in the execution of the Bubble sort on the following ordered set (show...
Write the output from the following code fragment: for (int i = 1; I < 7; ++i) { switch (i) { case 1: printf ("\n%d Banana", i); case 2: printf ("\n%d Kumquat", i);
Part D. On executing the below program, what will be the output of the following program if the source file contains a line "This is a sample."? [5 marks] #include <stdio.h> int main() { char ch; int k, n=0; FILE * fs = fopen("source.txt", "r"); while(1) { ch = fgetc(fs); if(ch == EOF) break; else { for(k=0;k<4;k++) fgetc(fs); printf("%c", ch); n += k; } } printf("%d\n", n); fclose(fs); return 0; } ---------------------------------- Any one can explain the question to me...
What is the output of the following fragment? please explain. C language int i = 1; int j = 1; while (i < 5) { i++; j = j * 2; } printf(“%d”, j); (a) 4 (b) 8 (c) 16 (d) 32
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...
( C prog) write an output for the following code fragment int a[]= {1, 2, 3, 4, 5, 6}: int *ip; int i; ip=a; ip +=3; *ip= *ip * 3; for (i=0; i <6; ++i) printf("%d," a[i]);
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 ...
C++ Write a program that asks for a number and then prints as many lines as the user inputs. Each line contains as many pairs of characters ("*#") as the number of this line. It should look like the right half of a pyramid. Your version of the program must print the same result as the expected output. To to this lab, you must use two do-while loops. Two exceptions: When the user inputs a number less than 1, then...
Given the following code in C, what is the output of this program? (10 Points) int mainO f 5. int i=10; for(int j-l;j-3;j++) int i=5 printf("i=%dn', i); printf("f%d\n", i); return 0;
1-Is it possible to run a program without a main() function? Yes No 2- How many main() functions can one have in a program? 2 This depends on what compiler you use. As many as you like 1 3- What does the following code fragment leave in x? char a = 'A'; int x = sizeof (a); 1 Depends on what compiler you use. 4 2 4- True or false: In a C program I can have two functions with...