Question

I need help in this code. Please do it perfectly and 100% correct

Part IV 1. For the following C snippet, write an equivalent code using a for-loop instead of while-loop (10 pts sum - 0; sum2

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main() {
    int i, sum, sum2;

    sum = 0;
    sum2 = 0;
    for (i = 0; i < 100; i++) {
        sum = sum + i;
        sum2 = sum2 + i*i;
    }
    
    printf("%d\n", sum);
    printf("%d\n", sum2);
    return 0;
}

4956 328358

Add a comment
Know the answer?
Add Answer to:
I need help in this code. Please do it perfectly and 100% correct Part IV 1....
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
  • 1. Please write the following code in Python 3. Also please show all output(s) and share...

    1. Please write the following code in Python 3. Also please show all output(s) and share your code. Below is a for loop that works. Underneath the for loop, rewrite the problem so that it does the same thing, but using a while loop instead of a for loop. Assign the accumulated total in the while loop code to the variable sum2. Once complete, sum2 should equal sum1. sum1 = 0 lst = [65, 78, 21, 33] for x in...

  • I need help finding the several errors and several loop errors for I get the final...

    I need help finding the several errors and several loop errors for I get the final output. C++ cLion #include <iostream> using namespace std; int main() { cout << "Welcome to Loop World" << endl; cout << endl; cout << "******************" << endl; cout << "Section I" << endl; cout << "******************" << endl; int sum; // Accumulates the total int i; // Used as loop control variable int numIter; // The number of times to iterate cout << "Enter...

  • I need to add a for or a while loop to the following code. please help...

    I need to add a for or a while loop to the following code. please help needs to be in c++. #include <iostream> #include <string.h> using namespace std; int main() {    char input[100]; cout << "Please enter a character string: "; cin >> input; char *head = &input[0], *tail = &input[strlen(input) - 1]; char temp = *head; *head = *tail; *tail = temp; tail--; head++; cout << "CString = " << input << "\n"; }

  • Please use C programming to write a code segment as an answer. Instead of using an...

    Please use C programming to write a code segment as an answer. Instead of using an while-loop like the following code, please implement a code segment by using a do-while loop. What is the output of the code? #include <stdio.h> void main() {        int i = 0;        while (i < 5);        {               printf(“%d ”, ++i);        } }

  • Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only....

    Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only. Thank you. Pointers and Dynamic Memory – Chapter 11 1. Write code using pointers and the Accounts class from week 1 assignment as follows – create a program in which you a. Create 10 accounts using an array with id’s 0 to 9 and refer to each account using pointer notation b. Add an initial balance of...

  • rewrite this post and code their for loops as while loops. The only thing I need...

    rewrite this post and code their for loops as while loops. The only thing I need to see in the while loop body is a statement that would change the loop counter as the for loop statement would. for (cars = 70; cars < 86; cars++) { } for (planes = 75; planes >= 0; planes--) { } for (trains = 0; trains < 100; trains += 4) { } Part 2: I used my third for loop do {...

  • Hi everyone, I need help In Haskell Coding. Please code in Haskell, Regards 1) Write a...

    Hi everyone, I need help In Haskell Coding. Please code in Haskell, Regards 1) Write a function that takes a list of tuples of three integers each and returns a list consisting of just the tuples that are Pythagorean triples. instead of using a list comprehension, use lambda expression and a function that tests one tuple and returns a Bool. As long as the lambda expression is correct, it is OK to make this simpler by having the lambda calls...

  • I need help putting These in correct order. Java please rearrange the following code into a...

    I need help putting These in correct order. Java please rearrange the following code into a working program based on the expected output. HINT: Use JDoodle to help in verifying the expected output 3. String D books new String 3 System.out.printinfbooks[refsl)h Int ref while (z < 3) System.out.print("books #*): books [0] "Grapes of wrath"; class BookArrays f books [1] Wind"; "Gone With The public static void main (String I ares) int z 0; 22+1; ref- title[2] int [I title new...

  • Part 1: Python code; rewrite this code in C#, run the program and submit - include...

    Part 1: Python code; rewrite this code in C#, run the program and submit - include comments number= 4 guesscount=0 guess=int(input("Guess a number between 1 and 10: ")) while guess!=number: guesscount=guesscount+1 if guess<number: print("Your guess is too low") elif guess>number: print("Your guess is too high") else: print("You got it!!") guess=int(input("Guess again: ")) print("You figured it out in ",guesscount," guesses") Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments #include <iostream> using...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

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