Question

In: Computer Science

int f2 (int n) j = 0; while (j <n) {for (int i = 0; i...

int f2 (int n) j = 0; while (j <n) {for (int i = 0; i <n; ++ i) {cout << "j =" + j; j = j + 5; }}

Solutions

Expert Solution

                       ANSWER : HERE IS THE ANSWER FOR YOUR QUESTION:

  

                       ------------------------------------------------------------------------------------------------------

CORRECT CODE:

#include <iostream>

using namespace std;

int f2 (int n)
{
int j = 0;
while (j <n)
{
for (int i = 0; i <n; ++ i)
{
  
//you are using +j instead of <<j for the output . thats why it was giving wrong output
cout << "j = " << j<<endl;
//incrementing

                       -------------------------------------------------------------------------------------------------------                

                  SNIPPET

                      ---------------------------------------------------------------------------------------------------------

                  OUTPUT

if you need any further assistance , feel free to provide your comments below

                       -------------------------------------------------------------------------------------------------------

I hope this would help you out.

If you like my answer , please upvote

If you have any doubt, you can provide comment /feedback below the answer

Thanks


Related Solutions

import java.util.*; class A { int i, j, k; public A(int i, int j, int k)...
import java.util.*; class A { int i, j, k; public A(int i, int j, int k) { this.i=i; this.j=j; this.k=k; } public String toString() { return "A("+i+","+j+","+k+")"; } } class Main { public static void main(String[] args) { ArrayList<A> aL=new ArrayList<A>(); Random rand= new Random(1000); //1000 is a seed value for (int p=0; p<10; p++) { int i = rand.nextInt(100); int j = rand.nextInt(200); int k = rand.nextInt(300); aL.add(new A(i, j, k)); } System.out.println("----- Original arraylist------"); for (A a: aL)...
def longest(string): start=0;end=1;i=0; while i<len(string): j=i+1 while j<len(string) and string[j]>string[j-1]: j+=1 if end-start<j-i: #update if current...
def longest(string): start=0;end=1;i=0; while i<len(string): j=i+1 while j<len(string) and string[j]>string[j-1]: j+=1 if end-start<j-i: #update if current string has greater length than #max start and end end=j start=i i=j; avg=0 for i in string[start:end]: avg+=int(i) print('The longest string in ascending order is',string[start:end]) print('Teh average is',avg/(end-start)) s=input('Enter a string') longest(s) i need a definition and explanation of this code that how it works?
(C++)Change the following loop to a while loop: int i; for (i=0; i<10; i++) {    ...
(C++)Change the following loop to a while loop: int i; for (i=0; i<10; i++) {     cout<<i<<endl; }
Please explain this code line by line void printperm(int *A,int n,int rem,int j) {    if(n==1)...
Please explain this code line by line void printperm(int *A,int n,int rem,int j) {    if(n==1)       {        for(int k=0;k<j;k++)        cout<<A[k]<<" + ";        cout<<rem<<"\n";        return;       }     for(int i=0;i<=rem;i++)    {          if(i<=rem)          A[j]=i;          printperm(A,n-1,rem-i,j+1);    } }
Consider the following code: void swap(int arr[], int i, int j) {        int temp = arr[i];...
Consider the following code: void swap(int arr[], int i, int j) {        int temp = arr[i];        arr[i] = arr[j];        arr[j] = temp; } void function(int arr[], int length) {        for (int i = 0; i<length / 2; i++)               swap(arr, i, (length / 2 + i) % length); } If the input to the function was int arr[] = { 6, 1, 8, 2, 5, 4, 3, 7 }; function(arr,8); What values would be stored in the array after calling the...
Consider the following function: int counter( int n) { int s = 0;    for ( int...
Consider the following function: int counter( int n) { int s = 0;    for ( int i = 0; i < n; i++)             for ( int j = i; j > 0; j--)                        s = s + 1;   return s; } Part (a): How many times "s=s+1;" will be executed? Determine a precise count.  Show all your work. Part (b): What is the time complexity of the "counter" function in terms of Big-O notation? Justify and show all your work.
#include <stdio.h> int main() { int i, j; printf("Enter two positive integers: "); scanf("%d%d", &i, &j);...
#include <stdio.h> int main() { int i, j; printf("Enter two positive integers: "); scanf("%d%d", &i, &j); // need to validate both being positive while (i != j) { i > j ? (i -= j) : (j -= i); } printf("GCD: %d\n", i); return 0; } The above code returns a GCD from two numbers entered. Use the above program to design a C program to compute of integer coefficients a and b such that gcd(i, j) = a xi...
public void printQueue(DoublyLinkedQueue<Integer> Q){ int len = Q.size(); int k = 0; for (int i=0; i...
public void printQueue(DoublyLinkedQueue<Integer> Q){ int len = Q.size(); int k = 0; for (int i=0; i < len; ++i){ k = Q.dequeue(); Q.enqueue(k);    System.out.println(Q.dequeue()); } } What is the complexity of this code? Select one: a. O(N), N = k b. Q(1) c. Q(N2), N = Q.size() d. O(M), M = Q.size() e. None of the alternatives is correct. which one?
#include <stdio.h> #include <stdlib.h> // required for atoi int main(void) {     int i=0,n,num,filenum[100],pos;     int...
#include <stdio.h> #include <stdlib.h> // required for atoi int main(void) {     int i=0,n,num,filenum[100],pos;     int c;    char line[100]; //declaring string for storing data in the line of text    FILE *fp; // declaring a FILE pointer    fp=fopen("numbers.txt","r"); // open a text file for reading    while(fgets(line, sizeof line, fp)!=NULL) {       // looping until end of the file         filenum[i]=atoi(line); //converting data in the line to integer and storing it into array        i++;    }...
i j(i) i j(i) i j(i) i j(i) 0 -0.0499 7 -0.08539 13 0.144812 19 0.08021...
i j(i) i j(i) i j(i) i j(i) 0 -0.0499 7 -0.08539 13 0.144812 19 0.08021 1 0.107506 8 0.062922 14 -0.0499 20 -0.30103 2 -0.06719 9 -0.04444 15 -0.18366 21 -0.33834 3 -0.04717 10 0.219422 16 -0.02898 22 0.058373 4 -0.09176 11 0.083849 17 0.08021 23 0.79083 5 -0.25918 12 -0.02261 18 -0.14271 24 0.130254 6 0.055643 25 -0.10177 (3 points) Please encipher the following plaintext with Caesar Cipher and the encryption key of 10: TODAYISTUESDAY; (3 points) In...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT