Given a number N as input, output the sum of all numbers from 1 to that number | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
- 1

Given a number N as input, output the sum of all numbers from 1 to that number

n <- readLines('stdin') n <- as.integer(n[1]) x <- c(1:N) for(i in 1:N){ sum <- sum + i } print(sum(x))

19th Oct 2021, 7:04 AM
Tree
Tree - avatar
5 ответов
+ 3
n <- readLines('stdin') n <- as.integer(n[1]) z <- c(1:n) print(sum(z))
19th Oct 2021, 7:41 AM
Roberto Onoro
Roberto Onoro - avatar
0
it says: object N not found
19th Oct 2021, 7:21 AM
Tree
Tree - avatar
0
so now what's wrong with this one: N <- readLines('stdin') N <- as.integer(N[1]) x <- c(1:N) for(i in 1:N){ print(n*(n+1)/2))
19th Oct 2021, 7:27 AM
Tree
Tree - avatar
19th Oct 2021, 7:43 AM
Tree
Tree - avatar
0
void main() { int n, i, s=0; clrscr(); printf(”Enter number :”); scanf(”%d”, &n); for(i=1;i<=n;i++) s+=i; print(”The sum of 1 to %d is %d”, n, a); getch(); }
21st Oct 2021, 5:31 AM
sree harsha
sree harsha - avatar