- 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))
5 odpowiedzi
+ 3
n <- readLines('stdin')
n <- as.integer(n[1])
z <- c(1:n)
print(sum(z))
0
it says: object N not found
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))
0
thanks Roberto Onoro
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();
}