Posts

Showing posts from August, 2020

fix programming error

Image
Programming errors can be categorized into three types: syntax errors, runtime  errors, and logic errors. #Beginner Runtime and logical error are difficult to identify. In gcc c++ compiler using namespace std; #include <iostream> using namespace std; int main() { float i = 17; float j = 0; cout << "runtime error 17/0 :" << i / j; cout << endl; cout << "logic error 17/7 :" << 17 / 7; cout << endl; cout << "fix logic error 17/7 :" << 17.0 /7; return 0; } copy Output runtime error 17/0 :inf logic error 17/7 :2 fix logic error 17/7 :2.42857 [Program finished] Runtime error is zero can't dived any number. Logic error are more difficult to identify in big calculation and big program to solve the error just apply type casting to fix error. In above example 17 divided by 7 is show int value when apply 17.0 divided by 7 the compiler identify the floating points is anser then they sh

Swap the number without using thrid varible or temp c++ program

Image
Swap the number without using thrid varible or temp program # Beginner In gcc c++ compiler using namespace std; #include <iostream> using namespace std; int main() { int number1, number2; cout << "enter two number :" << endl; cout << "number1 : " ; cin >> number1; cout << "number2 : " ; cin >> number2; cout << endl; cout << "number before swaping " << endl; cout << "number1 : " << number1 << endl; cout << "number2 : " << number2 << endl; cout << endl; number1 = number1 + number2; number2 = number1 - number2; number1 = number1 - number2; cout << "number after swaping " << endl; cout << "number1 : " << number1 << endl; cout << "number2 : " << number2 << endl; } copy Output enter two number : number1 : 54 n

Variable limits and size of variable in byte program cpp

Image
Limit of variable and size of variable #Beginner #Intermediate In gcc c++ compiler using namespace std; #include<iostream> #include<limits> using namespace std; int main() { cout<< "-------------------signed variable------------------------" <<endl; cout<< "variable | minimum value  | maximum value  |  size in byte" <<endl; cout<< "Char \t\t" <<CHAR_MIN<< "\t\t" <<CHAR_MAX<< "\t\t\t" << sizeof ( char )<<endl; cout<< "short int \t" <<SHRT_MIN<< "\t\t" <<SHRT_MAX<< "\t\t\t" << sizeof ( short int )<<endl; cout<< "int \t\t" <<INT_MIN<< "\t" <<INT_MAX<< "\t\t" << sizeof ( int )<<endl; cout<< "long int \t" <<LONG_MIN<< "\t" <<LONG_MAX<< "\t\t&quo

simple calculator using c++ program

Image
Simple calculator using c++ #Beginner In gcc c++ compiler using namespace std; #include <iostream> using namespace std; int main() { int number1, number2; cout << " enter two number to perfrom opration :" << endl; cout << endl << "number1 :" ; cin >> number1; cout << endl << "number2 :" ; cin >> number2; cout << endl; cout << "addition of " << number1 << "+" << number2 << " = " << number1 + number2; cout << endl; cout << "subraction of " << number1 << "-" << number2 << " = " << number1 - number2; cout << endl; cout << "multiple of  " << number1 << "X" << number2 << " = " << number1 * number2; cout << endl; cout << "dived of &

How to solve the c++ problem using steps

Image
Translate the following algorithm into C++ code: Step 1: Declare a double variable named miles with initial value 100. Step 2: Declare a double constant named KILOMETERS_PER_MILE with value  1.609. Step 3: Declare a double variable named kilometers, multiply miles and  KILOMETERS_PER_MILE, and assign the result to kilometers. Step 4: Display kilometers to the console. What is kilometers after Step 4? #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { /*Step 1: Declare a double variable named miles with initial value 100 */ const double MILES = 100; /*Step 2: Declare a double constant named KILOMETERS_PER_MILE with value 1.609. */ const double KILOMETERS_PER_MILE=1.609; /* Step 3: Declare a double variable named kilometers, multiply miles and  KILOMETERS_PER_MILE, and assign the result to kilometers */     double kilometer = MILES * KILOMETERS_PER_MILE;         /* Step 4: Display kilometers to the console. Wh

C++ constant variable program and area of circle program

