Deprecated: Optional parameter $i declared before required parameter $data is implicitly treated as a required parameter in /home4/aipsa9vw/public_html/blogs/wp-content/themes/voice/include/modules.php on line 4

Deprecated: Optional parameter $i declared before required parameter $data is implicitly treated as a required parameter in /home4/aipsa9vw/public_html/blogs/wp-content/themes/voice/include/modules.php on line 245

Deprecated: Optional parameter $output declared before required parameter $attr is implicitly treated as a required parameter in /home4/aipsa9vw/public_html/blogs/wp-content/themes/voice/include/snippets.php on line 431

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /home4/aipsa9vw/public_html/blogs/wp-content/themes/voice/include/mega-menu.php on line 147

Warning: Cannot modify header information - headers already sent by (output started at /home4/aipsa9vw/public_html/blogs/wp-content/themes/voice/include/modules.php:4) in /home4/aipsa9vw/public_html/blogs/wp-includes/feed-rss2.php on line 8
CBSE – AIPS ACADEMY https://aipsacademy.com/blogs AIPS ACADEMY Abadganj Daltonganj palamu Jharkhand , Which provides classes For Computer Science 11th 12th BCA , Computer Courses any many more.. palamu's No.1 Institute Fri, 28 Jul 2023 03:56:44 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 https://aipsacademy.com/blogs/wp-content/uploads/2022/08/cropped-aips-logo-32x32.png CBSE – AIPS ACADEMY https://aipsacademy.com/blogs 32 32 Console Input Output in C++ with Example https://aipsacademy.com/blogs/2023/02/12/console-input-output-in-c-with-example/ https://aipsacademy.com/blogs/2023/02/12/console-input-output-in-c-with-example/#respond Sun, 12 Feb 2023 02:20:47 +0000 https://aipsacademy.com/blogs/?p=446 In this tutorial we are going to learn console input output int C++ with example in very easy way.

Input through keyboard and output on the monitor/ screen is known as console input output.

To perform input /output operations , there are various functions.

console input / output can be divided into two categories.

  1. Unformatted input / output functions
  2. Formatted input / output functions

Unformatted input / output functions

It is mainly used for characters. No any control string is used.

Unformatted input functions

1. getch()

It takes entry of a single character. Entered key doesn’t display on the screen . It has defined in #include<conio.h> header file.

2. getche()

It takes a single character and very similar to getch( ). Entered character prints on the screen . It has defined in #include<conio.h> header file.

3. getchar()

It is used to take entry of single character form keyboard. It has defined in #include<stdio.h> header file.

4. gets()

It is used to take entry of a string(more than one words at a time) from the keyboard. It has defined in #include<stdio.h> header file.

Unformatted output functions

1. putch( )

It displays the character on the screen. It has defined in #include<conio.h> header file.

2. putchar( )

It displays the character on the screen. It has defined in #include<stdio..h> header file.

3.puts( )

It is used to display string on the monitor. It has defined in #include<stdio.h> header file.

]]>
https://aipsacademy.com/blogs/2023/02/12/console-input-output-in-c-with-example/feed/ 0
How to create own Header File in C++ with example https://aipsacademy.com/blogs/2023/02/12/how-to-create-own-header-file-in-c-with-example/ https://aipsacademy.com/blogs/2023/02/12/how-to-create-own-header-file-in-c-with-example/#respond Sun, 12 Feb 2023 02:16:00 +0000 https://aipsacademy.com/blogs/?p=443 In this topic we are going to learn How to create own header file in c++ in very easy steps.

As we know that Header file is a file that contains the definition of functions or methods.

It has extension .h by default.

If we write header files in a program then their respective functions can be used.

If we use any function and respective header file related with that function not included in program then compiler generates prototype error.

There are various header files in C++ which contains functions definition .

for example

#include<iostream.h>

contains the method related to input output like cin, cout…..

#include<conio.h>

contains the method related to console input output like clsrscr(), getch(), etc..

#include<math.h>

contains the method related to mathematics like sqrt( ), pow(), etc…

]]>
https://aipsacademy.com/blogs/2023/02/12/how-to-create-own-header-file-in-c-with-example/feed/ 0
Character Handling Functions in C++ with Example https://aipsacademy.com/blogs/2023/02/10/character-handling-functions-in-c-with-example/ https://aipsacademy.com/blogs/2023/02/10/character-handling-functions-in-c-with-example/#respond Fri, 10 Feb 2023 04:58:12 +0000 https://aipsacademy.com/blogs/?p=438 There are various character handling functions in C++ which provide facility to handle character in different ways.

C++ provides #include<ctype.h> header file for character handling.

All character functions have defined in #include<ctype.h> header file . “ctype” means charater type.

Character Functions

  • isalnum() :- This function is used to check whether a character is a letter or a digit i.e alphanumeric or not.
    • syntax isalnum(ch);
  • isdigit():- This function is used to check whether a character is digit or not.
    • syntax isdigit(ch);
  • isalpha():- This function is used to check whether a character is alphabet or not.
    • syntax isalpha(ch);
  • islower():- This function is used to check whether a character is lowercase alphabet or not.
    • syntax islower(ch);
  • isupper():- This function is used to check whether a character is uppercase or not.
    • syntax isupper(ch);
  • tolower():- This function is used to convert uppercase character to lowercase character.
    • syntax tolower(ch);
  • toupper():- This function is used to convert lowercase character to uppercase character.
    • syntax toupper(ch);
  • isspace():- This function is used to check whether a character is white space (blank) or not.
    • syntax ispace(ch);

Where ch is a character variable.

Note :

when a character function is used to check the condition then following cases may occur.

case 1: If condition is true then returns nonzero value.

case 2: If condition is false then returns zero.

Q.Write a program to represent isalnum( ) OR Write a program to check input character is alphabet numeric or not.

12th Computer Science Important Program

C++ Programming

C++ Programming Language Tutorial

Translators in Programming languages

Tokens in C++ Programming Language

Operators in C++ Programming Language

Conditional statements in C++ Language

Switch Statement in C++ Language

Loops / Iteration statement in C++ Language

Jump statements in C++ with best example

Arrays in C++ Programming Language

Functions in C++ Programming Language

Passing Arguments in Functions

Method / Function overloading in C++

String Functions in C++ with Example

Boolean Algebra

Introduction to Boolean Algebra- Best concepts

Important Law of Boolean algebra with Best concepts

Logic Gates and their types -Best Concept

De Morgan’s Law and their Applications

Applications of Boolean Algebra in Computer Science

DBMS

Introduction to DBMS | Database Management System

Communication and Network Concept

Introduction to Communication and Networks

11th Computer Science

C++ Basic Program for 11th Computer Science

]]>
https://aipsacademy.com/blogs/2023/02/10/character-handling-functions-in-c-with-example/feed/ 0
String Functions in C++ with Example https://aipsacademy.com/blogs/2023/01/23/string-functions-in-c-with-example/ https://aipsacademy.com/blogs/2023/01/23/string-functions-in-c-with-example/#respond Mon, 23 Jan 2023 14:17:20 +0000 https://aipsacademy.com/blogs/?p=359 There are various string handling functions in C++ Language which provides facility to handle string or string manipulation in different ways.

All functions of String handling in C++ have defined in header file #include<string.h>

example

strlen(), strcat(), strcpy(), strlwr(), strupr(), etc..

characters Represented in double quote or inverted comma known as string.

Example

“Ram” “225” “A” “5” etc..

String Functions

  • strlen():- It is used to find length of the string.
    • syntax strlen(Str);
  • strcat():- This function is used for concatenating two strings.
    • syntax strcat(Str1, Str2);
  • strcpy():- This function is used for copying of one string to another string.
    • syntax strcpy(Str1,Str2);
  • strupr():- This function converts into uppercase.
    • syntax strupr(Str);
  • strlwr():- This functions converts into lowercase.
    • syntax strlwr(Str);
  • strrev():- This function is used to reverse of the string.
    • syntax strrev(Str);
  • strcmp():- This function is used for comparison of two strings.It is case sensitive.
    • syntax strcmp(Str1,Str2);
  • stricmp():- This compares two strings by ignoring cases. According to this method “RAM” and “Ram” are same.
    • syntax stricmp(Str1,Str2);

Note:

During process of comparison following cases may occur.

case 1: if str1 and str2 are same then output becomes zero.

case 2:- if str1 is greater then output is greater than zero (positive value).

case 3:- if str2 is greater then output is less than zero(Negative value)

Q. Write a program to enter String (name) and print them.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
char str[20]; 
cout<<”Enter any string=”;
cin>>str;
cout<<”String =”<<str;
getch();
}

Output
Enter any string=Ram kumar
String =Ram
Note :- cin>> does not allow to enter full string (more than one word)
Note :- we use gets () function of #include for full string(more than word)

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()  
{
clrscr();
char str[20]; 
cout<<”Enter any string=”;
gets(str);
cout<<”String =”<<str;
getch();
}

Output
Enter any string= Ram kumar
String = Ram kumar

Q.Write a program to find length of the string . or Write a program to represent strlen( ) function.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str[20]; 
cout<<”Enter any string=”;
gets(str);
cout<<”length of string =”<<strlen(str);
getch();
}

OR

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str[20]; 
int l;
cout<<”Enter any string=”;
gets(str);
l=strlen(str);
cout<<”length of string =”<<l;
getch();
}

Output
Enter any String= Ram kumar
length of string =9
Note: Ram (3 letter) Kumar(5 letter) and between space 1 letter

Q.Write a program to convert lowercase string into uppercase string.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str[20]; 
cout<<”Enter any string in lowercase=”;
gets(str);
cout<<”Uppercase string =”<<strupr(str);
getch();
}

Output
Enter any string in lowercase= aips
Uppercase string =AIPS

Q.Write a program to convert uppercase string into lowercase string.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str[20]; 
cout<<”Enter any string in uppercase=”;
gets(str);
cout<<”lowercase string =”<<strlwr(str);
getch();
}

Output
Enter any string in uppercase=AIPS
lowercase string=aips

Q.Write a program to Reverse of input string.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str[20]; 
cout<<”Enter any string =”;
gets(str);
cout<<”reverse string =”<<strrev(str);
getch();
}

Output
Enter any string=AIPS
reverse=SPIA

Q.Write a program represent strcat() function

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str1[20], str2[20]; 
cout<<”Enter first string =”;
gets(str1);
cout<<”Enter second string =”;
gets(str2);

cout<<strcat(str1,str2);
getch();
}

Output
Enter first string=ram
Enter second string=sita
ramsita
Note:- After concatenation (adding) stores in str1.

OR

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str1[20], str2[20]; 
cout<<”Enter first string =”;
gets(str1);
cout<<”Enter second string =”;
gets(str2);
strcat(str1,str2);
cout<<str1;
getch();
}

Output
Enter first string=ram
Enter second string=sita
ramsita

Q.Write a program to represent strcmp( ) function.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str1[20], str2[20]; 
cout<<”Enter first string =”;
gets(str1);
cout<<”Enter second string =”;
gets(str2);

cout<<strcmp(str1,str2);
getch();
}

Output
Enter first string=ram
Enter second string=ram
0
Note:- Returns zero(0) if both the strings are same.

OR


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str1[20], str2[20]; 
cout<<”Enter first string =”;
gets(str1);
cout<<”Enter second string =”;
gets(str2);

cout<<strcmp(str1,str2);
getch();
}

Output
Enter first string=ram
Enter second string=Ram
32
Note:- Returns positive value if str1 is greater. (ASCII r- ASCII R)

OR

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str1[20], str2[20]; 
cout<<”Enter first string =”;
gets(str1);
cout<<”Enter second string =”;
gets(str2);

cout<<strcmp(str1,str2);
getch();
}

Output
Enter first string=Ram
Enter second string=ram
-32
Note:- Returns Negative value if str2 is greater. (ASCII R- ASCII r)

Q.Write a program to represent stricmp( ) function.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str1[20], str2[20]; 
cout<<”Enter first string =”;
gets(str1);
cout<<”Enter second string =”;
gets(str2);

cout<<stricmp(str1,str2);
getch();
}

Output
Enter first string=ram
Enter second string=Ram
0
Note:- compares after ignoring case. according to this function r=R

Q.Write a program to represent strcpy( ) function.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()  
{
clrscr();
char str1[20], str2[20]; 
cout<<”Enter first string =”;
gets(str1);

strcpy(str2,str1);
cout<<str2;
getch();
}

output
Enter first string=ram
ram
Note:- copies Right value to left.

12th Computer Science Important Program

C++ Programming

C++ Programming Language Tutorial

Translators in Programming languages

Tokens in C++ Programming Language

Operators in C++ Programming Language

Conditional statements in C++ Language

Switch Statement in C++ Language

Loops / Iteration statement in C++ Language

Jump statements in C++ with best example

Arrays in C++ Programming Language

Functions in C++ Programming Language

Passing Arguments in Functions

Method / Function overloading in C++

String Functions in C++ with Example

Boolean Algebra

Introduction to Boolean Algebra- Best concepts

Important Law of Boolean algebra with Best concepts

Logic Gates and their types -Best Concept

De Morgan’s Law and their Applications

Applications of Boolean Algebra in Computer Science

DBMS

Introduction to DBMS | Database Management System

Communication and Network Concept

Introduction to Communication and Networks

11th Computer Science

C++ Basic Program for 11th Computer Science

To be continued…. for more……check daily…………

]]>
https://aipsacademy.com/blogs/2023/01/23/string-functions-in-c-with-example/feed/ 0
Method / Function overloading in C++ https://aipsacademy.com/blogs/2023/01/19/method-function-overloading-in-c/ https://aipsacademy.com/blogs/2023/01/19/method-function-overloading-in-c/#respond Thu, 19 Jan 2023 14:15:42 +0000 https://aipsacademy.com/blogs/?p=354 Method / Function overloading means more than one functions with same name with different arguments for different purpose in a program.

Method / Function overloading is an example of polymorphism.

Using no argument no return value function overloading can’t be done.

Example

void area(int); // to find area of square

void area(int,int); //to find area of rectangle

void area(float); // to find area of circle

Q.Write a program to find area of Square,Rectangle, and Circle using function overloading. (compile time)

#include<iostream.h>
#include<conio.h>
void area(int); // for area of square
void area(int,int); // for area of rectangle
void area(float);  // for area of circle
void main()  
{
clrscr();
int s,l,b;
float r;
s=5;
l=6;
b=4;
r=5;
area(s);
area(l,b);
area(r);
getch();
}
void area(int x)
{
cout<<”Area of square=”<<(x*x);
}
void area(int x , int y)
{
cout<<”\nArea of rectangle=”<<(x*y);
}
void area(float x)
{
cout<<”\nArea of circle=”<<(3.14*x*x);
}

Output

Area of square=25

Area of rectangle=24

Area of circle=78.5

Q.Write a program to find area of Square,Rectangle, and Circle using function overloading. (Run time)

#include<iostream.h>
#include<conio.h>
void area(int); // for area of square
void area(int,int); // for area of rectangle
void area(float);  // for area of circle
void main()  
{
clrscr();
int s,l,b;
float r;
cout<<”Enter value of side,length,breadth, and radius=”;
cin>>s>>l>>b>>r;
area(s);
area(l,b);
area(r);
getch();
}
void area(int x)
{
cout<<”Area of square=”<<(x*x);
}
void area(int x , int y)
{
cout<<”Area of rectangle=”<<(x*y);
}
void area(float x)
{
cout<<”\nArea of circle=”<<(3.14*x*x);
}

output

Enter value of side,length,breadth, and radius=5

6

4

5

Area of square=25

Area of rectangle=24

Area of circle=78.5

Note :-

Method / Function Overriding :-

When base class and derived class contains the method of same signature then this term is known as method overriding.

Same signature means every this is same i. Method name, arguments, types, etc.

when we call the method using object of derived class then method of base class is overridden.

example.

class nips

{

public:

void show(int x,int y)

{

…………………

}

};

class gla: public nips

{

public:

void show(int x,int y)

{

……………………

}

}

This topic will be discussed after Inheritance…… …

]]>
https://aipsacademy.com/blogs/2023/01/19/method-function-overloading-in-c/feed/ 0
Passing Arguments in Functions https://aipsacademy.com/blogs/2023/01/19/passing-arguments-in-functions/ https://aipsacademy.com/blogs/2023/01/19/passing-arguments-in-functions/#respond Thu, 19 Jan 2023 14:08:40 +0000 https://aipsacademy.com/blogs/?p=350 Passing arguments in functions means value given to function on which operation is to be performed.

There are three ways of passing arguments in functions.

  1. Call by value / Pass by Value
  2. Call by Reference / Pass by Reference
  3. Call by Address / Pass by Address

Call by value / Pass by value

In this type value is passed in function’s argument and operation is done on formal argument.

Any change made in formal argument does not effect the actual argument.

Q. Write a program to represent call by value for swapping of two variables.

#include<iostream.h>
#include<conio.h>
void swap(int,int);
void main()  
{
clrscr();
int a,b;
a=10;
b=20;
cout<<”Before swapping a=”<<a<<”\tb=”<<b;
swap(a,b);
cout<<”\nAfter swapping in main a=”<<a<<”\tb=”<<b;
getch();
}
void swap(int x,int y)
{
int z;
z=x;
x=y;
y=z;
cout<<”\n After swapping in function a=”<<x<<”\tb=”<<y;
}

Output

Before swapping a=10 b=20

After swapping in function a= 20 b=10

After swapping in main a=10 b=20

OR (Run time)

#include<iostream.h>
#include<conio.h>
void swap(int,int);
void main()  
{
clrscr();
int a,b;
cout<<”Enter value of a and b=”;
cin>>a>>b;
cout<<”Before swapping a=”<<a<<”\tb=”<<b;
swap(a,b);
cout<<”\nAfter swapping in main a=”<<a<<”\tb=”<<b;
getch();
}
void swap(int x,int y)
{
int z;
z=x;
x=y;
y=z;
cout<<”\n After swapping in function a=”<<x<<”\tb=”<<y;
}

Output

