Programming Assignment الحل الثاني
4 مشترك
صفحة 1 من اصل 1
Programming Assignment الحل الثاني
السلام عليكم ..
هادا حلي لوظيفة البرمجة ..
اي سؤال على طريقتي بالحل مرحب فيه
واي ملاحظة او تعديل بكون شاكر للمساهمين معنا
هادا حلي لوظيفة البرمجة ..
اي سؤال على طريقتي بالحل مرحب فيه
واي ملاحظة او تعديل بكون شاكر للمساهمين معنا
السؤال الأول:
Write a program to do the following:
$ declare the two dimension array NUM of five rows and five columns
$ fill in the array elements with values as follows
Hint : build and call a function power
$ call a function printing(…) to print the elements of the array on the screen
$ print the sum of the elements in a selected column m
- الكود:
//++++++++++++++++++++++++++++++++++++++++++++++
// Name: Basel Younes AlTamimi ~||~ ID: 100005
//++++++++++++++++++++++++++++++++++++++++++++++
//Q1))..
#include <iostream>
#define row 5
#define column 5
using namespace std;
int power(int n,int y);
void PrintNUM();
void PrintSum();
int NUM [row][column] ;
int main (){
int temp ;
for(int i=1 ; i<row ; i++){
NUM[i-1][0] = 1;
for(int j=1 ; j<=column ; j++)
NUM[i-1][j] = power(i , j);
}
//for printing
PrintNUM();
cout<<"\n\n";
//column summation
PrintSum();
cout<<endl;
system ("pause");
return 0;}
int power(int n , int y){
int pwr = 1 , sum = 0;
for(int i=0 ; i< y ; i++){
pwr = pwr * n;}
return pwr;
}
void PrintNUM()
{int temp;
cout<<"the power array as the following:\n"
<<"---------------------------------\n"
<<"0 1 2 3 4 ....column numbers....\n"
<<"^^^^^^^^^^^^^^^^^\n";
for(int i=0 ; i<(row-1) ; i++){
for(int j=0 ; j<column ; j++){
if(NUM[i][j] < 10)
cout<< NUM[i][j] <<" ";
else
cout<< NUM[i][j] <<" ";}
cout<<endl;}
}
void PrintSum(){
int SelectedColumn;
for(int j=0 ; j<column ; j++)
NUM[4][j] = 0;
//column summation
cout<<"enter the column number to find its summation: ";
cin>> SelectedColumn;
if(SelectedColumn>4 || SelectedColumn<0)
cout<<"error!!\n";
else{
for(int i=0 ; i<(row-1) ; i++){
NUM[row-1][SelectedColumn] = NUM[row-1][SelectedColumn] + NUM[i][SelectedColumn];
}
cout<< "the summation of the column is "<<NUM[4][SelectedColumn];
}
}
عدل سابقا من قبل Basel Tamimi في 6/5/2011, 5:26 am عدل 1 مرات
تابع للحل السابق ...
السؤال الخامس:
السؤال السادس:
السؤال السابع:
السؤال الثامن:
مش عارف شو كان خاطر ع بالي لما حليتو ^__^
!!!!
.. على كل حل أنس اسهل
Write a program that displays the factorial of (N) numbers using fact_fun(…) that accepts the number and return the result to main.
- الكود:
//++++++++++++++++++++++++++++++++++++++++++++++
// Name: Basel Younes AlTamimi ~||~ ID: 100005
//++++++++++++++++++++++++++++++++++++++++++++++
//Q5))..
#include <iostream>
double fact_fun(int n);
using namespace std;
int main (){
int n;
double fact;
cout<<"enter a number n >>( n <170 )<< to display its factorial \n"
<<"to exit enter -1\n"
<<"-------\n";
cin>>n;
cout<<endl;
while(n!=-1){
if(n==0)
{cout<<"the result is: "<<1<<endl
<<"--------------\n";}
else if (n<0)
cout<<"the entered number should be 0 or greater\n";
else{
fact=fact_fun(n);
cout<<"the result is: "<<fact<<endl
<<"--------------\n";}
cout<<endl<<"enter another number: ";
cin>>n;
}
return 0;
}
double fact_fun(int n){
double fact=n;
for(int i=n-1;i>0;i--)
fact=fact*i;
return fact;
}
السؤال السادس:
Write a program that calls a function fib( n) in which the function receives (n) and prints the first (n) terms of the Fibonacci series.
Example if n=7
The output: 1 1 2 3 5 8 13
- الكود:
//++++++++++++++++++++++++++++++++++++++++++++++
// Name: Basel Younes AlTamimi ~||~ ID: 100005
//++++++++++++++++++++++++++++++++++++++++++++++
//Q6))..
#include <iostream>
void fibon(int n);
using namespace std;
int main (){
int n;
cout<<"this program to print the first (n) terms of the Fibonacci series\n\n"
<<"enter a number:\n"
<<"---------------\n";
cin>>n;
cout<<endl<<"The terms: ";
fibon(n);
cout<<"\n\n";
system ("pause");
return 0;
}
void fibon(int n){
int fib[100];
for(int i=0;i<n;i++){
if (i<2)
fib [i]=1;
else
fib[i]=fib[i-1]+fib[i-2];
}
for(int i=0;i<n;i++)
cout<<fib[i]<<" ";
}
السؤال السابع:
Write a program that calculates how many digits in an entered number n.
- الكود:
//++++++++++++++++++++++++++++++++++++++++++++++
// Name: Basel Younes AlTamimi ~||~ ID: 100005
//++++++++++++++++++++++++++++++++++++++++++++++
//Q7))..
#include <iostream>
double count(double n);
using namespace std;
int main (){
double n,total;
cout<<"This program calculates how many digits in an entered number.\n\n"
<<"enter a number: \n"
<<"---------------\n";
cin>>n;
total=count(n);
cout<<"\nNumber of digits= "<<total;
cout<<"\n\n";
system ("pause");
return 0;
}
double count(double n){
double s=0;
for(double i=n;i>=1;i/=10)
s++;
return s;
}
السؤال الثامن:
Write a program that checks a palindrome property for entered numbers, the number of digits is unknown. You can read the palindrome from either side
Example: 12321 is palindrome , 221122 is palindrome , 12345 is not
- الكود:
//++++++++++++++++++++++++++++++++++++++++++++++
// Name: Basel Younes AlTamimi ~||~ ID: 100005
//++++++++++++++++++++++++++++++++++++++++++++++
//Q8))..
#include <iostream>
void count(int n);
void check(int n,int size);
using namespace std;
int main (){
int n;
cout<<"This program checks a palindrome property for entered numbers\n"
<<"the enterd number would be +ve and has less than 10 digits\n\n"
<<"enter number: \n"
<<"-------------\n";
cin>>n;
if (n<=999999999 && n>=0)
count(n);
else cout<<"your input equil (-) or has a large number of digits!!\n";
cout<<endl;
system ("pause");
return 0;
}
void count(int n){
int size=0;
for(int i=n;i>=1;i/=10)
size++;
check(n, size);
}
void check(int n,int size){
int origin=n;
int num[100],disision=1;
int i,j;
for(int i=0;i<size;i++){
num[i]=n%10;
n/=10;}
for(i=0,j=size-1 ;i<=j,j>=i; i++,j--)
if (num[i]!=num[j]){
disision=0;
break;}
if (disision==1) cout<<"\nThe "<<origin<<" is Palindrome ";
else cout<<"\nThe "<<origin<<" is NOT palindrome ";
cout<<endl;
}
مش عارف شو كان خاطر ع بالي لما حليتو ^__^
!!!!
.. على كل حل أنس اسهل
وبالختام
هاذا ما لدينا ..
وشكراً
^__^
هاذا ما لدينا ..
وشكراً
^__^
رد: Programming Assignment الحل الثاني
شكرا كتير على مساهمتكم انت والاخ انس
بس المشكله انه نعرف نحلهم لما يجو بالامتحان
بس المشكله انه نعرف نحلهم لما يجو بالامتحان
hana- عدد المساهمات : 2
تاريخ التسجيل : 09/03/2011
العمر : 35
رد: Programming Assignment الحل الثاني
حياكم اللهhana كتب:شكرا كتير على مساهمتكم انت والاخ انس
مش صعبات بس بدهم شوية تركيزhana كتب:بس المشكله انه نعرف نحلهم لما يجو بالامتحان
على كل حال جاي اضرابات كتير بنتسلى عليهم
رد: Programming Assignment الحل الثاني
hana كتب:شكرا كتير على مساهمتكم انت والاخ انس
بس المشكله انه نعرف نحلهم لما يجو بالامتحان
العفو ..
وعلى سيرت الامتحان
كل ما تحلي اسئلة اكتر بتصير الفكرة تخطر ع بالك اسرع وبالامتحان ما بتتغلبي
ويمكن تصدف ويجي نفس السؤال اللي حليتيه بالامتحان !!
صفحة 1 من اصل 1
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى
3/7/2011, 11:05 pm من طرف anas mohtaseb
» امتحان الفاينال لمختبر برمجة الحاسوب
26/5/2011, 1:45 pm من طرف Basel Tamimi
» حل سؤال الموظفين والرواتب
22/5/2011, 3:17 pm من طرف Basel Tamimi
» sum program with parameters
22/5/2011, 9:33 am من طرف Basel Tamimi
» مختبر 9
18/5/2011, 5:43 pm من طرف Basel Tamimi
» سلايدات الكتاب للاقسام 4 5 7
6/5/2011, 2:07 pm من طرف Basel Tamimi
» شكرا لكم
4/5/2011, 8:51 pm من طرف anas mohtaseb
» Programming Assignment الحل الثاني
2/5/2011, 7:58 am من طرف Basel Tamimi
» سؤال على ال parallel arrays
1/5/2011, 5:06 am من طرف Basel Tamimi