//the statement that jab class likhte h to bilkul bi memory nhi khai jati and //objects bnane pe hi memory allocate hoti hai is not completlety true (partially true) /*jab hum class bnate hai to kuch memory (for example functions ki) sare functions ke liye same allocate ki jati hai otherwise har object ke liye alg memory allot hogi*/ #include <iostream> using namespace std ; class shop { int itemId [ 100 ]; int itemPrice [ 100 ]; int counter; public: void initCounter ( void ) { counter = 0 ; } void setPrice ( void ); void displayPrice ( void ); }; void shop :: setPrice ( void ){ cout << "enter id of your item no" << counter + 1 << endl; cin >> itemId [counter]; cout << "enter price of your item" << endl; cin >> itemPrice [counter]; counter ++ ; } void ...
#include <iostream> using namespace std ; int main (){ int a ; int b ; cout << "enter the value of a : \n " ; // <<this is insertion operator, >>this is extraction operator // cout is used for making an output, cin is used for extracting an input cin >> a ; cout << "enter the value of b : \n " ; cin >> b ; cout << "the sum is " << a + b ; return 0 ; }
//code for factorial #include <iostream> using namespace std ; int factorial ( int y ) { if (y <= 1 ){ return 1 ; //ye nhi btaenge to infinitely chalta rahega } return y * factorial (y - 1 ); } int fib ( int y ) { if (y <= 2 ){ return 1 ; } return fib (y - 1 ) + fib (y - 2 ); } // fibonacci sequence int main (){ int x; // cout<<"enter the number whose factorial u wanna find "; // cin>>x; // cout<<"the factorial of "<<x<<" is "<<factorial(x)<<endl; cout << "enter the term u wanna find out in the fibonacci sequence" << endl; cin >> x; cout << "the term in fibonacci sequence at position " << x << " is " << fib (x); retur...
Comments
Post a Comment