Image
C++ constant variable program and area of circle program #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { /* constant variable always denote in capital letter */ const double PI = 3.14159; //step 1 : read radius from user cout<< "enter the radius of circle :" ; double radius; cin>>radius; cout<<endl; // step 2 : compute area double area = radius * radius * PI ; //step 3 : show area cout<< "area of the circle is : " <<area; } copy Output enter the radius of circle :13 area of the circle is : 530.929 [Program finished] Constant variable always declared in upper alphabet eg. const double PI ;  you can't use Ï€ as variable name therefore pi and PI is allowed but you defined constant the use variable name PI to simply understand the PI variable is constant variable. the const variable can't change the value. Need of Programmer

How to swap the number c++ program

Image
How to swap the number using third variable ? #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { int number1 , number2 ; cout<< "enter two number :" <<endl; cout<< "number1 : " ;cin>>number1; cout<< "number2 : " ;cin>>number2; cout<<endl; cout<< "number before swaping " <<endl; cout<< "number1 : " <<number1<<endl; cout<< "number2 : " <<number2<<endl; int temp = number1; number1 = number2; number2 = temp; cout<<endl; cout<< "number after swaping " <<endl; cout<< "number1 : " <<number1<<endl; cout<< "number2 : " <<number2<<endl; } copy Output enter two number : number1 : 14 number2 : 56 number before swaping number1 : 14 number2 : 56 number after swap

c++ variable declaration program

Image
c++ variable declaration program #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { int number1(30); /* is same as int number1=30 */ float number2(40.7); /* is same as float number2 = 40.7 */     char letter( 'A' );          cout<<number1<<endl;     cout<<number2<<endl;     cout<<letter<<endl; } copy Output 30 40.7 A [Program finished] Need of Programmer Need of Programmer

Simple C++ variable program

Image
C++ variable to store the data in memory variable are the register to hold the data at certain memory loaction .  #Beginner In gcc C++ compiler using namespace std #include <iostream> using namespace std; int main() { bool value = 0; /* boolean datatype 0 or 1 and true or false */ cout << "boolean number is :" << value << endl; short int short_int = 32767; /* short int is -32,768 to +32,767 */ cout << "short int number is :" << short_int << endl; unsigned short int un_short_int = 65535; /*only postive short int is 0 to 65535 */ cout << "postive short number is :" << un_short_int << endl; int int_number = 2147483647; /* normal int is -2147483648 to +2147483647 */ cout << "integer number is :" << int_number << endl; unsigned int un_int_number = 4294967295; /* postive normal int is 0 to  4294967295 */ cout << "postive integ

How to write simple c++ pattern display program

Image
How to write simple pattren display program in c++? only for beginner #Beginner In turbo c++ compiler #include<iostream.h> #include<conio.h> int main() { clrscr(); cout<< "   *       " <<endl; cout<< "  ***    " <<endl; cout<< " *****  " <<endl; cout<< "*******" <<endl; getch(); return 0; } In gcc compiler #include<iostream> int main() { std::cout<< "   *       " <<std::endl; std::cout<< "  ***    " <<std::endl; std::cout<< " *****  " <<std::endl; std::cout<< "*******" <<std::endl; return 0; } In gcc c++ compiler using namespace std #include<iostream> using namespace std; int main() { cout<< "   *       " <<endl; cout<< "  ***    " <<endl; cout<< " *****  " <<endl; cout<< "

How to write c++ simple input and output program?

Image
C++ simple input and output program #Beginner Cin>> use for get input for keybord Cout<< display output In turbo c++ complier #include<iostream.h> #include<conio.h> int main() { clrscr(); cout<< "enter your number :" ; int number; /* integer variable to store input */ cin>>number; cout<<endl<< "you number is : " <<number; /* to show input to output */ getch(); return 0; } In gcc c++ compiler #include<iostream> #include<conio.h> int main() { clrscr(); std::cout<< "enter your number :" ; int number; /* integer variable to store input */ std::cin>>number; std::cout<<std::endl<< "you number is : " <<number; /* to show input to output */ getch(); return 0; } In gcc c++ compiler using namespace std #include<iostream> #include<conio.h> using namespace std; int main() { clrscr(); cout<< "enter you