Enter value of a and b= 10

20

Before swapping a=10 b=20

After swapping in function a= 20 b=10

After swapping in main a=10 b=20

Call by Reference / Pass by Reference

In this type memory address is passed in function’s Argument Implicitly.

Any change made in formal argument is permanent.

Q. Write a program to represent call by Reference for swapping of two variables.

#include<iostream.h>
#include<conio.h>
void swap(int &,int &);
void main()  
{
clrscr();
int a,b;
a=10;
b=20;
cout<<”Before swapping a=”<<a<<”\tb=”<<b;
swap(a,b);
cout<<”\nAfter swapping in main a=”<<a<<”\tb=”<<b;
getch();
}
void swap(int &x,int &y)
{
int z;
z=x;
x=y;
y=z;
cout<<”\n After swapping in function a=”<<x<<”\tb=”<<y;
}

Output

Before swapping a=10 b=20

After swapping in function a= 20 b=10

After swapping in main a=20 b=10

OR (Run time)

#include<iostream.h>
#include<conio.h>
void swap(int &,int &);
void main()  
{
clrscr();
int a,b;
cout<<”Enter value of a and b=”;
cin>>a>>b;
cout<<”Before swapping a=”<<a<<”\tb=”<<b;
swap(a,b);
cout<<”\nAfter swapping in main a=”<<a<<”\tb=”<<b;
getch();
}
void swap(int &x,int &y)
{
int z;
z=x;
x=y;
y=z;
cout<<”\n After swapping in function a=”<<x<<”\tb=”<<y;
}

Output

Enter value of a and b= 10

20

Before swapping a=10 b=20

After swapping in function a= 20 b=10

After swapping in main a=20 b=10

Call by Address / Pass by Address

In this type memory address is passed in function’s Argument Explicitly.

Any change made in formal argument is permanent.

Q. Write a program to represent call by Address for swapping of two variables.

#include<iostream.h>
#include<conio.h>
void swap(int *, int *);
void main()  
{
clrscr();
int a,b;
a=10;
b=20;
cout<<”Before swapping a=”<<a<<”\tb=”<<b;
swap(&a , &b);
cout<<”\nAfter swapping in main a=”<<a<<”\tb=”<<b;
getch();
}
void swap(int *x , int *y)
{
int *z;
*z=*x;
*x=*y;
*y=*z;
cout<<”\n After swapping in function a=”<<*x<<”\tb=”<<*y;
}

Output

Before swapping a=10 b=20

After swapping in function a= 20 b=10

After swapping in main a=20 b=10

OR (run time)

#include<iostream.h>
#include<conio.h>
void swap(int *, int *);
void main()  
{
clrscr();
int a,b;
cout<<”Enter value of a and b=”;
cin>>a>>b;
cout<<”Before swapping a=”<<a<<”\tb=”<<b;
swap(&a , &b);
cout<<”\nAfter swapping in main a=”<<a<<”\tb=”<<b;
getch();
}
void swap(int *x , int *y)
{
int *z;
*z=*x;
*x=*y;
*y=*z;
cout<<”\n After swapping in function a=”<<*x<<”\tb=”<<*y;
}

Output

Enter value of a and b=10

20

Before swapping a=10 b=20

After swapping in function a= 20 b=10

After swapping in main a=20 b=10

]]>
https://aipsacademy.com/blogs/2023/01/19/passing-arguments-in-functions/feed/ 0
Functions in C++ Programming Language https://aipsacademy.com/blogs/2023/01/19/functions-in-c-programming-language-2/ https://aipsacademy.com/blogs/2023/01/19/functions-in-c-programming-language-2/#respond Thu, 19 Jan 2023 14:00:36 +0000 https://aipsacademy.com/blogs/?p=347

The number of statements grouped in a logical units to perform some specific task , are called functions.

Function makes program easier to understand and maintain .

when a program is made using function that can be easily modified and error can be detected.

A large program is divided into several functions to handle in easy way.

There are two types of function.

  1. Library function / Built in function
  2. User defined function.

Library Function

The predefined function is called library function.

we can use library function using their respective header files.

If we use library functions and respective header file is not included then we get Prototype error.

we can’t understand the internal working of the library function.

example: sqrt( ), pow( ), strlen( ) , etc…

User defined function

The function defined by the user is called user defined function.

we can understand the structure of the user defined function.

we can modify user defined function when needed .

It can be used in four ways.

  1. No Argument, No Return value
  2. With Argument, But not Return value
  3. With Argument , with Return value
  4. No Argument, but return value

Parts of Functions:

There are following part of function.

  1. Function prototyping:- It determines the function name,number of arguments and their types, return type etc..
  2. Function call:- When we want to execute the statements of function then we need function calling. function is invoked or called with parameters or arguments.
  3. Function definition :- It contains the statement, which to be performed after calling.
  4. Actual argument:- Argument inside the function call is known as actual argument.
  5. Formal Argument:- Argument inside the function definition is called formal argument.

No Argument , No Return Value

example

void sum(); // prototyping part
void main()
{
......
......
.......
sum(); // calling part
getch();
}
void sum()
{
.....
......//Definitioin part

}

Q.Write a program to find sum of two numbers using No argument , No return value.(compile time)

#include<iostream.h>
#include<conio.h>
void sum();
void main()
{
clrscr();
sum();
getch();
}
void sum()
{
float a,b,c;
a=10;
b=20;
c=a+b;
cout<<”Sum=”<<c;
}

Output

Sum=30

Q.Write a program to find sum of two numbers using No argument , No return value.(Run time)

#include<iostream.h>
#include<conio.h>
void sum();
void main()
{
clrscr();
sum();
getch();
}
void sum()
{
float a,b,c;
cout<<”Enter value of a and b=”;
cin>>a>>b;
c=a+b;
cout<<”Sum=”<<c;
}

output

Enter value of a and b=10

20

sum=30

With Argument , But not Return Value

Example

void sum(float ,float); // prototyping part
void main()
{
float a,b;
a=10;
b=20;
......
.......
sum(a,b); // calling part, Actual argument
getch();
}
void sum(float x,float y)  // formal argument
{
float z;
z=x+y;
cout<<"sum="<<z;
......//Definitioin part

}

