Here I will introduce you to the Most Common and Simple C++ Programs That you should try to do. I am Pretty Sure that you might have seen these if you have ever gone to a Coding School. Even when I first take Admission to my University in Bachelor Program in Computer Science. At very first we were introduced to such kind of simple programs. We did not know what we were doing. we were thinking why would someone use coding and programming Languages to find the sum of two Numbers. But After Time we come to know that it was not about finding the sum of two Numbers but Instead it was about creating the Concepts of how the Programming Works and how the computer find the sum of two numbers.

__Simple C++ Programs __

__Finding The Sum Of two Integers in C++__

Although this program seems easy and of course this one is easy. but to be honest, after completing the "Hello World" Program we were introduced to the data types in c++. and along with that we also discussed how the operator works in c++. finally, our professor at the end of the class asks us to create a program in c++ that finds the sum of the two Integer in c++. So I have saved that file upon telling now. I will simply show you how I solve that problem at that moment.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int first;

int second;

first=34;

second=35;

int sum;

sum=first+second;

cout<<"The Sum of two Number Is "<< sum<<endl:

return 0;

}

__Finding The Absolute Value Of An Integer in C++ __

Once you get familiar with the basic syntax of the language in my case it is c++. the next Program you have to create might be to make a c++ program that finds the absolute value of a given integer value. it can be done by the fi else statement. once you get familiar with the if-else statements then this program is a piece of cake for you. we were asked to create such a program when we were about to complete two weeks in computer science. although in computer science you have to learn everything related to computers but your main focus must-have programming is it is the most progressive field in today's era. so I came up with this solution although I was a beginner.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int Number;

Number=34;

int absoulteval;

if (Number<0)

absoulteval=-absoulteval;

else

absoulteval=Number;

cout<<"The Absolute value of "<<Number<<" is " absoultevalue:

return 0;

}

__Find the Multiplication of Two Numbers in C++__

This program seems very much similar to the one above which I have written about the addition of two numbers in c++. you only have to remove the sign of addition there and put the sign of multiplication and you are done. This one is so easy as the previous one there is not rocket science.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int firstNumber;

int secondNumber;

firstNumber=34;

secondNumber=35;

int multiple;

sum=firstNumber*secondNumber;

cout<<"The multiplicatio of two Number Is "<< multiple<<endl:

return 0;

}

__Find the Subtraction of Two Numbers in C++__

This program seems very much similar to the one above which I have written about the addition of two numbers in c++. you only have to remove the sign of addition there and put the sign of minus and you are done. This one is so easy as the previous one there is not rocket science. also i have chage the variable name to subtraction.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int first;

int second;

first=34;

second=35;

int subtraction;

sum=first*second;

cout<<"The subtraction Number Is "<< subtraction<<endl:

return 0;

}

__Find the Division of Two Numbers in C++__

This program seems very much similar to the one above which I have written about the subtraction of two numbers in c++. you only have to remove the sign of subtraction there and put the sign of division and you are done. This one is so easy as the previous one there is not rocket science. also, I have to change the variable name to division.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int first;

int second;

first=34;

second=35;

int division;

division=firstNumber*second;

cout<<"The division of two Is "<< division<<endl:

return 0;

}

__Finding Even And Odd Number Program in C++__

As you have seen the program in which we find the absolute value of the integer now you are familiar with the use of the if-else statement. now you are ready for your next program which is finding whether a number is off or even. As it seems very easy you only have to use the if-else statement. of course, you can use the switch statement. but for such a simple program in c++ one will not use the switch statement. we were asked to create such a program after introducing it to the if-else statement. my solution to this program is the following.

#include <iostream>

using namespace std;

int main ()

{

int a ;

int result;

cout <<"Enter a number=";

cin>>a;

result =a%2;

if (r==1)

cout<<a<<" is odd number.";

else

cout <<a<<" is even.";

return 0;

}

__Find the Factorial of a Number in C++__

Do not worry if you know a little bit of mathematics this program is very much easy. you will have to use a loop. the concept of the factorial number is not that complex. you might already be familiar from your sixth or seventh grade that what is the factorial. Now we will find how can we find the Factorial of a number.

#include <iostream>

using namespace std;

void factorial (int x);

