This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Jamol Meyliyev
- Raund() funksiyasi nima?
Elementar matematikada siz yaxlitlash degan tushunchani eshitgan bo'lsangiz kerak.Yaxlitlash yerik sonlar yoki sonning standard shaklidan uzoqroq bo'lgan shaklda berilgan sonlarni ixchamlab olish uchun ishlatiladi deyish mumkin.
Quyida round()
funksiya ishlatilish sintaksisini ko'rib o'tamiz.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
float son;
cout<<"Sonni kiriting: ";
cin>>son;
cout<<"Natija: "<<round(son);
return 0;
}
Console:
Sonni kiriting: 12.234234
Natija: 12
- fixed setprecision() functions funksiyasi nima?
Ushbu funksiya haqida qisqacha va elementar tushuntiradigan bo'lsam, Ushbu funksiya ham round()
funksiyasi kabi yaxslitlash amalini bajaradi faqat ushbu funksiyani round()
funksiyasidan farqi round()
funksiyasi berilgan float yoki double tipidagi sonni integer tipiga o'zlashtirib beradi.fixed setprecision()
funksiyasi esa sonning ma'lum bir qismini yaxlitlash imkonini yaratadi.
Quyida masala orqali tushuntirishga harakat qilaman.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
/* fixed<<setprecision() - yaxlitlash funksiyasi
bo'lib quyida berilgan masala orqali qanday
ishlashi haqida qisqacha tushuncha beraman.Nega
pastdagi misolda 2 soni yozilgan desak ushbu
qavslar ichiga yozilgan sonning butun ishorasidan
keyin nechta songacha yaxlitlashni anglatadi.
Masalan:
12.3273242 => fixed<<setprecision(2) => 12.33 consolega chiqadi.
*/
double son1;
float son2;
cin>>son1;
cin>>son2;
cout<<"Area is "<<fixed<<setprecision(2)<<son1*son2<<".";
return 0;
}
Console:
Son1 => 8.25
Son2 => 6.47
Natija: 53.38
Ushbu keltirib o'tilgan misollar orqali round()
va fixed setprecision()
funksiyalari o'rtasidagi farqni va afzalliklarini qisqacha ko'rib chiqdik.
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Jamol Meyliyev
Jamol Meyliyev | Sciencx (2022-09-22T17:26:36+00:00) Round() and fixed setprecision() functions. Retrieved from https://www.scien.cx/2022/09/22/round-and-fixed-setprecision-functions/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.