Wednesday, 25 May 2016

THIS IS REGUARDING THE QUARIES WHICH MAY COME UP

HELLO GUYS THIS BLOG CREATED BY ME IS TO PROVIDE FREE EDUCATION TO ALL THE STUDENTS WHO FEEL THAT COMPUTER SCIENCE IS NOT THEIR CUP OF TEA...

MY AIM IS TO SOLVE YOUR QUARIES AND HELP YOU IN ANY WAY POSSIBLE.

COMMENT YOU DOUBTS YOUR QUARIES OR ANY QUESTION WHICH YOU WANT TO SOLVE OR CLARIFY.....

ASK QUESTIONS DOUBTS QUARIES OR DEMAND ANY ASSISTANCE........I'LL BE THERE FOR YOUR HELP.

A PROGRAM MAY BE CREATED IN MANY DIFFERENT WAYS i.e BY USING CLASS,FUNCTIONS, THROUGH CONSTRUCTORS OR ANY OTHER THING...THEREFORE IF YOU FEEL THAT YOU NEED SOME SORT OF ASSISTANCE BE FREE TO COMMENT IT BELOW....




THANKS.

FIBONACCI SERIES - HSC FAVORITE QUESTION

NOW WHAT IS FIBONACCI SERIES....

0,1,1,2,3,5,8,13........

followed the trend???Noo??

A series of number in which each number is the sum of preceding two numbers is known as Fibonacci series.
This is a very important and the most asked question of HSC.


#include<iostream.h>

#include<conio.h>



void main()

{

clrscr(); \\clears the previous output



int a=0, b=1, n, c;  \\first two numbers of fibonacci series is 0 and 1

cout<<"Enter the number of terms till you want fibonacci series";

cin>>n; \\User choice, till wherever he wants to print the series

cout<<a<<"\t"<<b;



for(int i=1; i<=(n-2);i++)           \\ you must be thinking why (n-2), its because first two terms i.e 0                                                            and 1  are already included

{

cout<<a<<"\t"<<b<<"\t";       \\it'll print 0 and 1 which is first two numbers

c=a+b;                \\now as we go by definition fibonacci series is evaluated by adding the
                                                                                        previous two numbers....here that number is c

cout<<c;

b=c; \\now upgrade the values of variable.... think yourself y

a=b;

}

getch();

}




TRAVERSING IN AN ARRAY- LINEAR SEARCH EXAMPLE

TRAVERSING AN ARRAY SIMPLY MEANS TO GO OVER THE ENTIRE DATA AT LEAST ONCE. SUPPOSE YOU ARE SEARCHING FOR A CHAPTER IN TEXTBOOK.....WHAT YOU DO IS GO TO INDEX AND SEARCH FOR THE CHAPTER.....SUPPOSE YOU FOUND THE CHAPTER AT 5TH ENTRY YOU'LL NOT GO FURTHER.......
HOWEVER THIS ISN'T THE CASE OF TRAVERSING. IN TRAVERSING ALL THE ENTRIES ARE CHECKED EVEN THOUGH YOU DON'T WANT THE REST....
THIS IS HOW THE CONCEPT OF TRAVERSING WORKS...................


NOW A QUICK PROGRAM FOR LINEAR SEARCH A NUMBER.


#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int arr[10]; \\THIS WILL CREATE AN ARRAY VARIABLE 'arr' containing 10 digits in

data type integer

int search;

for(int a=0;a<10;a++) \\for loop for accepting 10 numbers from the user

{

cout<<"Enter the"<<(a+1)<<" numer \t"; \\here (a+1) means 1

cin>>arr[a];

}

cout<<"Enter the number to be searched";

cin>>search;

for(int i=0;i<10;i++)

{

if(arr[i]==search) \\ in c++ == means equals to
{

cout<<"The number is"<<arr[i]<<"found at"<<(i+1)<<"th position";

                    \\here we used (i+1)th position because the index of the array starts from 0

}

else

{

cout<<"The number you are searching is not found";

}

getch();

}

}

USING IF-ELSE-IF Ladder STATEMENT

//THIS PROGRAM ILLUSTRATES THE USE OF IF STATEMENTS IN C++(USEFUL IN HSC)

NOW IF STATEMENT IS A CONDITIONAL STATEMENT IN C++ i.e WHERE YOU WANT TO MAKE ANY CHOICE IN RUN TIME(i.e DURING EXECUTION OF PROGRAM).

LETS SEE AN EASY EXAMPLE TO COMPARE THREE NUMBER ENTERED BY THE USER. FINDING OUT WHICH ONE IS LARGEST AMONG THEM


#include<iostream.h>

#include<conio.h>

 void main()

{

clrscr();

int a,b,c;                      \\this is variable declartion

cout<<"Enter three numbers";     \\Print the content as it is on output screen

cin>>a;

cin>>b;

cin>>c;              \\you can also take input in one step as cin>>a>>b>>c;



if(a>b && a>c)       \\if statement... Now here we have 2 condition to check i.e

                       \\ a>b and a>c. In c++ and is written as two emphasand symbol.

{

cout<<a<<"Is the largest number"; \\be clever and think like a programmer

}

else if(b>a && b>c)

{

cout<<b<<"Is the largest number";

}

else

{

cout<<c<<"Is the largest number";

}

getch();

}

PROGRAM ON ARRAY

\\An array is a set of similar data types having contagious memory location.


#include<iostream.h>

#include<conio.h>

void main()

{

clrscr(); \\To clear previous output

int arr[10]; \\declaration of array of data type int

int a,sum=0;

cout<<"Enter 10 numbers to print the sum";


for(a=0;a<10;a++)

{

cin>>arr[a];

sum=sum+arr[a];

}

cout<<sum;

getch();


}



PROGRAM ON FOR LOOP

#include<iostream.h>

#include<conio.h>

void main()

        {


clrscr();   \\this will clear the previous output generated

int a; \\this is called as variable declaration

int sum = 0; \\this is variable  initialization

for(a=0 ; a<=10; a++) \\the general syntax of for loop is for(variable intialization; condition;                                                    increment/decrement operator)

{

sum=sum+a;

}

cout<<sum; \\this will print the value of variable sum

getch();

}

PROGRAM TO SWAP NUMBERS

#include<iostream.h>

#include<conio.h>


void main()

{

clrscr();                        \\this will clear the previous output generated

int a,b;                           \\ this is know as variable declaration. 'int' is a data type(a keyword)

int c;                                               \\another variable declaration

cout<<"Enter the value of a";   \\this command will generate the message as it is on the screen

cin>>a;         \\this is taking input from the user

cout<<"Enter the value of b"; \\this command will generate the message as it is on the screen

cin>>b;          \\this is taking input from the user



cout<<"The entered value of a and b is";

cout<<a<<"\t"<<b;                          

c=b;                                                  \\we introduced a variable 'c' to copy contents of b to c

b=a;                                                    then a to b......now value of a is transferred to b

a=c;                                                   then again c to a(c contains value of b)

                                                        \\ in short we used another variable (c) to exchange contens.

cout<<"The new value after swap is ";

cout<<a<<"\t"<<b;

getch();                                              

}

C++ : MY FIRST PROGRAM (Basics)

#include<iostream.h>

#include<conio.h>


void main()

{

clrscr();

cout<<"Hello There! This is my first Program";

getch();


}




This is the most basic program which will print a simple output that you entered through the text within the program...