Jump to content
منتدى البحرين اليوم

Recommended Posts

Write a c++ program that inputs an integer large than zero (0) and calculates the sum of the powers from 1 to that integer. For example, if the integer equals to 4, the sum of the powers is 288 (11 + 22 + 33 + 44 ).

 

Your program should display an error message if the input number is not valid. Your program RUN (Input\Output) should be as follows:

Enter a number greater than zero: 4

288

 

Link to comment
Share on other sites

بحل جاهز

لكن ما بتستفيدون منه

بالاضافة للحركة الجديدة الي مسوينها ان الاجوبة المنسوخة يوزعون درجتها على الطلاب الي جايبينها..

حاول على الاقل تغير فيه شوي.

#include <iostream>
using namespace std;
void main(){
int x,sum=0,r=1;
cout<<"Enter a number greater than zero: ";
cin>>x;
if(x>0){
for (int i=1;i<=x;i++){
r=1;
for (int j=1;j<=i;j++)
r=r*i;
sum=sum+r;}
cout<<sum<<endl;
}
else
cout<<"Wrong number"<<endl;
}

وانصحك جربه في البرنامج اول.. ssm9.gif

Edited by مغرور جدا
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
الرد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...