| Ricko Brain
 
  
 
 Dołączył: 07 Sie 2006
 Posty: 3255
 Przeczytał: 0 tematów
 
 Pomógł: 5 razy
 Ostrzeżeń: 0/5
 Skąd: ..::Zabrze::..
 
 | 
            
                |  Wysłany: Śro 13:31, 06 Mar 2013    Temat postu: STUDIA: Petle w C++ | Programy |  |  
                | 
 |  
                | FOR - SILNIA 
 
 
 
	  | Cytat: |  
	  | #include <cstdlib> #include <iostream>
 
 using namespace std;
 
 int main(int argc, char *argv[])
 {
 int n,s=1;
 cout<<"Podaj n"<<endl;
 cout<<"n=";
 cin >>n;
 for (int i=1;i<n+1;i++)
 s*=i;
 cout<<n<<"!="<<s<<endl;
 system("PAUSE");
 return EXIT_SUCCESS;
 }
 |  
 FOR - SUMA OD KRAŃCÓW
 
 
 
 
	  | Cytat: |  
	  | #include <cstdlib> #include <iostream>
 
 using namespace std;
 
 int main(int argc, char *argv[])
 {
 int a,b,s=0,i;
 cout<<"Podaj dwie liczby"<<endl;
 cout<<"a=";
 cin>>a;
 cout<<"b=";
 cin>>b;
 
 if (b > a)
 {
 for (i=a;i<b+1;i++)
 s+=i;
 }
 else
 {
 for (i=b;i<a+1;i++)
 s+=i;
 }
 cout<<"Suma="<<s<<endl;
 system("PAUSE");
 return EXIT_SUCCESS;
 }
 |  
 FOR - WYRAZ CIĄGU FIBONACCIEGO
 
 
 
 
	  | Cytat: |  
	  | #include <cstdlib> #include <iostream>
 
 using namespace std;
 
 int main(int argc, char *argv[])
 {
 int n,i,s1=1,s2=1,pom;
 cout<<"Podaj n"<<endl;
 cout<<"n=";
 cin>>n;
 
 if ((n == 1) || (n == 2))
 cout << "Liczba "<<n<<"=1"<<endl;
 else
 {
 for (i=3;i<n+1;i++)
 {
 pom=s1;
 s1=s1+s2;
 s2=pom;
 }
 cout<<"Liczba wynosi "<<s1<<endl;
 }
 system("PAUSE");
 return EXIT_SUCCESS;
 }
 
 |  
 WHILE - SILNIA
 
 
 
 
	  | Cytat: |  
	  | #include <cstdlib> #include <iostream>
 
 using namespace std;
 
 int main(int argc, char *argv[])
 {
 int n,s=1,i=1;
 cout<<"Podaj n"<<endl;
 cout<<"n=";
 cin >>n;
 while (i<n+1)
 {
 s*=i;
 i++;
 }
 cout<<n<<"!="<<s<<endl;
 
 system("PAUSE");
 return EXIT_SUCCESS;
 }
 |  
 WHILE - SUMA OD KRAŃCÓW
 
 
 
 
	  | Cytat: |  
	  | #include <cstdlib> #include <iostream>
 
 using namespace std;
 
 int main(int argc, char *argv[])
 {
 int a,b,s=0;
 cout<<"Podaj dwie liczby"<<endl;
 cout<<"a=";
 cin>>a;
 cout<<"b=";
 cin>>b;
 
 if (b > a)
 while (b>=a)
 {
 s=s+b;
 b=b-1;
 }
 
 else
 while (a>=b)
 {
 s=s+a;
 a=a-1;
 }
 cout <<"Suma="<<s<<endl;
 
 system("PAUSE");
 return EXIT_SUCCESS;
 }
 |  
 DO...WHILE - SILNIA
 
 
 
 
	  | Cytat: |  
	  | #include <cstdlib> #include <iostream>
 
 using namespace std;
 
 int main(int argc, char *argv[])
 {
 int n,s=1,i=1;
 cout<<"Podaj n"<<endl>>n;
 do
 {
 i++;
 s*=i;
 }
 while(i<n);
 cout<<n<<"!="<<s<<endl;
 
 system("PAUSE");
 return EXIT_SUCCESS;
 }
 |  
 Post został pochwalony 0 razy
 
 Ostatnio zmieniony przez Ricko dnia Śro 13:38, 06 Mar 2013, w całości zmieniany 4 razy
 |  |