Submission

Status:
--------------------

Score: 0

User: Chronicallymi

Problemset: ผลบวก (ง่าย)

Language: c

Time: 0.089 second

Submitted On: 2024-10-04 17:53:39

#include <stdio.h>
#include<math.h>
int main (){
  int n,x,y,i,sum=0;
  printf("enter the amount of inputs ");
  scanf("%d",&n);
  if(n<2){
    printf("input amount too low!");
    return 0;
  }else if(n>1000000){
    printf("input too high!");
    return 0;
  }
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
 printf("please enter the range of the numbers(x-y) : ");
  scanf("%d",&x);
  scanf("%d",&y);
   if(x==0|&y==0){
     printf("y and/or x cannot be 0!");
   }else if(x>y){
    printf("x cannot be higher than y!");
    return 0 ;
  }else if(y>=n){
    printf("y cannot be higher than the amount of inputs!");
  }
  for(i=0;i<n;i++){
    if(x<=a[i] && a[i]<=y){
      sum += a[i];
    }
   }
    printf("the sum of the inputs in the range of %d and %d is %d",x,y,sum);
}