Lập trình đơn giản

No_pvp

cho sồ nguyên dương N là bình phương của một số nguyên. Tính tổng

s=1+4+9+16+25+...+N

ngôn ngữ c++

đầu vào #include<bits/stdc++.h>

gợi ý: 

du=i%10;

tongcacso=tongcacso+du*du*du;

 

Gia Huy
8 tháng 7 2023 lúc 15:27

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

#include <bits/stdc++.h>

int main() {
    int n;
    cin>>n;
    int sum=0;

    for(int i=1;i<=n;i++)
    {
        sum+=i*i;
    }
    cout<<"The total is: "<<sum<<endl;

    for(int j=0;j<=50000;j++)
    {
        int du=j%10;
        int tongcacso=j%10*j%10*j%10;
        cout<<"du="<<du<<endl;
        sum=sum+du*du*du;
        cout<<"\nsum= "<<sum<<endl;
        cout<<"sum= (sum+j*j*j) "<<endl;
    }

    return 0;
}

 

Bình luận (0)

Các câu hỏi tương tự
No_pvp
Xem chi tiết
No_pvp
Xem chi tiết
No_pvp
Xem chi tiết
ytkc
Xem chi tiết
No_pvp
Xem chi tiết
ytkc
Xem chi tiết
ytkc
Xem chi tiết
No_pvp
Xem chi tiết
No_sun
Xem chi tiết