CODE MUST BE IN C
1. Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have alreadybeen declared, use a while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total. Use no variables other than n, k, and total.
2. Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j.
3. Given int variables k and total that have already been declared, use a do...while loop to compute the sum of the squares of the first 50 positive integers and store this value in total. Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total. Use no variables other than k and total.
4. Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have alreadybeen declared, use a do...while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total. Use no variables other than n, k, and total.
5.
Given that two int variables, total and amount, have been declared, write a sequence of statements that:
After each value is read in to amount, it is added to the value in total (that is, total is incremented by the value in amount).
6. Given that two int variables, total and amount, have been declared, write a loop that reads non-negative values into amountand adds them into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
1)
#include <stdio.h>
#include <math.h>
int main() {
int n=4,k=1,total=0;
while(k<=4)
{
total+=pow(k,3);
k++;
}
printf("Sum of cubes :%d",total);
return 0;
}
===========================
output:
==============================
2)
#include <stdio.h>
#include <math.h>
int main() {
int n=4,j=0;
do
{
printf("*");
j++;
}while(j!=n);
return 0;
}
============================
Output:
===========================
3)
#include <stdio.h>
#include <math.h>
int main() {
int k=1,total;
do
{
total=k*k;
k++;
}while(k!=50);
printf("Sum :%d",total);
return 0;
}
================================
Output:
===============================
4)
#include <stdio.h>
#include <math.h>
int main() {
int n=4,k=1,total=0;
while(k<=4)
{
total+=pow(k,3);
k++;
}
printf("Sum of cubes :%d",total);
return 0;
}
===========================
output:
============================
5)
#include <stdio.h>
#include <math.h>
int main() {
int total=0,amount;
printf("Enter first value :");
scanf("%d",&amount);
total+=amount;
printf("Enter first value :");
scanf("%d",&amount);
total+=amount;
printf("Enter first value :");
scanf("%d",&amount);
total+=amount;
printf("Total :%d",total);
return 0;
}
================================
Output:
===============================
6)
#include <stdio.h>
#include <math.h>
int main() {
int total=0,amount;
printf("Enter number :");
scanf("%d",&amount);
while(amount>0)
{
total+=amount;
printf("Enter number :");
scanf("%d",&amount);
}
printf("Total :%d",total);
return 0;
}
=============================
Output:
=====================Could you plz rate me
well.Thank You
CODE MUST BE IN C 1. Given an int variable n that has been initialized to...
java : Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a do...while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Use no variables other than n, k, and total.
Given an int variable k that has already been declared, use a while loop to print a single line consisting of 97 asterisks. Use no variables other than k. PLEASE ANSWER IN C
Given an int variable n that has already been declared, write some code in C that repeatedly reads a value into n until at last a number between 1 and 10 (inclusive) has been entered.
Convert the following while loop into a for loop. int 1 - 50: int sum-07 while (sum < 1000) sum - sum + 1; Question 35 (2 points) Saved Given an int variable k that has already been declared, use a while loop to print a single line consisting of 80 dollar signs. Use no variables other than k. int sum = 0; for(int i = 100;sum < 10000;1-- sum = sum + i;
In C
An array ints of integers has already been declared and initialized. A function printint has been defined with the following prototype: void printint(int *); Write code that will call printint with a pointer to the second value in the array ints. Note: you will not need to declare an int variable.
Written in python programming for MyProLab :) Please use simple code Assume the availability of a function called printStars. The function receives an integer value as an argument. If the argument is positive, the function prints (to standard output) the given number of asterisks. Thus, if printStars(8) is called, ******** (8 asterisks) will be printed. Assume further that the variable starCount has been declared and initialized with an integer value, possibly negative or zero. Write some code that does nothing...
assume that input is an int array. the array is already declared and initialized wnd every element is assigned to an integer number. in addition assume that the array contains at least 1 element. write a code that contains one while loop abd no other loops to find both maximum and minimum numbers from input. then outout the maximum minus the minumum to the console window. (using java eclipse coding)
4. Given the following code, int x = 5, n; do{ n = 0; for (int i = 0; i < x; i++) { n = n + x; System.out.println(n); } while (x > 1); a) What will be the value of x after the code segment is executed? Initial value of x 5 b) What is the output of the code segment? c) Explain how the flow of control moves in the given code segment. When explaining, show how...
Given that two int variables, total and amount, have been declared write a loop that reads non-negative values into amount and adds them into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0. To read a value into amount use a method, getNum() that we provide for you a class named TC: amount = TC.getNum(); Instructor Notes: amount = TC.getNum(); TC is the name of a class program....
For the C code 1 int loop while(int a, int b) int result 1; while (a < b) t result (atb); return result; Gcc generates the following assembly code: %ebp+8, mov1 movl movl %ebp+12 at 8(%ebp) ,%ecx 12(%ebp) ,%ebx $1,%eax a at b 5 jge L11 leal (%ebx, %ecx), Xodx 8 L12: inull %eax , %eax addl $1,%ecx addl $1, edx cmp1 %ecx , %ebx 9 10 12 13 J8 14 ·L11: .L12 In generating this code, occ makes an...