Posts

Number System

Image
 Number System  Any number system there is an ordered set of symbols known as digits with rules defined for performing arithmetic operation like addition, multiplication etc. A collection of these digits makes a number which in general has two parts -- integer and fractional, set apart by a radix point(.)                    where N= a number               b=radix or base of the number system               n = number of digits in integer portion               m=number of digits in fractional portion           d n-1 = most significant digit(msd)           d -m =least significant digit(lsd) Types of Number System The four most common number system types are: Decimal number system (Base- 10) Binary number system (Base- 2) Oct...

Array in C++

Image
 Array:   Array in C++ Array is defined as an ordered list of homogeneous data element. May be of type int, float,char or double  All these element are stored in consecutive memory locations An array is described by a single name or an identifier and each element in an array is referenced by a subscript  enclosed  in a pair of square brackets Syntax:               type variable_name[lengthofarry]; Program: Write a program take input and display the element using array in cpp. Code: #include< iostream> using namespace std; int main() { int i,arr[100],no; cout<<"Enter the number of element (less than 100)"; cin>>no; for(i=0;i<no;i++) { cout<<"Enter the element at"<<i <<" place"; cin>>arr[i]; } cout<<"Elemen in the arry is :"; i=0; while(i<no) { cout<<"\n"<<arr[i]; i++; } } Ouput: Enter the number of element (less than 100...

Function in C++

Image
 Function in C++  Function in cpp A   function is a group of statements that together perform a task. Every C++ program has at least one function, which is  main(). we can also say that A function is block of code that performs  specific task. Syntax of function:                            return_type  Function_Name(parameters){                                        code performs that task; } Types of function: There are two type function in C++ 1.Standard Library Functions:  Predefined in C++ 2.User define Function: C++ allows the programmer to define their own function . Program:  Write a program to find out the sum of two number using Function   in C++. Code: #include<iostream> using namespace std;  int sum(int num1,int num2) { i...

While & do while loop in C++

Image
 While in CPP . A  while  loop statement repeatedly executes a target statement as long as a given condition is true .  This is also a loop Structure , but is an enter-controlled one  Syntax: while( condition is true) {  action1; } action 2; Program : Write a program in CPP to count the number of alphabets ,digit and special Symbol                @#$%&)using while loop.  #include<iostream> using namespace std; int main() {           char  str[100];            int i=0 ,digit=0,alphabets=0,special=0,characters=0 ,count=0; cout<<"Enter the string :"; gets(str); cout<<"Enter string is "<<str<<"\n"; while(str[i]!='\0') { count++; i++; } i=0; while(str[i]!='\0') { if(str[i]>='0' && str[i]<='9') { digit++; } if(str[i]=='@' ||str[i]=='#' ||str[i]=='$' ||str[i]=='%'||str[i]=='^'||...

For loop in C++

Image
 For loop: The for is an entery entrolled loop and is used when an action is to be repeated for a predetermined number of times. Similarly When we have  executes same line of statement  repetitively is done by LOOP. Syntax: for(initial value; test; increment)        { action1; } action2; Program: Write a program to print 1 to 10 number using for loop . Code: #include<iostream> using namespace std; int main() { int i; for(i=1;i<=10;i++) { printf("%d\n",i); } } OUTPUT: 1 2 3 4 5 6 7 8 9 10 -------------------------------- Program2Write a Program in C++ to Print all natural numbers upto N without using semi-                                       colon(;) using for loop. Code: #include<iostream> using namespace std; int main() { int i , no; cout<<"Enter the number to print "; cin>>no; for(i=1;i<=...