Znajdziesz dla mnie chwile ?

liczyłes na bimbały?
najpierw posty poprosze:*

FTIMS


#1 18-03-2012 07:09:07

jogo

Nie mam jaj aby pisać

Zarejestrowany: 15-03-2012
Posty: 5
Punktów :   

cwiczenia 2

zadania z ciwczen 2
mam nadzieje ze nikt nie ma zamiaru uzywac ctrl+c ctrl+v

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

     

    float zad1(float x)
    {
          if( x>=0 and x<=M_PI)return sin(x)+1;
          else if(x<=10 and x>M_PI)return 0.5*x;
          else return 2*x*x+x+2;
          }
         
    float zad2(int n)
    {
          float s=0;
          for(int i=5;i<=n;i++){
          s=s+pow(2.0,i)/(2*i+1);
          }
          return s;
         
          }
         
    float zad3(float x)
    {
         
          float r=1,silnia=1;
         
          for(int i=1;i<=6;i++)
          {
                  silnia=silnia*i;
                  r=r+pow(x,i)/silnia;
                  }
                  return r;
    }
    void zad4()
    {
         int m;
         for(int i=1;i<11;i++)
         {
                 for(int j=1;j<=10;j++)
                 {
                                   m=i*j;
                                   cout<<setw(4)<<m;
                 }
                 cout<<endl;
         }
    }
    void zad5()
    {
         for(int i=1;i<=255;i++)
         cout<<char(i)<<" "<<i<<endl;
         }
   
    float zad6(int n)
    {
    //1
                     for(int i=0;i<n;i++)
                     {
                      for(int j=0;j<=i;j++)
                       {
                                cout<<"*";
                                 }
                                  cout<<endl;
         
                                    }
                         cout<<endl;
 
   //2
                      for(int i=0;i<n;i++)
                       {
                          for(int j=n;j>i;j--)
                              {
                                    cout<<"*";
                                    }
                        cout<<endl;
                         }
                         cout<<endl;
 
  //3
                         for(int i=0;i<n;i++)
                                 {
                                   for(int j=1;j<=i;j++)
                                    {
                                             cout<<" ";
                                               }
                                                 for(int j=n;j>i;j--)
                                                   {
                                                           cout<<"*";
                                                             }
         
                                                             cout<<endl;
                              }
                              cout<<endl;
 
  //4
                              for(int i=0;i<n;i++)
                               {
                                for(int j=n-1;j>i;j--)
                                 {
                                          cout<<" ";
                                           }
                                             for(int j=0;j<=(i*2);j++)
                                               {
                                                        cout<<"*";
                                                          }
                                                            cout<<endl;
                                                            }
                                                             cout<<endl;
 
  //5
                                for(int i=0;i<n;i++)
                                 {
                                   for(int j=n-1;j>i;j--)
                                    {
                                            cout<<" ";
                                              }
                                                for(int j=0;j<=i;j++)
                                                  {
                                                            cout<<"*";
                                                              }
                                                                cout<<endl;
                                                                 }
                                                                  cout<<endl;
 
  //6
                                for(int i=0;i<n;i++)
                                {
                                 int k=i*2;
                                  for(int j=0;j<i;j++)
                                   {
                                          cout<<" ";
                                           }
                                            for(int j=n*2-1;j>k;j--)
                                             {
                                              cout<<"*";
                                               }
                                                cout<<endl;
                                                }
          }
   
         
