Zestaw 2
zad2.
#include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> using namespace std; int main(int argc, char *argv[]) { int x; cout<<"Podaj liczbe:"<<endl; cin>>x; cout<<endl<<"liczba = "<<x<<endl; if(x > 0){ for(int i = x;i > 0;i--){ cout<<i<<" "; } cout<<endl<<"liczby nieparzyste:"<<endl; for (int i = 0;i<x;i++){ if( i%2 != 0){ cout<<i<<" "; } } cout<<endl<<"liczby dajace reszte 3:"<<endl; for (int i = 0;i<x;i++){ if( i%3 == 2 and i%2 == 0){ cout<<i<<" "; } } cout<<endl<<"wielokrotnosci 5:"<<endl; for (int i = 0;i<=x;i++){ if( i%5 == 0){ cout<<i<<" "; } } } system("PAUSE"); return EXIT_SUCCESS; }
zad3 nie używajcie printf zamiast tego uzyjcie cout, i set precision.
cout<<"katy"<<endl<<"Kat sin cos tg ctg"<<endl; for(int i=0;i<=90;i+=15){ float rad = (i*3.14)/180; if(i == 0) cout<<" "; cout<<i<<" | "; printf("%.2f", sin(rad )); cout<<" "; printf("%.2f", cos(rad )); if(i == 90){ cout<<" --- "; }else{ cout<<" "; printf("%.2f", tan(rad )); } if( i == 0){ cout<<" ---- "; }else{ cout<<" "; printf("%.2f",cos(rad )/sin(rad )); } cout<<endl; }
zad 4.
cout.setf(ios::right ,ios::adjustfield); int padding =0; for(int i =0; i<380; i+=12){ padding = (sin((i*M_PI)/180)*10); cout<<setw(padding+15)<<"*"<<endl; } cout<<endl;
zad5.
#include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <iomanip> #include <stdio.h> using namespace std; float licz_bok(float x1,float y1,float x2,float y2){ float len = sqrt( pow(x2 - x1) + pow(y2-y1)); return len; } double licz_tri(float x1,float x2,float x3,float y1,float y2,float y3){ } int main(int argc, char *argv[]) { double x1,x2,y1,y2,x3,y3; int t; cout<<"wybierz tryb:"<<endl<<"1 - liczenie dlugosci"<<endl<<"2 - liczenie trojkata"; cin>>t; if( t == 1){ cout<<"Podaj x1"<<endl; cin>>x1; cout<<"Podaj y1"<<endl; cin>>y1; cout<<"Podaj x2"<<endl; cin>>x2; cout<<"Podaj y2"<<endl; cin>>y2; cout<<licz_bok(x1,y1,x2,y2); }else{ cout<<"Podaj x1"<<endl; cin>>x1; cout<<"Podaj y1"<<endl; cin>>y1; cout<<"Podaj x2"<<endl; cin>>x2; cout<<"Podaj y2"<<endl; cin>>y2; cout<<"Podaj x3"<<endl; cin>>x3; cout<<"Podaj y3"<<endl; cin>>y3; licz_tri(x1,x2,x3,y1,y2,y3); } system("PAUSE"); return EXIT_SUCCESS; }
Ostatnio edytowany przez danone89 (18-03-2012 15:34:31)
Offline