lisek
 |
Wysłany:
Czw 15:25, 08 Lis 2007 Temat postu: programy na koło |
|
siema na razie udało mi się napisać pierwsze trzy programy na koło, jak są jakieś błędy to dajcie znać:
1 liczby z przedziału a ;b których dzielnikiem jest d
Kod: |
#include <iostream.h>
#include <math.h>
#include <conio.h>
int main(int argc , char *argv[])
{
clrscr();
int a,b,l,i;
if(argc==4)
{
a=atof(argv[1]);
b=atof(argv[2]);
l=atof(argv[3]);
}
else
{
cout<<"Podaj dolna granice przedzialu :"<<endl;
cin>>a;
cout<<"Podaj gorna granice przedzialu :"<<endl;
cin>>b;
cout<<"Podaj dzielnik :"<<endl;
cin>>l;
}
cout<<"Liczby z przedzialu od "<<a<<" do "<<b<<" podzielne na "<<l<<" to:"<<endl;
{
for(i=a;i<=b;i++)
if((i%l)==0)
{
cout<<i<<"\t";
}
if(a==0)
if(b==0)
if(l==0)
{
cout<<"Nie ma takich liczb "<<endl;
}
}
cout<<"\nNacisnij dowolny klawisz\n"<<endl;
getch();
return 0;
} |
2. Program wyszukujący dzielniki l w przedziale a;b
Kod: |
#include <iostream.h>
#include <math.h>
#include <conio.h>
int main(int argc , char *argv[])
{
clrscr();
int a,b,l,i;
if(argc==4)
{
a=atof(argv[1]);
b=atof(argv[2]);
l=atof(argv[3]);
}
else
{
cout<<"Podaj dolna granice przedzialu :"<<endl;
cin>>a;
cout<<"Podaj gorna granice przedzialu :"<<endl;
cin>>b;
cout<<"Podaj liczbe dla ktorej zostana wyszukane dzielniki :"<<endl;
cin>>l;
}
cout<<"Liczby z przedzialu od "<<a<<" do "<<b<<" bedace dzielnikami "<<l<<" to:"<<endl;
{
for(i=a;i<b;i++)
if((l%i)==0)
{
cout<<i<<"\t";
}
if(a==0)
if(b==0)
if(l==0)
{
cout<<"Nie ma takich liczb "<<endl;
}
}
cout<<"\nNacisnij dowolny klawisz\n"<<endl;
getch();
return 0;
}
|
3 Program wyszukujący wartość k - tego elementu ciągu Fibonacciego
Kod: |
#include <iostream.h>
#include <conio.h>
#include <math.h>
fib(long);
int main(int argc, char *argv[])
{
clrscr();
long k;
if (argc==2)
{
k=atof(argv[1]);
}
else
{
cout<<"Podaj ktory element ciagu fibonacciego chcesz uzyskac :"<<endl;
cin>>k;
}
if(k>0)
{
cout<<k<<" element ciagu fibonacciego wynosi "<<fib(k)<<endl;
}
cout<<"\nNacisnij dowolny klawisz\n"<<endl;
getch();
return 0;
}
fib(long element)
{
if(element<=0)
return 0;
if(element<=1)
return 1;
else
return fib(element-1)+fib(element-2);
} |
|
|