Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

Sunday, November 8, 2020

Simple Array program using C++


For many other Language Programs related to C++ , Data Structure microprocessor 8086 etc... related to MSBTE, Computer engineering, IT ...visit our BLOG


#include<iostream>
using namespace std;
int main()
{
int array[10],b,c;
for(b=0;b<10&&(cin>>c);b++)
{
  array[b]=c;
}
for(b=0;b<10;b++)
{
 cout<<array[b];
}
return 0;
}


Programs:-

For many other Language Programs of microprocessor 8086, C++ , Data Structures visit our  BLOG 

There are programs of Object-Oriented Programming, Operators (logical, arithmetic ,relational,etc) ,exception handling , inheritance ,string operations ,etc




Friday, June 5, 2020

All Operators Explained - C (with Example)



 Here is list of all Types of Operators with Explanation and Example!!
Lets Start....


1. Arithmetic operators:- These are the symbols used to indicate the operations on operands.Here is a table which shows the operators under this section.

Operator
Meaning
Example
+
Addition
a+b;
-
Subtraction
a-b;
*
Multiplication
a*b;
/
Division
a/b;
%
Modulus
a % b;

     
Operation of modulus operator:- 4/2=2 (here quotient is taken)  but in modulus operator, 4%2=0 (here remainder is taken).





2. Relational operator:- These are the symbols used to show the relation between operands.

Operator
Meaning
Example
Less than
a < b;
<=
Less than or equal to
a <= b;
Greater than
a > b;
>=
Greater than or eual to
a >= b;
==
Checking Equal to
a == b;
!=
Checking Not equal to
a != b;
  




3.Logical operator:- These are the symbols used to evaluate the conditions and expressions.

Operator
Meaning
Example
&&
And
a=6 and  b=3;

(a<10 && b>1)
||
Or
a=12 ,b=3;

(a==12 || b==5)
!
Not
a=6 , b=3
 !(a == b)



4. Assignment operator:- 


Operator
Meaning
Example
=
Equals to
x=6



5.Compound Assignment Operator:-


Operator
Example
Equivalent

Assume  c = 10
+=
c + =10
c=20
c= c + 10 ;
==
c - =5
c=5
 c = c- 5 ;
*=
c * =2
c=20
 c = c* 2;
/=
c / = 5
c = 2
c = c/ 5 ;




6. Ternary operator:-  

This operator evaluates the expression or a condition .If condition is true then Value 1 is considered or else the Value 2 is considered.

  { Expression ? Value 1 : Value 2 ;}     

   x = (a = =10)  5 : 15 ;    .........where the value of  a=10
  
Since the given expression in the bracket  (a = =10) becomes true, the value 1 will be returned to the user. Hence, the value of x will be 5.

 x = (a = =10)  5 : 15 ;    .........where the value of  a=3

Since the given expression in the bracket  (a = =10) becomes false, the value 2 will be returned to the user. Hence, the value of x will be 15.



!!  HERE IS A LINK FOR A PROGRAM BASED ON  Ternary / conditional operator  !!





7. Bitwise operator:- 
                                          
Short form of binary language is bit ..... for example the language of 0's and 1's ..
When we have 8 bits we have 1 byte i.e., 1 byte = 8 bits.

Bitwise  operators are used to manipulate the data at bit level. These operators operate on each bit of the data.They are used for complimenting or shifting bits . They may not be applied on float or double types.


Operator
Meaning
~
One’s complement
>> 
Right shift
<< 
Left shift
&
Bitwise AND
|
Bitwise OR
^
Bitwise XOR(exclusive OR)



Working of the operators:-
These operators work on two integer type operands.They work on their operands bit by bit starting from LSB to MSB . Here is their example:-  

Most            - - - - - - -      Least
Significant +   - - - - - - -    Significant
Bit                                        Bit
(MSB)                                    (LSB)



The three most commonly used bitwise operators are :-

1.     Bitwise AND
2.     Bitwise OR
3.     Bitwise XOR
Use and their working:-  Lets take example of milk and tea considering operand1 and operand 2 to be milk and tea respectively.

operand 1= OP1 = milk
operand 2 = OP2 = tea

Operand 1
(milk )
(OP1)
Operand 2
(tea)
(OP2)
 OP1 & OP2
both OP1  (milk) and OP2 (tea) should be available
OP1
/OP2
Any one OP1 (milk) or OP2 (tea) should be available
OP1^
OP2
Highest number will be taken .  Equal inputs will give zero
0
0
(not available)
0
(Equal inputs will give zero)
0
1
0  (both not available)
1
1
1
0
0  (both not available)
1
1
1
1
1  (both available)
1
 (Equal inputs will give zero)



Programs:-

For many other Language Programs of microprocessor 8086, C++ , C , Data Structures visit our  BLOG and search for topic u want .....

Flowchart,Algorithm,Pseudo Code in Detail -Problem Solving Techniques



                                     Hello guys !! Today we will see what are best tips for writing Flowchart, Algorithm, Pseudo code.
                       Step by step this page describes what is Flowchart?, What is algorithm?, What is pseudcode?And also take a look at how to draw and write them correctly.We are also going to see Applications of  Flowchart , Algorithm, Pseudo code.
                       The Problem Solving Techniques include Flowchart , Algorithm, Pseudo code, and Program.They are common to all languages may be in C or C++ or java or python,etc.
                      Lets Start.....



Flowchart:-

           It is a diagramatic representation of flow of execution of program .Each step in  the flow chart is represented by the different symbol  and the symbol  contains  short  description of the process.
                The symbols are linked to each other with arrows showing the direction of the flow.the standard symbols are as follows:-
start/stop = ⭘
input/output =
general =
decision = a rhombus symbol
connector =  ⬅

Algorithm:- 
                       
             
                   It is the logical sequence of operations described in precise sequence.A algorithm is to be prepared before writing the program . It is mainly written in english language.

example
:- for addition of 2 numbers
1.     start
2.     read a , b
3.     calculate c= a + b ;
4.     display c
5.     stop


PseudoCode:-

             Some statements will be converted into higher level language it is a informal high level description of the operating principal of a operating program or algorithm.

example:-(
 for addition of 2 numbers )

     

1.     start
2.     input 2 numbers
3.     calculate sum
4.     output sum
5.     stop

Actual Application :-


Flowchart:-




Algorithm:-

1.       start
2.     declare integer variables r , ar , cir
3.     accept the value of radius of circle from user
4.     ar =  r * r * 3.14;  
5.     cir = 2 * 3.14 * r;
6.     print the area and circumference of the circle.                 



Program :-

The Flowchart and Algorithm will remain same only program code will differ w.r.t. coding language.
If u have chosen C language here is the code... 
#include<stdio.h>                                                                          
#include<conio.h>
void main()
{
  int r = 0 , ar = 0 , cir = 0 ;  
  clrscr();                               

  printf("\n Enter the radius of circle");
  scanf("%d",& r);                 
  ar =  r*r*3.14;                     
  cir = 2*3.14*r;

printf("\n The area of circle is = %d \n The circumference of circle is = %d ", ar , cir);
getch();

}
 
 
Programs:-

For many other Language Programs of microprocessor 8086, C++ , Data Structures and MSBTE diploma and engineering related concepts visit our  BLOG