int main ()

{

int number;

int fact =1;

for (int i=1;i<=number;i++)

{

fact=fact*i;

}

cout <<"fact"<<number<<"is "<<fact;

return 0;

}

__Find the Grade of a Student in C++__

To find the Grade of the student you must have given some rules that you have to check these rules are called a condition in your c++ program. you have to check the student marks under any conditions once the required condition is met you will output the grade of the student. for this case, you can use either the if-else statement of the switch statement with different cases inside the body of the switch.

#include <iostream>

using namespace std;

int main ()

{

int marks;

cout <<"enter your marks. ";

cin>>marks;

if (marks>=90)

cout <<"A grade";

else if(marks>=90)

cout<<"B grade";

else if(marks>=80)

cout<<"C grade";

else if (marks>=70)

cout<<"D grade";

else

cout<<"F grade.";

return 0;

}

__Ascending order of three number without using Loop in c++__

This program can also be done by using the if-else statement and by using the comparision operator in c++.

#include<iostream>

#include <conio.h>

using namespace std;

int main ()

{

int n1,n2,n3;

cout <<"Enter numbers.\n";

cout<<" first number=";

cin>>n1;

cout<<"second number=";

cin >> n2;

cout <<"third number=";

cin >>n3;

if (n1<n2 && n1<n3)

cout <<n1<<"less than"<<n2

<<" and"<<n3;

if (n2<n1 && n2<n3)

cout <<n2<<"less than"

<<n3<<" and "<<n1;

if (n3<n1 && n3 <n2)

cout <<n3<<" less than "

<<n1<< " and "<<n2;

return 0;

getch ();

}

__Finding the Prime Numer In C++__

This is a very simple and not efficient program to find whether a given number is Prime or not. here is my code to solve this program. you can do it by using the Loop.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int i,n;

int count =0;

cout <<"enter a number=";

cin >>n;

for (i=1;i<=n;i++)

{

if (n%i==0)

count++;

}

if (count==2)

cout<<n<<"prime number.";

else

cout <<n<<"not prime number.";

return 0;

}

This is It. Hope you find it useful. Please comment on your suggestion and if possible also share this with your friend. this is my personal view on how to create these programs. Stay Connected to the (Alixaprodev.com).

__Finding The Sum Of two Integers in C++__Although this program seems easy and of course this one is easy. but to be honest, after completing the "Hello World" Program we were introduced to the data types in c++. and along with that we also discussed how the operator works in c++. finally, our professor at the end of the class asks us to create a program in c++ that finds the sum of the two Integer in c++. So I have saved that file upon telling now. I will simply show you how I solve that problem at that moment.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int first;

int second;

first=34;

second=35;

int sum;

sum=first+second;

cout<<"The Sum of two Number Is "<< sum<<endl:

return 0;

}

__Finding The Absolute Value Of An Integer in C++__Once you get familiar with the basic syntax of the language in my case it is c++. the next Program you have to create might be to make a c++ program that finds the absolute value of a given integer value. it can be done by the fi else statement. once you get familiar with the if-else statements then this program is a piece of cake for you. we were asked to create such a program when we were about to complete two weeks in computer science. although in computer science you have to learn everything related to computers but your main focus must-have programming is it is the most progressive field in today's era. so I came up with this solution although I was a beginner.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int Number;

Number=34;

int absoulteval;

if (Number<0)

absoulteval=-absoulteval;

else

absoulteval=Number;

cout<<"The Absolute value of "<<Number<<" is " absoultevalue:

return 0;

}

__Find the Multiplication of Two Numbers in C++__This program seems very much similar to the one above which I have written about the addition of two numbers in c++. you only have to remove the sign of addition there and put the sign of multiplication and you are done. This one is so easy as the previous one there is not rocket science.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int firstNumber;

int secondNumber;

firstNumber=34;

secondNumber=35;

int multiple;

sum=firstNumber*secondNumber;

cout<<"The multiplicatio of two Number Is "<< multiple<<endl:

return 0;

}

__Find the Subtraction of Two Numbers in C++__This program seems very much similar to the one above which I have written about the addition of two numbers in c++. you only have to remove the sign of addition there and put the sign of minus and you are done. This one is so easy as the previous one there is not rocket science. also i have chage the variable name to subtraction.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int first;