Q.Write a program to find sum of two numbers using with argument , but not return value.(compile time)

#include<iostream.h>
#include<conio.h>
void sum(float,float);
void main()
{
clrscr();
float a,b;
a=10;
b=20;
sum(a,b);
getch();
}
void sum(float x, float y)
{
float z;
z=x+y;
cout<<”Sum=”<<z;
}

Output

sum=30

Q.Write a program to find sum of two numbers using with argument , but not return value.(Run time)

#include<iostream.h>
#include<conio.h>
void sum(float,float);
void main()
{
clrscr();
float a,b;
cout<<”Enter value of a and b=”;
cin>>a>>b;
sum(a,b);
getch();
}
void sum(float x, float y)
{
float z;
z=x+y;
cout<<”Sum=”<<z;
}

Output

Enter value of a and b=10

20

sum=30

With Argument, With Return value

Example

float sum(float ,float); // prototyping part
void main()
{
float a,b,c;
a=10;
b=20;
......
.......
c=sum(a,b); // calling part, Actual argument
cout<<"Sum="<<c;
getch();
}
float sum(float x,float y)  // formal argument
{
float z;
z=x+y;
return z;
......//Definitioin part

}

Q.Write a program to find sum of two numbers using with argument , with return value.(compile time)

#include<iostream.h>
#include<conio.h>
float sum(float,float);
void main()
{
clrscr();
float a,b,c;
a=10;
b=20;
c=sum(a,b);
cout<<”Sum=”<<c;
getch();
}
float sum(float x, float y)
{
float z;
z=x+y;
return z;
}

Output

sum=30

Q.Write a program to find sum of two numbers using with argument , with return value.(Run time)

#include<iostream.h>
#include<conio.h>
float sum(float,float);
void main()
{
clrscr();
float a,b,c;
cout<<”Enter value of a and b=”;
cin>>a>>b;
c=sum(a,b);
cout<<”Sum=”<<c;
getch();
}
float sum(float x, float y)
{
float z;
z=x+y;
return z;
}

Output

Enter value of a and b=10

20

sum=30

to be continued…..check Regular for more…..update

]]>
https://aipsacademy.com/blogs/2023/01/19/functions-in-c-programming-language-2/feed/ 0
Jump statements in C++ with best example https://aipsacademy.com/blogs/2023/01/19/jump-statements-in-c-with-best-example/ https://aipsacademy.com/blogs/2023/01/19/jump-statements-in-c-with-best-example/#respond Thu, 19 Jan 2023 13:55:00 +0000 https://aipsacademy.com/blogs/?p=344 Jump statements are used to transfer the control form one part of the program to another part.

There are three jump statements in C++ programming language.

  1. break statement
  2. continue statement
  3. goto statement

Break Statement in C++

This statement is used for two purpose.

  1. To terminate loop permanently
  2. To exit from switch case

Q. write a program to represent break statement.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=10; i++)
{
if(i==5)
break;
cout<<”\n AIPS ACADEMY”;
}
getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

OR

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=10; i++)
{
cout<<”\n AIPS ACADEMY”;

if(i==5)
break;
}
getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

Find Output

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=10; i++)
{

if(i==5)
break;
cout<<”\n”<<i;

}
getch();
}

output

1

2

3

4

Find Output

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=10; i++)
{
cout<<”\n”<<i;

if(i==5)
break;

}
getch();
}

Output

1

2

3

4

5

Continue Statement in C++

It is used to skip one execution of loop.

Q. write a program to represent continue statement.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=5; i++)
{

if(i==3)
continue;
cout<<”\n”<<i;

}
getch();
}

Output

1

2

4

5

Find output

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=5; i++)
{
cout<<”\n”<<i;

if(i==3)
continue;

}
getch();
}

Output

1

2

3

4

5

Goto Statement in C++

It is used to transfer the control from one part of the program to another part.

It can also be used for repeat some statements.

syntax

goto label;

Q. Write a program to print your name five times using goto statement.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
i=1;
aips:
cout<<”\n AIPS ACADEMY”;
i++;
if(i<=5)
goto aips;

getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

Q. Write a program to print numbers from 1 to 5 using goto statement.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
i=1;
aips:
cout<<”\n”<<i;
i++;
if(i<=5)
goto aips;

getch();
}

Output

1

2

3

4

5

Also Read: Loop in C++

]]>
https://aipsacademy.com/blogs/2023/01/19/jump-statements-in-c-with-best-example/feed/ 0
Arrays in C++ Programming Language https://aipsacademy.com/blogs/2023/01/19/arrays-in-c-programming-language/ https://aipsacademy.com/blogs/2023/01/19/arrays-in-c-programming-language/#respond Thu, 19 Jan 2023 13:47:29 +0000 https://aipsacademy.com/blogs/?p=341

Arrays are the fixed size, sequence collection of elements of same type.

It used to handle large volume of data in the term storing, Accessing and manipulating.

It is a derived data type, because we have to take help of primary data type when we use an array.without primary data type array can’t be used.

It shares common name for all its elements.

It works on index number and index begins with zero and ends with size -1.

Size of an array is known as subscript of an array.

It can be considered as set of elements stored in consecutive memory location but having same data type.

Types of Arrays

There are two types of array.

  1. single dimensional Array
  2. Double or Multi dimensional Array

Single dimensional Array:

An Array which works on single index , is known as single dimensional array or 1- D Array.

It is used for searching , sorting etc.

Syntax :

Datatype Array_Name[size];

int ar[5];

Q.Find sum of five numbers without array.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e,f;
a=5;
b=7;
c=9;
d=11;
e=13;
f=a+b+c+d+e;
cout<<"Sum="<<f;
getch();
}

output

sum=45

Q.Find sum of Five numbers using array.(only for cocept)

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5],s;
a[0]=5;
a[1]=7;
a[2]=9;
a[3]=11;
a[4]=13;
s=a[0]+a[1]+a[2]+a[3]+a[4];
cout<<”Sum=”<<s;
getch();
}

Output

sum=45

OR

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5]={5,7,9,11,13},s;
s=a[0]+a[1]+a[2]+a[3]+a[4];
cout<<”Sum=”<<s;
getch();
}

Output

Sum=45

OR

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5],s;
cout<<”Enter five numbers=”
cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
s=a[0]+a[1]+a[2]+a[3]+a[4];
cout<<”Sum=”<<s;
getch();
}

output

Enter five numbers=5

7

9

11

13

Sum=45

Q.Write a program to represent single dimensional array.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int a[5],i;	
cout<<”Enter five elements”;
for(i=0;i<5;i++)
{
cin>>a[i];
}
cout<<”Entered elements are”;
for(i=0;i<5;i++)
{
cout<<”\n”<<a[i];
}

getch();
}

Output

Enter five elements=11

12

13

14

15

Entered elements are

11

12

13

14

15

Q.Write a program to print Array’s elements in reverse order.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int a[5],i;	
cout<<”Enter five element”;
for(i=0;i<5;i++)
{
cin>>a[i];
}
cout<<”Entered elements in reverse order”;
for(i=4;i>=0;i--)
{
cout<<”\n”<<a[i];
}

getch();
}

Output

Enter five elements

11

12

13

14

15

Entered elements in reverse order

15

14

13

12

11

Q.Write a program to enter number of elements in an array and print them

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int a[50],n,i;	
cout<<”Enter number of elements=”;
cin>>n;
cout<<”Enter arrays elements=”;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<”Entered elements are”;
for(i=0;i<n;i++)
{
cout<<”\n”<<a[i];
}

getch();
}

output

Enter number of elements=5

Enter arrays elements=11

12

13

14

15

Entered elements are

11

12

13

14

15

Q.Write a program to enter number of elements in array and print them in reverse order.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int a[50],n,i;	
cout<<”Enter number of elements=”;
cin>>n;
cout<<”Enter arrays elements=”;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<”Entered elements in reverse”;
for(i=n-1;i>=0;i--)
{
cout<<”\n”<<a[i];
}

getch();
}

output

Enter number of elements=5

Enter arrays elements=11

12

13

14

15

Entered elements in reverse

15

14

13

12

11

Q.Write a program to find sum of entered arrays elements.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int a[50],n,i,s=0;	
cout<<”Enter number of elements=”;
cin>>n;
cout<<”Enter arrays elements=”;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<”Entered elements are”;
for(i=0;i<n;i++)
{
cout<<”\n”<<a[i];
s=s+a[i];
}
cout<<”\nSum of elements =”<<s;
getch();
}

output

Enter number of elements=5

Enter arrays elements=11

12

13

14

15

Entered elements are

11

12

13

14

15

sum of elements =65

Q.Write a program to find the smallest element in an array.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int a[50],n,i,s;	
cout<<"Enter number of elements=";
cin>>n;
cout<<"Enter arrays elements=";
for(i=0;i<n;i++)
cin>>a[i];

s=a[0];
for(i=1;i<n;i++)
{
if(s>a[i])
s=a[i];
}
cout<<"Smallest element ="<<s;
getch();
}

Output

Enter number of elements=5

Enter array’s elements=12

15

11

25

13

Smallest element=11

Q.Write program to find largest element in an array.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int a[50],n,i,l;	
cout<<”Enter number of elements=”;
cin>>n;
cout<<”Enter arrays elements=”;
for(i=0;i<n;i++)
cin>>a[i];

l=a[0];
for(i=1;i<n;i++)
{
if(l<a[i])
l=a[i];
}
cout<<”Largest element =”<<l;
getch();
}

Output

Enter number of elements=5

Enter array’s elements=12

15

11

25

13

Largest element=25

Q.Write a program to find largest and smallest element in an array.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int a[50],n,i,l,s;	
cout<<”Enter number of elements=”;
cin>>n;
cout<<”Enter arrays elements=”;
for(i=0;i<n;i++)
cin>>a[i];

s=a[0];
l=a[0];
for(i=1;i<n;i++)
{
if(s>a[i])
s=a[i];

if(l<a[i])
l=a[i];
}
cout<<”Smallest element=”<<s;
cout<<”Largest element =”<<l;
getch();
}

Output

Enter number of elements=5

Enter array’s elements=12

15

11

25

13

Smallest element=11

Largest element=25

Q.Write a program to represent Searching. OR Write a program to check particular is present or not in Array.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int a[50],n,i,t,j=0;	
cout<<”Enter number of elements=”;
cin>>n;
cout<<”Enter arrays elements=”;
for(i=0;i<n;i++)
cin>>a[i];
cout<<”Enter element which to be searched=”;
cin>>t;
for(i=0;i<n;i++)
{
if(t==a[i])
{
j=1;
break;
}
}
if(j==1)
cout<<”Element found at=”<<(i+1);
else
cout<<”Element not found”;
getch();
}

Output

Enter number of elements=5

Enter array’s elements=12

15

11

25

13

Enter element which to be searched=11

Element found at=3

Double Dimensional Array:-

An array which works on double index is called double dimensional array or 2 -D Array.

It is used for matrix manipulation or handle data in tabular form.

Syntax :

Datatype Array_Name[size][size];

int ar[5][5];

Q.Write a program to represent double dimensional array

to be continued…. Plz check for daily update….

]]>
https://aipsacademy.com/blogs/2023/01/19/arrays-in-c-programming-language/feed/ 0
Loops / Iteration statement in C++ Language https://aipsacademy.com/blogs/2023/01/19/loops-iteration-statement-in-c-language/ https://aipsacademy.com/blogs/2023/01/19/loops-iteration-statement-in-c-language/#respond Thu, 19 Jan 2023 13:33:00 +0000 https://aipsacademy.com/blogs/?p=334 Loops are used to repeat set of statement as long as specified condition is true.

loop/Iteration is a block of statement which are repeatedly executed for a certain number of times.

Loop is used to execute the statements repeatedly as long as the specified condition is true.

There are two categories of Loops:

  1. Entry control loop:- This loop executes when specified condition is true. Example for loop, while loop.
  2. Exit control loop:- This loop executes at least once whether the specified condition is true or false. example do while loop.

Parts of Loop

There are following parts of loop.

Initialization :- It indicates from where loop is to be started.

example: i=1;

Test condition:- It indicates how many times loop is to be executed.

example: i<=5;

Increment /Decrement :- To reach an end of the test condition increment or decrement is needed.

example: i++, i- –

For Loop:

This loop is the easiest loop among all the loops because it contains all the loop control structure at one place in a pair of parenthesis.

It is used for fixed time iteration.

It checks the initialization first then evaluates the test condition and if test condition becomes true then body of the loop is executed.

At last control goes to increment\ decrement and again test condition is evaluated , if test condition founds true then again body of the loop is executed.

This process continues until the specified condition is true.

syntax:

for(initialization; test condition ; increment/decrement)

{

body of the loop;

}

Q.Write a program to print your name five times using for loop.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=1;i<=5;i++)
{
cout<<"\n AIPS ACADEMY";
}
getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

OR

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=5;i>=1;i--)
{
cout<<"\n AIPS ACADEMY";
}
getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

Q.Write a program to print numbers from 1 to 5.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=1;i<=5;i++)
{
cout<<”\n”<<i;
}
getch();
}

output

1

2

3

4

5

Q. Write a program to print number from 5 to 1.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=5;i>=1;i- -)
{
cout<<”\n”<<i;
}
getch();
}

Output

5

4

3

2

1

Q. Write a program to print even number from 1 to 20.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=2;i<=20;i+=2)
{
cout<<”\n”<<i;
}
getch();
}

Output

2

4

6

8

10

12

14

16

18

20

Q. Write a program to print odd number from 1 to 10.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=1;i<=10;i+=2)
{
cout<<”\n”<<i;
}
getch();
}

Output

1

3

5

7

9

Q. Find output.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=5;i<=50;i+=5)
{
cout<<”\n”<<i;
}
getch();
}

Output

5

10

15

20

25

30

35

40

45

50

Q.Find output

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=50;i>=5;i-=5)
{
cout<<”\n”<<i;
}
getch();
}

Output

50

45

40

35

30

25

20

15

10

5

Q.Write a program to print your name up to specified term.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i;	
cout<<”Enter terms”;
cin>>n;
for(i=1;i<=n;i++)
{
cout<<”\n AIPS ACADEMY”;
}
getch();
}

Output

Enter terms=4

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

Q.Write a program to print numbers from 1 to specified term

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i;	
cout<<”Enter terms”;
cin>>n;
for(i=1;i<=n;i++)
{
cout<<”\n”<<i;
}
getch();
}

Output

Enter terms=5

1

2

3

4

5

Q.Write a program to print numbers from specified term to 1.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i;	
cout<<”Enter terms”;
cin>>n;
for(i=n;i>=1;i--)
{
cout<<”\n”<<i;
}
getch();
}

Output

Enter terms=5

5

4

3

2

1

Q.Write a program to print table of input number.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i,j;	
cout<<”Enter any number=”;
cin>>n;
for(i=1;i<=10;i++)
{
j=n*i;
cout<<”\n”<<j;
}
getch();
}

Output

Enter any number =5

5

10

15

20

25

30

35

40

45

50

Q.Write a program to print table of input number in following format.

Enter any number=5

5*1=5

5*2=10

…………..

……………

5*10=50

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i,j;	
cout<<”Enter any number=”;
cin>>n;
for(i=1;i<=10;i++)
{
j=n*i;
cout<<”\n”<<n<<”*”<<i<<”=”<<j;
}
getch();
}

Output

Enter any number=5

5*1=5

5*2=10

…………..

……………

5*10=50

Q.Write a program to print Factorial of input number.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i,j=1;	
cout<<”Enter any number=”;
cin>>n;
for(i=n;i>=1;i--)
{
j=j*i;
}
cout<<”Factorial=”<<j;
getch();
}

Output

Enter any number=5

Factorial=120

OR

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i,j=1;	
cout<<”Enter any number=”;
cin>>n;
for(i=n;i>=1;i--)
{
j=j*i;
cout<<i<<”*”;
}
cout<<”=”<<j;
getch();
}

Output

Enter any number=5

5*4*3*2*1*=120

Q.Write a program to find factor of input number.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i;	
cout<<”Enter any number=”;
cin>>n;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
cout<<”\n”<<i;
}
}
getch();
}

Output

Enter any number =6

1

2

3

6

Q.Write a program to find sum of factors of input number.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i,s=0;	
cout<<”Enter any number=”;
cin>>n;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
cout<<”\n”<<i;
s=s+i;
}
}
cout<<”sum of factor=”<<s;
getch();
}

Output

Enter any number =6

1

2

3

6

sum of factors=12

Q.Write a program to check number is perfect or not.

(sum of factors =two times of number)

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i,s=0;	
cout<<”Enter any number=”;
cin>>n;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
s=s+i;
}
}
if(s==n*2)
cout<<”Perfect number”;
else
cout<<”Not perfect number”;

getch();
}

Output

Enter any number=6

Perfect number

Q.Find output.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=65;i<=90;i++)
{
cout<<i <<"\t";
}

getch();
}

Output

65 66 67 68 69 70 ……..90

Q.Write a program to print uppercase alphabet using ASCII Code.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=65;i<=90;i++)
{
cout<<(char)i;
}

getch();
}

Output

A B C D E F G H……….Z

Q.Write a program to print uppercase alphabet in reverse order.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=90;i>=65;i--)
{
cout<<(char)i;
}

getch();
}

Output

Z Y X W ………………..A

Q. Find Output

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=90;i>=65;i--)
{
cout<<i;
}

getch();
}

90 89 88 87…..65

Q.Write a program to print lowercase alphabet using ASCII Code.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=97;i<=122;i++)
{
cout<<(char)i;
}

getch();
}

Output

a b c d e …………………..z

Q.Find output

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=97;i<=122;i++)
{
cout<<i;
}

getch();
}

Output

97 98 99 100…….122

Q.Write a program to print lowercase alphabet in reverse order.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=122;i>=97;i--)
{
cout<<(char)i;
}

getch();
}

Output

z y x w ………………..a

Q.Write a program to print numbers from 0 to 9 using ASCII code.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=48;i<=57;i++)
{
cout<<(char)i;
}

getch();
}

Output

0 1 2 3 4 5 6………………..9

Q.Find output.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
for(i=48;i<=57;i++)
{
cout<<i;
}

getch();
}

Output

48 49 50 51 52 53 ……..57

Q.Write a program to print following series.

1 2 3 4 5 ……………n

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i;	
cout<<”Enter value of n=”;
cin>>n;
for(i=1;i<=n;i++)
{
cout<<i<<”\t”;
}

getch();
}

Output

Enter value of n=5

1 2 3 4 5

Q.Write a program to print following series and sum also.

1 2 3 4 5 ……………n

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,i,s=0;	
cout<<”Enter value of n=”;
cin>>n;
for(i=1;i<=n;i++)
{
cout<<i<<”\t”;
s=s+i;
}
cout<<”\nsum of series=”<<s;
getch();
}

Output

Enter value of n=5

1 2 3 4 5

sum of series=15

While loop:-

This loop is an entry control loop. It executes the block of statement as long as the certain condition is satisfied.

Control exits from loop when the specified condition is false.

Syntax:

while(test condition)

{

body of the loop;

}

Q.Write a program to print your name five times using while loop.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
i=1;
while(i<=5)
{
cout<<”\n AIPS ACADEMY”;
i++;
}
getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

OR

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
i=5;
while(i>=1)
{
cout<<”\n AIPS ACADEMY”;
i--;
}
getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

Q.Write a program to print reverse of digits of input number.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,r,s=0;	
cout<<”Enter value of n=”;
cin>>n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
cout<<”Reverse of digits=”<<s;
getch();
}

Output

Enter any number=123

Reverse=321

Q.Write a program to print sum of digits of of input number.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,r,s=0;	
cout<<”Enter value of n=”;
cin>>n;
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
cout<<”sum of digits=”<<s;
getch();
}

Output

Enter any number=123

sum of digits =6

Q.Write a program to print multiplication of digits of of input number.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,r,s=1;	
cout<<”Enter value of n=”;
cin>>n;
while(n>0)
{
r=n%10;
s=s*r;
n=n/10;
}
cout<<”Multiplication of digits=”<<s;
getch();
}

Output

Enter any number=423

Multiplication of digits =24

Q.Write a program to check to number is palindrome or not.

(palindrome means same number and reverse)

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int n,r,s=0,t;	
cout<<”Enter value of n=”;
cin>>n;
t=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(s==t)
cout<<”Palindrome number”;
else
cout<<”Not palindrome number”;
getch();
}

Output

Enter any number=121

Palindrome number

Do- while loop:-

This loop executes its body at least once whether the specified condition is true or false.

This loop executes its body first then checks the test condition.

Syntax:

do

{

body of the loop;

}while(test condition);

Q. Write a program to print your name five times using do while loop.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
i=1;
do
{
cout<<”\n AIPS ACADEMY”;
i++;
} while(i<=5);

getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

OR

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
i=5;
do
{
cout<<”\n AIPS ACADEMY”;
i--;
} while(i>=1);

getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

Q.Write a program to print numbers from 1 to 5 using do while.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
i=1;
do
{
cout<<”\n”<<i;
i++;
} while(i<=5);

getch();
}

Output

1

2

3

4

5

Q.Write a program to print numbers from 5 to 1 using do while.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;	
i=5;
do
{
cout<<”\n”<<i;
i--;
} while(i>=1);

getch();
}

Output

5

4

3

2

1

Nested Loop in C++

one loop inside another loop is called nested loop. It is used to print data in tabular form.

example:

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

{

for(j=1;j<=3;j++)

{

cout<<“AIPS \t”;

}

cout<<“\n”;

}

here j is nested or inner loop and i is outer loop.

outer loop for row and inner loop for column

Q.Write a program to print following format.

AIPS AIPS AIPS AIPS

AIPS AIPS AIPS AIPS

AIPS AIPS AIPS AIPS

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
{
cout<<”AIPS  \t”;
}
cout<<”\n”;
}
getch();
}

Q.Write a program to print following format.

1 2 3 4 5

1 2 3 4 5

1 2 3 4 5

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=5;j++)
{
cout<<j<<”\t”;
}
cout<<”\n”;
}
getch();
}

Q.Write a program to print following format.

1 1 1 1 1

2 2 2 2 2

3 3 3 3 3

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=5;j++)
{
cout<<i<<”\t”;
}
cout<<”\n”;
}
getch();
}

Q.Write a program to print following format.

AIPS

AIPS AIPS

AIPS AIPS AIPS

AIPS AIPS AIPS AIPS

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
cout<<”AIPS \t”;
}
cout<<”\n”;
}
getch();
}

Q.Write a program to print following format.

1

1 2

1 2 3

1 2 3 4
#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
cout<<j<<” \t”;
}
cout<<”\n”;
}
getch();
}

Q.Write a program to print following format.

1

2 2

3 3 3

4 4 4 4

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
cout<<i<<” \t”;
}
cout<<”\n”;
}
getch();
}

Q.Write a program to print following format.

A B C D E

A B C D E

A B C D E

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=65;i<=67;i++)
{
for(j=65;j<=69;j++)
{
cout<<(char)j<<” \t”;
}
cout<<”\n”;
}
getch();
}

Q.Write a program to print following format.

A A A A A

B B B B B

C C C C C

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=65;i<=67;i++)
{
for(j=65;j<=69;j++)
{
cout<<(char)i<<” \t”;
}
cout<<”\n”;
}
getch();
}

Q.Write a program to print following format.

A

A B

A B C

A B C D

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=65;i<=68;i++)
{
for(j=65;j<=i;j++)
{
cout<<(char)j<<” \t”;
}
cout<<”\n”;
}
getch();
}

Q.Write a program to print following format.

A

B B

C C C

D D D D

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i,j;
for(i=65;i<=68;i++)
{
for(j=65;j<=i;j++)
{
cout<<(char)i<<” \t”;
}
cout<<”\n”;
}
getch();
}

to be continued…

]]>
https://aipsacademy.com/blogs/2023/01/19/loops-iteration-statement-in-c-language/feed/ 0