Posted: Tue Dec 11, 2007 3:32 pm Post subject: چند جمله اي
- برنامه که دو چند جمله ای بگیرد و با یکدیگر جمع نماید و حاصل را در خرروجی چاپ نماید . چند جمله ای اول چند متغیر x دارد و بعد ضرایب x را به تر تیب از توان بزرگ به کوچک و عدد ثابت که همان توان 0 بگیرد و برای جمله دیگر نیز به همین ترتیب
#include<iostream.h>
#include<conio.h>
void addup(int,int);
int *arr1,*arr2,power1,power2;
void main()
{
clrscr();
cout<<"Khosh Omadid ..."<<endl;
cout<<"Bozorg tarin tavane jomleye aval ?\n";
cin>>power1;
cout<<"Bozorg tarin tavane jomleye dovom ?\n";
cin>>power2;
addup(power1,power2);
getch();
}
void addup(int pw1,int pw2)
{
int *arr1,*arr2,*result,i,temp;
arr1= new int[pw1+1];
arr2=new int[pw2+1];
for (i=pw1;i>=0;i--)
{
cout<<"Jomleye aval :: Zaribe X ba tavane "<<i<<"ra vared konid"<<endl;
cin>>arr1[i];
}//end of 1st for
for (i=pw2;i>=0;i--)
{
cout<<"Jomleye dovom :: Zaribe X ba tavane "<<i<<"ra vared konid"<<endl;
cin>>arr2[i];
}//end of 2nd for
result=new int( pw1>=pw2 ? pw1 : pw2 );
for (i=( pw1>=pw2 ? pw1 : pw2 );i>=0;i--)
{
result[i]=0;
/* chon daram ba meghdare ghabli jam mikonam age meghdar dehiye avaliye ( 0 ) nashe moshkeli
pish miad, meghdare ghabli ke to on noghte az hafeze boode ro bahash jam mikone */
if (i<=pw1)
result[i]+=arr1[i];
if (i<=pw2)
result[i]+=arr2[i];
}//end of for
/*chap kardane natije ( result )*/
for (i=( pw1>=pw2 ? pw1 : pw2 );i>=0;i--)
{
cout<<result[i]<<"X^"<<i;
if (i!=0)
cout<<" + ";
}
}//end of Function addup
لطفا علامتها را بر عكس كن
****************************************
خدايا مومنم به اينكه هر كس به تو توكل كند شكست نمي خورد
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum