Concept explainers
Consider the following code (and assume that it is embedded in a complete and correct
char next;
int count = 0;
cout <<“Enter a line of input:\n”;
cin. get(next);
while (next != ‘\n’)
{
if ((count % 2) == 0) True if count is even
cout << next;
count ++;
cin.get(next) ;
}
If the dialogue begins as follows, what will be the next line of output?
Enter a line of input:
abcdef gh
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (4th Edition)
Concepts of Programming Languages (11th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Artificial Intelligence: A Modern Approach
Web Development and Design Foundations with HTML5 (8th Edition)
C++ How to Program (10th Edition)
- (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forwardFind an incorrect line in the following code segment: void swap(int *x, int *y) { int t = *x; *x = *y; *y = t;}....int a = 2, b = 3;swap(*a, *b);arrow_forwardGiven initial values of x= and a code : 2, y = 1 and count 2. count+=y; if (count 3 ) X--; else x++; Give the value of variables after the above code is executed.arrow_forward
- #include<stdio.h> #include<stdlib.h> main() { int m, sum = 0, counter = 0; int first = 2147483647, second = 2147483647, third = 2147483647, min = 2147483647; double average;printf("Enter an int or -1 to stop:\n"); while (1) {scanf_s("\n%d", &m);if (m == -1) { break; } sum = sum + m; counter++; if (m < first first == second first == third ) { third = second; second = first; first = m; } else if (m < second && m !=first ) { third = second; second = m; } else if (m < third && m != second) { third = m; } else if (first == second == third) { printf("min is: %d", first); }}printf("Sum of value: %d \n", sum); average =(double) sum /(double)counter; printf("Avarege is: %.2lf \n", average); printf("First min is: %d\n", first); printf("Second min is: %d\n", second); printf("Third min is: %d\n", third);system("pause"); } can you run this code pleasearrow_forward#include <stdio.h>int main(){int d;int s[20],i, j, p, lg=0,m,t=0;char c;printf("Enter number of sale: ");scanf("%d", &d);for(i=0; i<d; i++){ printf("\n sales %d sales: ",i+1);scanf("%d", &s[i]);}for(i=0; i<d; i++){for(j=i+1; j<d; j++){if(s[i] > s[j]){p= s[i];s[i] = s[j];s[j] = p;}}}printf("\n sales lowest to highest: ");for(i=0; i<d; i++){printf("\nsales %d ", s[i]);}printf("\n highest: %d ",t);getch();} it should be: highest : 2000arrow_forwardProgramming in language Carrow_forward
- 1. Rewrite the program segment that follows, using a for loop and do-while loop: = 1; product i = 0; %3D while (i < n) { scanf(“%d", &a); if (a != i) %3D product *= a; ++i; }arrow_forward#include<stdio.h> #include<conio.h> int mutex=1,full=0,empty=1,x=0; main() { int n; void producer(); void consumer(); int wait(int); int(signal); printf("\n1. Producer \n2. Consumer \n,3. Exit \n"); while(1) { printf("\n Enter the choice:"); scanf("%d", &n); switch(n); { case-1: if((mutex==1)&&(empty!=0)) producer(); else printf("Nuffer is full"); break; case-2: if((mutex==1)&&(full!=0)) consumer(); else print("Buffer is empty"); break; case-3: exit(0); break; } } } int wait(int s) {return(--s); } int signal(int s) { return(++s); } void producer() { mutex = wait(mutex); full = signal(full); empty=wait(empty); x++; printf("\n Producer produces the item %d",x); mutex= signal(mutex); } void consume() { mutex = wait(mutex); full = wait(full); empty = signal(empty); printf("\n Consumer consumes item %d",x); x--; mutex = signal(mutex); } CONVERT THIS C LANGUAGE CODE IN BASH SCRIPT THANKYOUarrow_forward13. Given the code char* myFunc (char *ptr, int n) { ptr += n; return ptr; } int main() { char x[100] = Code1; char *y. int n = Code2; y = myFunc (x, n); printf ("%s\n", y); return 0; } where Code1 and Code2 are not given. Which of the following does not give the output ABCDEF Code1 is "XYZABCDEF" and Code2 is 3 Code1 is "ABCABCDEF" and Code2 is 3 Code1 is "ABCDEFXY" and Code2 is 6 Code1 is "ABCDEF" and Code2 is 0arrow_forward
- /*code Kth Largest Factor A positive integer d is said to be a factor of another positive integer N if when N is divided by d, the remainder obtained is zero. For example, for number 12, there are 6 factors 1, 2, 3, 4, 6, 12. Every positive integer k has at least two factors, 1 and the number k itself.Given two positive integers N and k, write a program to print the kth largest factor of N. Input Format: The input is a comma-separated list of positive integer pairs (N, k). Output Format: The kth highest factor of N. If N does not have k factors, the output should be 1. Constraints: 1<N<10000000000 1<k<600. You can assume that N will have no prime factors which are larger than 13..arrow_forwardPlease explain the coding. Screen shot the code and the output.arrow_forwardmain.c + c Test Cases Executions 3. Negative Fusion by CodeChum Admin 1 E Run Tests As l've said before, there are three types of numbers: the positive, the zero, and the negative ones. Today, we shall pay attention only to the negative ones now. Make a loop that will accept O Test Case 1 random decimal/float numbers. When the user Your Output inputs 0, the loop will terminate and then output No Output the sum of all negative numbers inputted in 3 decimal places. Expected Output Let's code this. Enter a number: 2.4434 Enter a number: -1.3433 Input Enter a number: -2.444 Enter a number: 6.432 1. A series of decimal numbers Enter a number: 0 Sum of all negatives = -3.787 Output The first lines will contain message prompts to input the decimal numbers. The last line contains the sum of all negative numbers with 3 decimal places. O Test Case 2arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr