Programski jezik C++ - Vježbe - 2. dio

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

Computer Science 1620 Math Library. Remember this program? suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to.
Factorial Preparatory Exercise #include using namespace std; double fact(double); int fact(int); int main(void) { const int n=20; ofstream my_file("results.txt");
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions and Recursion Outline some useful problems.
Functions. COMP104 Functions / Slide 2 Introduction to Functions * A complex problem is often easier to solve by dividing it into several smaller parts,
ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne
第三次小考. #include using namespace std; int aaa(int *ib,int a1,int a2) { int u,v; int m=(a1+a2)/2; if(a1==a2)return ib[a1]; u=aaa(ib,a1,m); cout
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 4 Programming with Data Files.
Chapter 4 Summation.
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
Input a number #include using namespace std; int main() { int num; cout num; return 0; }
Simple Functions Writing Reuseable Formulas. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian.
LESSON 2 Basic of C++.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Chapter five exercises. a. false; b. true; c. false; d. true; e. true; f. true; g. true; h. false.
LESSON 2 Basic of C++.
#define #include<iostream> using namespace std; #define GO
Prog Club Introductory Presentation
LESSON 4 Decision Control Structure
EMT 101 – Engineering Programming
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Command Line Arguments
Programming Fundamentals
Writing Reuseable Formulas
solve the following problem...
Math Library and IO formatting
לולאות קרן כליף.
Function Basics.
Programming -2 برمجة -2 المحاضرة-5 Lecture-5.
Programiranje - Blokovi naredbi i logički tipovi –
OSNOVE PROGRAMIRANJA U PROGRAMSKOM JEZIKU
Random Number Generation
DSP Lab. Week 1 Drawing sinusoidal waves
אבני היסוד של תוכנית ב- C++
אבני היסוד של תוכנית ב- C++
Screen output // Definition and use of variables
הרצאה 03 אבני היסוד של תוכנית ב- C
Starting Out with C++: From Control Structures through Objects
Pointers & Functions.
اصول کامپیوتر ۱ مبانی کامپیوتر و برنامه‌سازی
Code::Block vs Visual C++
TEST II razredi.
CSC 270 – Survey of Programming Languages
C++ WORKSHOP Šimec Tino - FOI.
Programski jezik C++ - Vježbe - 5. dio
Programiranje - Naredbe za kontrolu toka programa – 1. dio
Programski jezik C++ - Vježbe - 4. dio
Programiranje - Naredbe za kontrolu toka programa – 3. dio
Programski jezik C++ - Vježbe - 1. dio
If Statements.
Let’s Write a Graphics Program
Mr. Dave Clausen La Cañada High School
CS1201: Programming Language 2
Arrays of Two-Dimensions
foo.h #ifndef _FOO #define _FOO template <class T> class foo{
Output Formatting Bina Ramamurthy 4/16/2019 BR.
Programming with Data Files
Pointers & Functions.
(Dreaded) Quiz 2 Next Monday.
TOPIC: FUNCTION OVERLOADING
Programming Strings.
Programming Fundamental
Programiranje - Naredbe za kontrolu toka programa – 1. dio
Introduction to Algorithms and Programming COMP151
Vježbenica 2: struktura grananja – 2.dio
Output Formatting Bina Ramamurthy 9/25/2019 BR.
CSE Module 1 A Programming Primer
Programski jezik C++ - Vježbe - 2. dio
Vježbenica 1b: Pravocrtna programska struktura
Presentation transcript:

Programski jezik C++ - Vježbe - 2. dio Ak. god. 2017/2018 Doc. Dr. Sc. Marko Maliković

Izračunavanje duljine hipotenuze pravokutnog trokuta #include <iostream> #include <conio.h> #include <cmath> using namespace std; int main() { cout << "Kateta 1 = "; double kat1; cin >> kat1; cout << "Kateta 2 = "; double kat2; cin >> kat2; double hip = sqrt(kat1*kat1+kat2*kat2); cout << "Hipotenuza = " << hip << endl; getch(); return 0; }

Zadatak  

Rješenje #include <iostream> #include <conio.h> #include <cmath> using namespace std; int main() { long double R; cout << "Upisi radijus: "; cin >> R; const long double volumen = 4*pow(R,3)*3.1415926/3; cout << "Volumen kugle je: " << volumen << endl; getch(); return 0; } RJEŠENJE ĆE ZA VOLUMEN = 695.500 BITI ISPISANO U OBLIKU: 1.40922e+018 AKO ŽELIMO DA RJEŠENJE BUDE ISPISANO BEZ ZNANSTVENE NOTACIJE TADA  VIDI SLIJEDEĆU STRANU

Rješenje #include <iostream> #include <conio.h> #include <cmath> using namespace std; int main() { cout.precision(0); // Određuje maksimalan broj decimalnih mjesta u ispisu decimalnih brojeva long double R; cout << "Upisi radijus: "; cin >> R; const long double volumen = 4*pow(R,3)*3.1415926/3; cout << "Volumen kugle je: " << fixed << volumen; // fixed ispisuje brojeve bez eksponencijalnog zapisa // Također ispisuje brojeve s onoliko znamenki // kako je definirano u cout.precision(0) getch(); return 0; } SADA ĆE RJEŠENJE ZA VOLUMEN = 695.500 BITI ISPISANO U OBLIKU: 1409223915598252464