2 solutions

  • 0
    @ 2026-9-13 11:59:21

    #include<bits/stdc++.h> using namespace std; int main(){

    int n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++) sum+=i;
    cout<<sum;
    
    return 0;
    

    }

    • -1
      @ 2024-8-23 20:08:50
      #include<iostream>
      #include<cmath>
      using namespace std;
      int f(int n)
      {
          if(n==1)
              return 1;
          else
              return n+f(n-1);
      }
      int main()
      {
          int n;
          cin>>n;
          cout<<f(n)<<endl;
          cin>>n;
      }
      
      • 1

      Information

      ID
      935
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      1
      Tags
      (None)
      # Submissions
      61
      Accepted
      43
      Uploaded By