int second;

first=34;

second=35;

int subtraction;

sum=first*second;

cout<<"The subtraction Number Is "<< subtraction<<endl:

return 0;

}

__Find the Division of Two Numbers in C++__This program seems very much similar to the one above which I have written about the subtraction of two numbers in c++. you only have to remove the sign of subtraction there and put the sign of division and you are done. This one is so easy as the previous one there is not rocket science. also, I have to change the variable name to division.

#include <iostream>

#include <conio.h>

using namespace std;

int main ()

{

int first;

int second;

first=34;

second=35;

int division;

division=firstNumber*second;

cout<<"The division of two Is "<< division<<endl:

return 0;

}

__Finding Even And Odd Number Program in C++__As you have seen the program in which we find the absolute value of the integer now you are familiar with the use of the if-else statement. now you are ready for your next program which is finding whether a number is off or even. As it seems very easy you only have to use the if-else statement. of course, you can use the switch statement. but for such a simple program in c++ one will not use the switch statement. we were asked to create such a program after introducing it to the if-else statement. my solution to this program is the following.

#include <iostream>

using namespace std;

int main ()

{

int a ;

int result;

cout <<"Enter a number=";

cin>>a;

result =a%2;

if (r==1)

cout<<a<<" is odd number.";

else

cout <<a<<" is even.";

return 0;

}

__Find the Factorial of a Number in C++__Do not worry if you know a little bit of mathematics this program is very much easy. you will have to use a loop. the concept of the factorial number is not that complex. you might already be familiar from your sixth or seventh grade that what is the factorial. Now we will find how can we find the Factorial of a number.

#include <iostream>

using namespace std;

void factorial (int x);

int main ()

{

int number;

int fact =1;

for (int i=1;i<=number;i++)

{

fact=fact*i;

}

cout <<"fact"<<number<<"is "<<fact;

return 0;

}

__Find the Grade of a Student in C++__To find the Grade of the student you must have given some rules that you have to check these rules are called a condition in your c++ program. you have to check the student marks under any conditions once the required condition is met you will output the grade of the student. for this case, you can use either the if-else statement of the switch statement with different cases inside the body of the switch.

#include <iostream>

using namespace std;

int main ()

{

int marks;

cout <<"enter your marks. ";

cin>>marks;

if (marks>=90)

cout <<"A grade";

else if(marks>=90)

cout<<"B grade";

else if(marks>=80)

cout<<"C grade";

else if (marks>=70)

cout<<"D grade";

else

cout<<"F grade.";

return 0;

}

__Ascending order of three number without using Loop in c++__This program can also be done by using the if-else statement and by using the comparision operator in c++.

#include<iostream>

#include <conio.h>

using namespace std;

int main ()

{

int n1,n2,n3;

cout <<"Enter numbers.\n";

cout<<" first number=";

cin>>n1;

cout<<"second number=";

cin >> n2;

cout <<"third number=";

cin >>n3;

if (n1<n2 && n1<n3)

cout <<n1<<"less than"<<n2

<<" and"<<n3;

if (n2<n1 && n2<n3)

cout <<n2<<"less than"

<<n3<<" and "<<n1;

if (n3<n1 && n3 <n2)

cout <<n3<<" less than "

<<n1<< " and "<<n2;

return 0;

getch ();

}

__Finding the Prime Numer In C++__This is a very simple and not efficient program to find whether a given number is Prime or not. here is my code to solve this program. you can do it by using the Loop.

#include <iostream>This is It. Hope you find it useful. Please comment on your suggestion and if possible also share this with your friend. this is my personal view on how to create these programs. Stay Connected to the (Alixaprodev.com).

#include <conio.h>

using namespace std;

int main ()

{

int i,n;

int count =0;

cout <<"enter a number=";

cin >>n;

for (i=1;i<=n;i++)

{

if (n%i==0)

count++;

}

if (count==2)

cout<<n<<"prime number.";

else

cout <<n<<"not prime number.";

return 0;

}

Nice efforts! keep it up

ReplyDeleteThank you so much. Please stay connected and visit daily. https://alixaprodev.blogspot.com/

Delete## Post a Comment