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

شفو الخطا في الاسايمنت شنو ؟


Recommended Posts

بسم الله الرحمن الرحيم

هلا

شخباركم

 

بغيت منكم اساعدوني وشوفوا لي شنو الخطا اللي سويته مو عارفة بالضبط

تعبت وانا احاول فيه

 

هذا السؤال

Suppose that m and n are integers and m is nonzero. Recall that m is called a divisor of n if n = mt for some integer t; that is, when m divides n, the reminder is 0. Moreover, m is called a proper devisor of n if m < n and m divides n. A positive integer is called perfect if it is the sum of its positive proper devisors.

 

For example, the positive proper devisors of 28 are 1, 2, 4, 7 and 14 and 1+ 2 + 4 + 7 + 14 = 28, therefore, 28 is perfect.

 

Write a program that takes as input a positive integer and then outputs whether the integer is perfect.

 

 

وهذا اللي كتبته

 

#include <iostream>

using namespace std;

int main()

{

int m,n,t,sum;

 

cin>>n;

cout<<"the positive proper devisors of:"<<endl;

cout<<"are"<<endl;

 

for(m=1;m=n-1;m++)

 

n=m*t;

m<n;

n%=m;

m=0;

cout<<n<<endl;

n=sum;

cout<<"perfect"<<endl;

 

 

return 0;

}

 

 

مشكورين مقدما

Link to comment
Share on other sites

أول شيء المفروض تسوين if statement ان يكون m<n و m%n وبعدين تخلين العمليات ..

 

وبالنسبة إلى forloop لازم اقواس لأن أكثر من شيء بتسويه الـfor ..

 

بعد في شيء في السؤال m divides n بس انتي في البرنامج مسوية العكس ..

 

هالاشياء بغض النظر إذا كان البرنامج بيطلع لج الجواب الصح أو لاء بس الأخطاء اللي جفتها قلتها لج

 

عقب ماتعدلين هاي كامل بعدين بنجوف العمليات عشان يطلع لج البرنامج العوامل ويجمعهم :smile:

 

Blue rose

Edited by Blue rose
Link to comment
Share on other sites

مشكووووووووووووووورة أختي روز يعطيج الله ألف عافية يا رب

 

قعدت أحاول في أني أحله بس ما عرفت :dde1: سويت اللي قلتي عليه بس ما عرفت :ssm11::ssm11:

 

 

وهذا اللي سويته شوفيلي وين الخطا

 

#include <iostream>

using namespace std;

int main()

{

int m,n,t;

cin>>n;

cout<<"the positive proper devisors of:"<<endl;

cout<<"are"<<endl;

 

if(m%n==0 && m<n)

{

m/n;

for(m=1;m>=1;m++)

t=3;

n=m*t;

cout<<n<<endl;

 

}

cout<<"perfect"<<endl;

 

 

return 0;

}

 

 

تحياتي

Link to comment
Share on other sites

تبين الحل ولا تبين تعرفين شنو الغلط؟

 

أنا ما عندي ++C هالفصل بس حاولت أحله وصار أوكي

 

#include <iostream.h>

 

int main ()

{

int m, n, temp, sum = 0;

 

cout << "Enter a positive integer: ";

cin >> n;

 

for (m = 1; m < n; m++)

{

temp = n % m;

 

if (temp == 0)

sum += m;

}

 

if (sum == n)

cout << "The integer you entered is perfect.\n";

 

else

cout << "The integer you entered is not perfect.\n";

 

return 0;

}

 

Edited by TheBaDBoY
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...