int main()
{
    nazwisko();
    char z,p;
    do{
       
       cout<<"podaj numer zadania: ";
       cin>>z;
       cout<<endl;
   
       switch(z)
       {
           case '1':
                 float a,h,x,y;
                 int n;
   
                 cout<<" podaj a="<<endl;
                 cin>>a;
                 cout<<" podaj n="<<endl;
                 cin>>n;
                 cout<<" podaj h="<<endl;
                 cin>>h;
   
                 for(int i=0;i<=n;i++)
                         {
                         x=a+i*h;
                         y=zad1(x);
                         cout<<x<<"  "<<y<<endl;
     
                         }
                 cout<<endl;
                 break;
           case '2':
                 int n1;
                 cout<<"podaj n: "<<endl;
                 cin>>n1;
                 cout<<"suma: "<<zad2(n1)<<endl;
                 cout<<endl;
                 break;
           case '3':
                 float x1;
                 cout<<"podaj x: ";
                 cin>>x1;
                 cout<<endl;
                 cout<<" wartosc funkcji f2: "<<zad3(x1)<<endl;
                 cout<<endl;
                 break;
           case '4':
                 zad4();
                 cout<<endl;
                 break;
           case '5':
                 zad5();
                 cout<<endl;
                 break;
           case '6':
                 int n2;
                 cout<<"podaj ilosc wierszy: "<<endl;
                 cin>>n2;
                 zad6(n2);
                 cout<<endl;
                 break;
                 
             }
             
       cout<<"wpisz k jesli chcesz wyjsc : ";
       cin>>p;
       cout<<endl;
       
             
             }while(p!='k' and p!='K');
   
     
    system("PAUSE");
    return 0;
}

Ostatnio edytowany przez jogo (18-03-2012 15:03:09)

Offline

 

#2 19-03-2012 10:02:56

 djgrabek

Truje dupe, ale jestem

status djgrabek@gmail.com
3116091
Call me!
Skąd: Głowno
Zarejestrowany: 06-11-2011
Posty: 20
Punktów :   
WWW

Re: cwiczenia 2

a tutaj moja wersja:

Kod:

#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

void menu();


void koniec (void)
{
     system ("cls");
     cout << "dobranoc";

}


int silnia (int n)
{
    if (n==1 || n==0)
      return 1;
    return silnia(n-1)*n;
}

void ZadA(void)
{
      int a,h,n;
      system ("cls");
      cout << "\nPodaj a: \t";
      cin >> a;
      cout << "\nPodaj h: \t";
      cin >> h;
      cout << "\nPodaj n: \t";
      cin >> n;
           
     
      float x;
      float wynik;
      int zn;

      system ("cls");
      cout << "\na=" << a << "\t h=" << h << "\t n=" << n;
      cout << "\n========================================";

      for (zn=0; zn <= n;zn++)
      {
          x=a+zn*h;
          
          if (x>=0 && x <= M_PI)
          {
             wynik=sin(x)+1;
          }
          else if (x> M_PI and x<=10)
          {
             wynik=x/2;
          }
          else 
          {
             wynik=2*x*x+x+2;
          }
          


          
          cout << "\na=" << a << "\t h=" << h << "\t n=" << zn << "\t f(x)=" << wynik;
          
      }
          system("PAUSE");
          menu();

      
}

void ZadB (void)
{
     int n;
     cout << "\nPodaj n: \t";
     cin >> n;

     
     float suma=0;
     float zn;

     for (zn=5;zn<=n;zn++)
     {
         suma = suma + pow(2,zn)/2*zn+1;
     }
     
     cout << "\n suma=" << suma;
     
               system("PAUSE");
          menu();

}

void ZadC ()
{
     int x;
     
     cout << "\nPodaj x: \t";
     cin >> x;
     
     int i;
     float suma=0;
     for (i=0;i<=6;i++)
     {
         suma = suma + pow(x,(float)i)/silnia(i);
     }
     
     cout <<"\n \n suma=" << suma;
               system("PAUSE");
          menu();

}
         
void ZadD (void)
{
     int x;
     int y;
     cout << "\n\n\n";
     
     for (x=1;x<=10;x++)
     { 
         cout << "\n";
         for (y=1;y<=10;y++)
         {
             cout << x*y  << "\t";

         }
     }
               system("PAUSE");
          menu();

}

void ZadE(void)
{
     int i;
     for (i=0;i<128;i++)
          cout << i <<"=" << (char)i << "\t";
               system("PAUSE");
          menu();

}


