Tuesday, April 28, 2020

Table in C, C++ and Python

ARS| BLOG

Command Line Mathematical Table In C, C++ AND Python, Using FOR And While Loops .


Introduction :

Hello programmers and everyone else. My name is ARS and I am going to tell you about encoding to write a basic command line Mathematical Table that takes the value and limit both by user in C, C++ and Python using While and For Loops. it is very easy to learn. But, first you need some other softwares as this tutorial shows you only to how to write a program. So, first download compilers for your platform, either it is android, mac os or Windows. Programming is same on every platform. You can find each compiler HERE. Now you need to install compilers, After setting up compilers, you need to open up a new project and then click new file. Now write the following code on it .


Code for C

Using While Loop.

#include <stdio.h>

#include <conio.h>


void main();

{

clrscr();

printf("Simple Table\n");


int a;

int b;

int c = 1;


printf("Enter Number= \n");

scanf("%d", &a);


printf("Enter Limit= \n");

scanf("%d", &b);


while(c<=b)

{

printf("%d * %d = %d", a, c, a*c);

c++;

}


getche();

}


For Loop.

#include <stdio.h>

#include <conio.h>


void main();

{

clrscr();

printf("Simple Table\n");


int a;

int b;


printf("Enter Number= \n");

scanf("%d", &a);


printf("Enter Limit= \n");

scanf("%d", &b);


for(int c = 1; c <= b; c++;)

{

printf("%d * %d = %d", a, c, a*c);

}


getche();

}


C++ Code

Using While Loop

#include <iostream>

#include <conio.h>

using namespace std;


int main();

{

cout << "Simple Table";


int a;

int b;

int c=1;


cout << "Enter Number= \n";

cin >> a;


cout << "Enter Limit= \n";

cin >> b;


while(c<=b)

{

cout << a, "*", c, "=", a*c;

c++;

}

getche();

}


Using For Loop.

#include <iostream>

#include <conio.h>

using namespace std;


int main();

{

cout << "Simple Table\n";


int a;

int b;

cout << "Enter Number= \n";

cin >> a;


cout << "Enter Limit= \n";

cin >> b;


for(int c=1; c<=b; c++)

{

cout << a, "*", c, "=", a*c;

}


getche();

}


Python Code

Using While Loop.


print("Simple Table\n");


a = int(input("Enter Number=\n"))

b = int(input("Enter Limit=\n"))

c = 1;


while(c <= b):

print(a, "*", c, "=", a*c)

c= c+1;



Using For Loop.


print("Simple Table\n");


a = int(input("Enter Number=\n"))

b = int(input("Enter Limit=\n"))


for c in range(1, b+1):

print(a, "*", c, "=", a*c)



Monday, April 27, 2020

Calculator in C, C++ and Python

ARS| BLOG

Command Line Calculators In C, C++ AND Python, Using Switch And Nested if Statements.


Introduction :

Hello programmers and everyone else. My name is ARS and I am going to tell you about encoding to write a basic command line calculator in C, C++ and Python using Switch and nested if statements. it is very easy to learn. But, first you need some other softwares as this tutorial shows you only to how to write a program. So, first download compilers for your platform, either it is android, mac os or Windows. Programming is same on every platform. You can find each compiler HERE. Now you need to install compilers, After setting up compilers, you need to open up a new project and then click new file. Now write the following code on it .


C Calculator Code

Using Switch Statement.

#include <stdio.h>

#include <conio.h>


void main();

{

clrscr();

printf("Simple Calculator\n");


double a;

double b;

int c;


printf("Enter First Number= \n");

scanf("%lf", &a);


printf("Enter Second Number= \n");

scanf("%lf", &b);


printf("Enter Operation= \n 1 to add\n 2 to subtract\n 3 to multiply\n 4 to divide\n");

scanf("%d", &c);


switch(c)

{


case 1:

printf("%lf + %lf = %lf", a, b, a+b);

break;


case 2:

printf("%lf - %lf = %lf", a, b, a-b);


case 3:

printf("%lf * %lf = %lf", a, b, a*b);

break;


case 4:

printf("%lf \/ %lf = %lf", a, b, a/b);

break;


default:

printf("ERROR");

break;


}

getche();

}


Using Nested if.

#include <stdio.h>

#include <conio.h>


void main();

{

clrscr();

printf("Simple Calculator\n");


double a;

double b;

int c;


printf("Enter First Number= \n");

scanf("%lf", &a);


printf("Enter Second Number= \n");

scanf("%lf", &b);


printf("Enter Operation= \n 1 to add\n 2 to subtract\n 3 to multiply\n 4 to divide\n");

scanf("%d", &c);


if(c == 1)

{

printf("%lf + %lf = %lf", a, b, a+b);

}


if(c == 2)

{

printf("%lf + %lf = %lf", a, b, a-b);

}


if(c == 3)

{

printf("%lf \/ %lf = %lf", a, b, a/b);

}


if(c == 4)

{

printf("%lf * %lf = %lf", a, b, a*b);

}


else

{

printf("ERROR");

}


getche();

}


C++ Calculator Code

Using Switch Statement

#include <iostream>

#include <conio.h>

using namespace std;


int main();

{

cout << "Simple Calculator";


double a;

double b;

int c;


cout << "Enter First Number= \n";

cin >> a;


cout << "Enter Second Number= \n";

cin >> b;


cout << "Enter Operation= \n 1 to add\n 2 to subtract\n 3 to multiply\n 4 to divide\n";

cin >> c;


switch(c)

{


case 1:

cout << a << "+" << b << "=" << a+b;

break;


case 2:

cout << a << "-" << b << "=" << a-b;


case 3:

cout << a << "*" << b << "=" << a*b;

break;


case 4:

cout << a << "/" << b << "=" << a/b;

break;


default:

cout << "ERROR";

break;


}

getche();

}


Using Nested if.

#include <iostream>

#include <conio.h>

using namespace std;


int main();

{

cout << "Simple Calculator\n";


double a;

double b;

char c;


cout << "Enter First Number= \n";

cin >> a;


cout << "Enter Second Number= \n";

cin >> b;


cout << "Enter Operation= \n + to add\n - to subtract\n * to multiply\n \/ to divide\n";

cin >> c;


if(c == '+')

{

cout << a << "+" << b << "=" << a+b;

}


if(c == '-')

{

cout << a << "-" << b << "=" << a-b;

}


if(c == '/')

{

cout << a << "/" << b << "=" << a/b;

}


if(c == '*')

{

cout << a << "*" << b << "=" << a*b;

}


else

{

cout << "ERROR";

}


getche();

}


Python Calculator Code

Using Nested if.


pritf("Simple Calculator\n");


a = int(input("Enter First Number=\n"))

b = int(input("Enter Second Number=\n"))

c = input("Enter Operation= \n + to add\n - to subtract\n * to multiply\n / to divide\n")


if(c == '+'):

{

print(a, "+", b, "=", a+b)

}


if(c == '-'):

{

print(a, "-", b, "=", a-b)

}


if(c == '/'):

{

print(a, "/", b, "=", a/b)

}


if(c == '*'):

{

print(a, "+", b, "=", a*b)

}


else:

{

print("ERROR");

}


Table in C, C++ and Python

ARS| BLOG ⮙ ARS C C++ Python Contact Command Line Mathematical Table In C, C++ AND Python, Using FOR And While Loops . ...