R programming language.
Write a R code that adds integer 1, 2, 3, …. Until the sum is over 1000. Remember, the upper bound is not known. The stop is handled by the sum when it is over 1000. Students use a) while and b) repeat to do the work
Please Refer below snapshot of code i have commented code as well please refer in case of any doubt please let me know in comment section , i would be happy to help you.
Here is code:-
A)Using while
----------------
#R version 3.3.2
# intializing num and sum
num <- 1
sum <- 0
# test to check if sum is less than 1000 and as soon as it is
greater than 1000 loop should be false
while(sum < 1000){
num=num+1
sum = sum + num
}
print(sum)
print(num)
------------------------
B) using repeat
-----------------
#R version 3.3.2
num <- 1
sum <- 0
repeat{
num=num+1
sum = sum +num
if(sum>=1000){
break
}
}
print(sum)
print(num)
--------------------


Explanation:-
when sum became greater than 1000 then while loop and repeat loop became false so in that time sum is 1034 and that time num value would be 45,
in mathematics we know that sum of n number formula that is:-
n(n+1)/2 if we will put n =45 than 45(46)/2=1035 let us take one number below ie. n =44 so 44(45)/2=990 so at num 45 it will became false first time .in case of doubt and query please do comment Thanks,
R programming language. Write a R code that adds integer 1, 2, 3, …. Until the...
Programming in C language.
Write the code that will test the vakue of an integer variable grade and performs the following actions: if grade is .print the message "Slcth grade" it grade is 7,print the message "Seventh grade if grade is B, print the message 'Eighth grade for any other value of grade, print the message "Not in middle school
CDA-3101 – MIPS Assembly Programming 1. Write the following code segment in MIPS assembly language code: 3. Write a MIPS program to find the sum of squares from 1 to n. Where n=10. For example, the sum of squares for 10 is as follows: 12+22+32+……+n2=385
Code in assembly language please
"Write an assembly 32 bit program that adds two numbers (other than 5 and 6) and stores the value to a variable called 'sum'. Also, use a block COMMENT to depict the name and description of the program, author of the program, and date."
USING PYTHON PROGRAMMING
LANGUAGE
15. Write code to open a file named data.txt, which contains 3 numbers, and print the sum of those numbers to the console 16. Write code that opens a file named words.txt containing an essay, and the prints out the SECOND word in the file to the console
Write a C# program (Integer Math Calculator, the programming requirements are as follows: When typing in 3+4, 10-5, 12*12, 15/5 from console, the program should give the right answers on screen like 7, 5, 144, 3. This is what I have so far: namespace ConsoleApplication3 { class Program { static void Main(string[] args) { String input; do { Console.Write("Type int values to calulate or stop to exit: "); input = Console.ReadLine(); if (input.ToLower() != "stop") { char[] delimiters = {...
Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2 is equal to the sum of the first n odd numbers. For example, 16 = 4^2 = 7 + 5 + 3 + 1. Write a function that takes as input a natural number, n, and that returns the square of its input by adding the first n odd numbers. Your code may not contain delayed operations and must use accumulative recursion.
Using the C Programming Language: An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each...
Write a MATLABT code that divides an integer n by an integer m using successive addition. Use a while loop to keep adding m until n is reached and exceeded. Return the quotient q and the remainder r:
Programming Problem: SUMMING ARRAY ELEMENTS - Use Assembly Language x86 (MASM) Write an assembly code calculates the sum of all array elements. Save the sum in the EAX register. ------------------------------------------------------------------------------- This is my code so far: INCLUDE Irvine32.inc N=10 .data array SDWORD N DUP(0,1,2,3,4,5,6,7,8,9) j DWORD ? k DWORD ? .code main PROC ; not complete exit main ENDP END main
In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...