void menu(void)
{
    char menuu;
    int m;
    system ("cls");
    cout << "\n\t ********************";
    cout << "\n\t 1 - zadanie 1 ";
    cout << "\n\t 2 - zadanie 2 ";
    cout << "\n\t 3 - zadanie 3 ";
    cout << "\n\t 4 - zadanie 4 ";
    cout << "\n\t 5 - zadanie 5 ";
    cout << "\n" << "\t k - koniec";
    menuu=getchar();
    
    switch ((int)menuu)
    {
           case 49 : ZadA() ;
                break;
           case 50 : ZadB() ;
                break;
           case 51 : ZadC() ;
                break;
           case 52 : ZadD() ;
                break;
           case 53 : ZadE() ;
                break;
           case 75 : koniec()     ;
                break;
           case 107: koniec();
                break;
           default : menu();
    }
}


int main(int argc, char *argv[])
{
    
    menu();
                
    
     
    /*
    
    ZadA (5,4,10);
    ZadB (10);
    ZadC (10);
    ZadD ();
    ZadE ();
    */
    system("PAUSE");
    
    return EXIT_SUCCESS;
}

zapomniałem o choinkach ;D

Kod:

void ZadF(void)
{
    int y;
     
     cout << "\nPodaj ilosc wierszy: \t";
     cin >> y;
     
     // A

     for (int a=0;a<=y;a++)
     {
         for (int b=1;b<=a;b++)
         {
             cout << "*";
         }
         cout << "\n";
     }
     system("PAUSE");     
     

     // B
     for (int a=0;a<=y;a++)
     {
         for (int b=y;b>=a;b--)
         {
             cout << "*";
         }
         cout << "\n";
     
     }
     system("PAUSE");     
     //C
     
     int lewa,prawa,srodek;
     int b,c,d;
     int szerokosc=y*2+1;
     for (int a=0;a<y;a++)
     { 
         //szekokosc=wiersze*2+1
         
         int srodek = szerokosc/2;
         
         for (b=0;b<srodek-a;b++)
             cout<< " "; // LEWY ZNAK
             
         for (c=srodek-a;c<=srodek+a;c++)
             cout << "*";
             
         for (d=srodek+a+1;d<szerokosc;d++)
             cout <<" "; // PRAWY ZNAK
              
         cout << "\n";
     }
     system("PAUSE");
 
     //D
     

     szerokosc=y*2-1;
     for (int a=y-1;a>=0;a--)
     { 
         //szekokosc=wiersze*2+1
         
         int srodek = szerokosc/2;
         
         for (b=0;b<srodek-a;b++)
             cout<< " "; // LEWY ZNAK
             
         for (c=srodek-a;c<=srodek+a;c++)
             cout << "*";
             
         for (d=srodek+a+1;d<szerokosc;d++)
             cout <<" "; // PRAWY ZNAK
              
         cout << "\n";
     }
     system("PAUSE");     
     
     
     //E
     
     for (int a=0;a<y;a++)
     {
         for (b=0;b<y-a-1;b++)
             cout << " ";
         for (c=y-a-1;c<y;c++)
             cout << "*";
         cout << "\n";
     }
     system("PAUSE");  
     
     //F
     for (int a=y;a>0;a--)
     {
         for (b=0;b<y-a;b++)
             cout << " ";
         for (c=y-a;c<y;c++)
             cout << "*";
         cout << "\n";
     }
     system("PAUSE");  
           
     
     menu();
}

Ostatnio edytowany przez djgrabek (19-03-2012 12:05:32)


"Tylko dwie rzeczy sa nieskonczone: wszechsiat i ludzka glupota, chociaz co do pierwszego nie mam pewnosci"
[Albert Einstein]

Offline

 

Stopka forum

RSS
Powered by PunBB 1.2.23
© Copyright 2002–2008 PunBB
Polityka cookies - Wersja Lo-Fi

[ Generated in 0.071 seconds, 8 queries executed ]


Darmowe Forum | Ciekawe Fora | Darmowe Fora
www.analityka-med.pun.pl www.zdhbratnieslowo.pun.pl www.szkolapodzaglami.pun.pl www.mythwaronline.pun.pl www.obpu.pun.pl