C++

C++ Program – CheckSum generator

May 11, 2011

//Downloaded From theonlinetutorials.com //Source code #include<iostream.h> #include<stdio.h> #include<string.h> #include<conio.h> #define size 100 unsigned short int checksum(char []); void valch(unsigned short int check,char message[]); int main(){ clrscr(); cout<<” Enter any thing :”; char message[size]={0}; cin>>message; unsigned short int check=checksum(message); getch(); valch(check,message); getch(); return 0; } void valch(unsigned short int check,char message[]){ unsigned short int t[size],ch=0; int [...]

Read the full article →

C++ Program – Remove duplication of the word

May 11, 2011

//Downloaded From theonlinetutorials.com //Source code #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> void dop(char s[]) { char a[100],b[100]; a[0]=NULL; b[0]=NULL; int flag=0,sa=0; for(int i=0;i<=strlen(s);i++) { if(s[i]==’ ‘||s[i]==NULL) { b[sa]=’ ‘; sa++; b[sa]=NULL; flag=1; } else { b[sa]=s[i]; sa++; } if(flag==1) { if(strcmp(a,b)==0) { for(int j=(i-sa);j<=strlen(s);j++) { s[j]=s[j+sa]; } i=i-sa; } flag=0; sa=0; strcpy(a,b); } } } int main() [...]

Read the full article →

C++ Program – Display Fun Stars

May 11, 2011

//Downloaded From theonlinetutorials.com //Source code #include<iostream.h> #include<conio.h> int main() { int n,i,j; cout<<”Enter an integer value below 200 :”; cin>>n; for(i=0;i<n;i++) { for( j=0;j<i;j++) cout<<” “; cout<<”*”; for( j=1;j<=2*(n-i)-1;j++) { cout<<” “; } cout<<”*”; cout<<endl; } for(j=0;j<i;j++) cout<<” “; cout<<”*”<<endl; for(i=n-1;i>=0;i–) { for( j=0;j<i;j++) cout<<” “; cout<<”*”; for( j=1;j<=2*(n-i)-1;j++) { cout<<” “; } cout<<”*”; cout<<endl; [...]

Read the full article →

C++ Program – Find the 2 largest number from the given set of numbers

May 9, 2011

//Downloaded From theonlinetutorials.com #include<iostream.h> #include<conio.h> int main() { int a[1000],n,max,max1; cout<<”How many no you will input”<<endl; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; } //Escape When two input are not avaliable if(n<=1) { cout<<”Maximu two No are”<<endl; for(int i=0;i<n;i++) { cout<<a[n]<<endl; } return 0; } //store maximu value between a[0] and a[1] max=a[0]>a[1]?a[0]:a[1]; max1=a[0]<a[1]?a[0]:a[1]; for(i=2;i<n;i++) { if(a[i]>max1) [...]

Read the full article →

C++ Program – Matrix Multiplication

May 9, 2011

//Downloaded From theonlinetutorials.com #include<iostream.h> #include<conio.h> #define size 100 void dis(int *a,int r1,int c1) { for(int i=0;i<r1;i++) { for(int j=0;j<c1;j++) { cout<<*(a+i*size+j)<<”\t”; } cout<<endl; } } void getd(int *a,int *r1,int *c1) { cout<<”Enter no of row”; cin>>*r1; cout<<”Enter no of col”; cin>>*c1; cout<<”Now enter the data”; for(int i=0;i<*r1;i++) { for(int j=0;j<*c1;j++) { cin>>*(a+i*size+j); } cout<<endl; } [...]

Read the full article →

Nesting of loops in C++

May 7, 2011

When a loop is written inside other loop, then the representation is know as the nesting of looping constructs. In this representation,the child loop is executed fully and then the control is transferred to its parent loop for the next repetition. Example program: #include<iostream.h> #include<conio.h> void main() { char ans=’y’; int x=1,y; while(ans!=’n’||ans!=’N’) { count<<”Enter [...]

Read the full article →

For loop in C++

May 7, 2011

A for loop is said to be very handy and is used very often inside a program. Because it is easy to represent and debug for errors. This loop is used when we know the number of repetitions. Syntax: for(<initialization>;<condition>;<increment/decrement>) { Statements; . . } /*————————————————————*/ //To display odd values between 1 and 10 #include<iostream.h> [...]

Read the full article →

While loop in C++

May 7, 2011

This loop is exactly the reverse of the do…while loop. It checks for the condition at the beginning and later executes the given set of statements. Hence there might not be at leastone chance that the statements ate executed. Syntax: While(condition) { statements; . . } Example program: //To display even values between 1 and [...]

Read the full article →

Do…while loop in C++

May 7, 2011

A do…while loop is used when the statements are to be executed at the beginning and later the condition to be checked. Hence there is at least one chance that the given statements are executed. Syntax: do { statements; . . } while(condition); Example program //To print natural numbers from 1 – 10 #include<iostream.h> #include<conio.h> [...]

Read the full article →

C++ Program – Vowel checking

May 7, 2011

//Downloaded From theonlinetutorials.com #include<iostream.h> #include<conio.h> void main() { char ch; cout<<”Enter a character value” ; cin>>ch; switch(ch) { case ‘a’: case ‘e’: case ‘i’: case ‘o’: case ‘u’: { cout<<”Vowel”; break; } default: cout<<”Not a vowel”; } getch(); } Output:1 Enter a character : i Vowel Output:2 Enter a character : h Not a vowel

Read the full article →

Swith….Case Statements in C++

May 7, 2011

The switch…case construct provides a better way of representing the conditions, as it reduces the complexity in code and easier to debug and understand. Syntax: Switch(<Variable>) { case<Variable1>; { Statements; break; } case<Value2>; { Statements; break; } . . default: { Statements; } } /*———————————————————————-*/ #include<iostream.h> #include<conio.h> void main() { char vowel; cout<<”Enter a charactor [...]

Read the full article →

Nested If …Else Statements in C++

May 7, 2011

If an if…else is specified within another if or else construct, then the structure is said to be nested if…..else construct. Syntax: if (condition) { Statements; . . if(condition) { statements; . . } else { statements; . . } . . } else { Statements; . . } /*—————————————————————-*/ #include<iostream.h> #include<conio.h> void main() { [...]

Read the full article →

Nested if statements in C++

May 7, 2011

Often it becomes a necessity to specify conditions within conditions, in order to execute a set of statements. In such situations, we can make use of the nested if constructs. These constructs are specified one inside the other. Syntax: if (condition) { Statements; . . if (condition) { Statements; . . } . . } [...]

Read the full article →

if……else statements in C++

May 7, 2011

In the if ….else construct, two block of statements are specified, one for the if and the other for the else part. The block of statements in the if are executed if the condition specified results are true. The block present in the else part will be executed, if the specified condition in the if [...]

Read the full article →

C++ program – To check whether x is greather than y (IF statement)

May 7, 2011

//Downloaded From theonlinetutorials.com #include<iostream.h> #include<conio.h> void main() { int x,y; cout<<” Enter values for x and y: “; cin>>x>>y; if (x>y) cout<<”x is big”; if (y>x) cout<<”y is big”; getch(); } Output Enter values for X and y : 10 20 y is big Enter values for x and y : 20 10 x is [...]

Read the full article →

Simple IF statement in C++

May 7, 2011

The simple if statements execute the given block of statements, if the specified conditions become true. This can be given a diagrammatical form as follows:   C++ Syntax: if(<condition>) { Statements; . . . } Example: If (a>b)     //Check if value in a is big { . . } If (a==b)   //Check if value in [...]

Related Posts Plugin for WordPress, Blogger...
Read the full article →