Home » Archives for September 2013
Unknown |
4:10 PM |
C/C++
Do you know what is a prime number?
A natural number greater than 1 which has only two divisors 1 and it is called a prime number. For example: 7 is a prime number. Because it has only two divisors 1 and 7 (itself).
Now I am going to tell you how to find a prime number by using C++ program. Just type these code below
//C++ Program to find Prime number
#include<iostream.h>
#include<conio.h>
void main()
{
//clrscr();
int number,count=0;
cout<<"Enter number to check it is Prime or not ";
cin>>number;
for(int a=1;a<=number;a++)
{
if(number%a==0)
{
count++;
}
}
if(count==2)
{
cout<<" PRIME NUMBER \n";
}
else
{
cout<<" NOT A PRIME NUMBER \n";
}
//getch();
}
Thanks!
Read more ...
Unknown |
11:14 AM |
C/C++
// A C++ program to find the largest value among any four numbers
#include <iostream.h>
void main(void)
{
float a,b,c,d;
cout << "Enter any four numbers \n";
cin >>a >>b >>c >>d;
if (a > b) {
if (a > c) {
if (a > d)
cout <<"Largest value" << a << endl;
else cout <<"Largest value" << d << endl;
}
else {
if (c > d)
cout <<"Largest value" << c << endl;
else cout <<"Largest value" << d << endl;
}
} // end of outer if part
else {
if (b > c) {
if (b > d)
cout <<"Largest value" << b << endl;
else cout <<"Largest value" << d << endl;
}
else {
if (c > d)
cout <<"Largest value" << c << endl;
else cout <<"Largest value" << d << endl;
}
} // end of outer else part
} // end of main program
Output:
Enter any four numbers
10 40 50 70
Largest value 70
Thanks!
Read more ...
Unknown |
1:20 PM |
C/C++
Now I am telling you how to find the largest value of any three numbers with C++ program.
If you enter any three numbers you will get the largest value from these. It's so simple and easy program.
However, Let's start our program.
#include <iostream.h>
void main( void)
{
float x,y,z;
cout << "Enter any three numbers \n";
cin >> x >> y >> z;
if (x > y) {
if (x > z)
cout <<"Largest value" << x << endl;
else
cout <<"Largest value" << z << endl;
}
else if (y > z)
cout <<"Largest value" << y << endl;
else
cout <<"Largest value" << z << endl;
} // end of main program
You can see this output:
Enter any three numbers
10 40 50
Largest value 50
Read more ...
Unknown |
10:12 AM |
C/C++
Today I am going to tell you how to get Compound Interest with C program. It is not very difficult. Very simple and easy program.
However, Let's start our program. Open your Turbo C program and enter the following codes:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main (){
float p, r, n, i, f;
clrscr ();
printf("Please enter a value for the principal (p) : );
scanf ("%f", &p);
printf("Please enter a value for the interest rate (r) : );
scanf ("%f", &r);
printf("Please enter a value for the number of Years (n) : );
scanf ("%f", &n);
i=r/100;
i=i+l
f=p*(pow (i,n));
printf ("\n The Final value (F) is : %. 3f",f);
getch ();
}
Then compile and run.
Thanks!
Read more ...
Unknown |
2:20 PM |
C/C++
Today I am
going to tell you how to create a simple C++ program.
Suppose we
would like to display the message “Hello world! This is my first program” on
your video screen.
#include
<iostream. h>
void
main() // program heading
{ // begin
cout
<< "Hello world! This is my
first program";
} // end
The
function main() must be placed before the begin statement. It invokes another
function to perform its job. The { symbol or notation is used as the
begin statement. The declaration of variables and the type of operations are
placed after the begin statement. The end statement is denoted by the
symbol }. In C++ , the semicolon
(;) serves the purpose of the statement terminator rather than a separator.
Statements are terminated by a semicolon and
are grouped within braces {….}. Most statement contains expression, sequences
of operators, function calls, variables and constants that specify computation.
Variable
and function names are of arbitrary length and consist of upper and lower case
letters, digits and underscore and they may not start with a numeral. All C++
keywords are written in lowercase letters.
Any
statement or functions within comments are not executable and they are ignored
by the compiler.
Read more ...
Unknown |
5:24 PM |
C/C++
For the last couple of decades, the C programming language has been widely accepted for all applications, and are perhaps the most powerful of structured programming languages.
In recent times, the object oriented programming (OOP) paradigm has become
popular in modern software life cycles. Now, C++ has the status of a structured
programming language with Object Oriented Programming (OOP) methodology, in
which the software reusability, testability, maintainability, portability and reliability
are the key features and requisites of modern software development.
Initially, the
C++ programming language was considered as just an enhanced version of the C
program with a few extra keywords. But it is not so. It is one of the well designed
and widely accepted object oriented programming languages.
C++ has
become quite popular due to the following reasons:
- · ·
It
supports all features of both structured programming and object oriented
programming.
- ·
It
gives the easiest way to handle the data hiding and encapsulation with the help
of powerful keyword such as class,
private, public and protected.
- ·
Polymorphism
through virtual function, virtual based classes and virtual destructors give the
late binding of the compiler.
- ·
Inheritance,
one of the most powerful design concepts is supported with single inheritance
and multiple inheritance of base class and derived classes.
- ·
It
provides overloading of operators and functions.
- ·
C++
focuses on function and class templates for heading parameterized data types.
- ·
Exception
heading is done with the extra keyword , namely, try, catch and throw.
- ·
Provides
friends, static methods, constructors destructors for the class objects.
-
This blog has
been organized in such a manner that new programmers will find easy to read and
understand. I have assumed the reader has no prior knowledge of C++.
Read more ...