1 solutions

  • 0
    @ 2024-7-20 20:35:43

    其实大可以不用循环

    a[n]=a[1]+(n-1)*d

    #include<bits/stdc++.h>
    using namespace std;
    int a1,a2,d,n;
    int h[1005];
    int main(){
    	cin>>a1>>a2>>n;
    	d=a2-a1;
    	h[1]=a1;
    	h[2]=a2;
    	for(int i=3;i<=n;i++){
    		h[i]=h[i-1]+d;
    	}
    	cout<<h[n];
    	return 0;
    }
    
    • 1

    Information

    ID
    6876
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    1
    Tags
    # Submissions
    5
    Accepted
    5
    Uploaded By