C++ program to find the sum of digits of a number.
Algorithm:-
Input=number
number1=0, sum=0;
while loop > 0
(a) number1 equal to remainder of number divide
by 10
number1=number%10;
(b) add sum and number1 to sum
sum=sum+number1;
(c) divide number by 10
number=number/10;
print sum;
exit;
Approach to solve:-
Input=259
number1=number%10=9
sum=sum+number1=9
number=number/10=25
number1=number%10=5
sum=sum+number1=14
number=number/10=2
number1=number%10=2
sum=sum+number1=16
number=number/10=0
Program:-
#include<iostream>
using...
Wednesday, 22 November 2017
Saturday, 18 November 2017
C++ program to check whether a number is palindrome or not?
what is a palindromic number?
A palindromic number is a number which remains same when its digits are reversed. Example 121,16461 etc.
Let understand the algorithm of the program.
Input=number
reverse_number=0;
temp=number;
while loop number > 0
(a)multiply reverse_number by 10 and add remainder of number divide by 10 to reverse_number
reverse_number= reverse_number*10+number%10;
(b)divide...
Thursday, 16 November 2017
How to reverse a number in C++?
Write a C++ program to reverse digits of a number
Reverse number:-
Input=7890
Output=0987
Algorithm:-
Input=number
reverse_number=0;
while loop number > 0
(a)multiply reverse_number by 10 and add remainder of number divide by 10 to reverse_number
reverse_number= reverse_number*10+number%10;
(b)divide number by 10
number=number/10;
print reverse_number.
Approach to solve:-
Input:num=7890
rev_num=0
rev_num=rev_num*10+num%10=0
num=num/10=789
rev_num=rev_num*10+num%10=09
num=num/10=78
rev_num=rev_num*10+num%10=098
num=num/10=7
rev_num=rev_num*10+num%10=0987
num=num/10=0
Program:-
#include<iostream>
using...
Sunday, 22 October 2017
Jump Statement:Break,Go To and Continue statement
JUMP STATEMENTS
Jump statements are used to interrupt the normal flow of the program or you can say that the jump statements are used to jump a particular statement or piece of code.
Types of jump statements:-
Break
Continue
GoTo
BREAK STATEMENT:-
The break statement is used inside the loop or switch case.It is used to come out from the loop or switch case.When we use break statement...
Friday, 20 October 2017
Do While Loop
DO... WHILE LOOP
Do... while is another type of looping.It is quite different from the for loop but similar to the while loop with one important difference. In do... while loop initialization at the top of the loop, update condition inside the loop and test condition at bottom of the loop.The body of do..while loop is executed once, Before checking...
Saturday, 14 October 2017
While Loop
WHILE LOOP
while studying for loop we have seen that all the three parts of the loop are present in a line but in while loop, there is a difference in the syntax.In while loop, we initialize the loop outside the loop then test condition where the loop is defined and update condition in the body of the loop.
syntax:-
initialization expression;
while (test_expression)
{
// statements
...
Tuesday, 10 October 2017
How to Install Codeblocks IDE on windows 7 ,8 and 10?

How to install and use codeblocks IDE on windows 7,8 and 10?
hello Folks,
In this post, I will share the steps to download and install codeblocks on windows OS and also share how to use it and compile the program on it.
step by step procedure to install codeblocks
1. As we know codeblocks is...
Friday, 29 September 2017
Types Of For Loop
In the previous post, we understand how for loop works and three parts of for loop.In this post, I will discuss the types of for loop or in which way you will use for loop.
For loops are mainly two types:
Infinite for loop
Nested for loop
THE INFINITE FOR LOOP:-
A loop becomes infinite loop if the condition never becomes false. For loop required three parts to run initialization, test expression,...
Sunday, 24 September 2017
Iteration Statement- For Loop
Iteration is a process where a set of instruction or statement is executed repeatedly for a specified number of time or until a condition is met.Iteration statements are commonly known as loops.There are three types of looping statements in C++:
For
While
Do while
A looping is consist of three parts:- initialization, test expression, increment/decrement or update value. A loop will run whenever...
Friday, 22 September 2017
Selection Statement- the switch case statement
THE SWITCH CASE STATEMENT:-
A switch statement is used for multiple-way selections that will branch into different code segments based on the value of a variable or expression. This expression or variable must be of integer data type.
syntax:
switch (expression)
{
case value1:
code segment1;
break;
case value2:
code segment2;
break;
.
.
.
case valueN:
code segmentN;
...
Monday, 18 September 2017
How to write a program without using semicolon in C++?
As we know every line in C++ ends with the semicolon but we can print a string without using any semicolon in the program. we can print string by using if-else, looping or switch case but here I'm print a string with if-else without using the semicolon.
program to print a string without using any semicolon:-
#include<iostream>
using namespace std;
main()
{
if(cout<<"Hello...
Thursday, 14 September 2017
Decision Making Statement:- If-else Statement

Control Statements enable us to specify the flow of program control,i.e. the order in which the instructions in a program must be executed. They make it possible to make decisions, to perform tasks repeatedly or to jump from one section of code to another.
There are four types of control statements...
Subscribe to:
Posts (Atom)