So hello to all, I'll write a few elementary codes for beginners,to provide a basic insight of C++ , this blog post will see additions from time to time ,so stay tuned.
Current Number Of Codes In Blog : 8
To jump to the code you need press "Ctrl + G" and type heading or use the navbar.
------------------------------------------------------------------------------------------------------
ABC Section
To Show Average of Five Entries
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,c,d,e,f; //Here float is used to include numbers with decimal points
cout<<"Enter Values":
cin>>a>>b>>c>>d>>e;
f=a+b+c+d+e/5;
cout<<"Average Marks is";
cout<<f;
getch();
}
------------------------------------------------------------------------------------------------------------
To Find ASCII Code for the given character
Note: Almost all characters on your keyboard have a ASCII code in C++ ranging from 0 to 265. >Eg 'A' has ASCII code 65
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr()
char n;
int x;
cout<<"Enter a character";
cin>>n;
x=n;
cout<<"ASCII Code is "<<x;
getch()
}
---------------------------------------------------------------------------------------------------
Largest Among Four Numbers Entered
Note- An improvement of this code is in the loop section
void main()
{
clrscr();
int a,b,c,d,e=0,f=0;
cout<<"Enter 4 numbers";
cin>>a>>b>>c>>d;
if (a>e)
e=a;
if (b>e)
e=b;
if (c>e)
e=c;
if (d>e)
e=d;
cout<<"Largest Number Is"<<e;
if((a!=e)&&(a>f))
f=a;
if((b!=e)&&(b>f))
f=b;
if((c!=e)&&(c>f))
f=c;
if((d!=e)&&(d>f))
f=d;
cout<<"2nd Largest Number Is"<<f;
getch();
}
----------------------------------------------------------------------------------------------------
Loop-A-Loop Section
Fibonacci Series Till N Numbers
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b=1,c,n;
cin<<n; //For The Range
cout<<a<<"\n"<<b<<"\n";
do
{ //You can also use 'for' loop
c=a+b;
a=b;
b=c;
cout<<c<<"\n";
} while(c<n);
getch();
}
-----------------------------------------------------------------------------------------------------
To Reverse The Digits Of A Number
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c=0;
cin>>a; //The Digit We Want To Reverse
do
{ b=a%10;
a=a/10;
c=c*10+b;
} while(a!=0);
cout<<c;
getch();
}
-------------------------------------------------------------------------------------------------
HCF Among Two Numbers
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,r,k,x;
cin>>a>>b;
if(a>b)
{
k=b;
}
else
{
k=a;
}
for(r=1;r<=k;r++)
{
if((a%r==0)&&(b%r==0))
x=r;
}
cout<<"HCF"<<x;
getch();
}
--------------------------------------------------------------------------------------------------
Largest Even And Odd Numbers Among The Numbers Entered
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b=0,c=1;
cout<<"Enter Number"<<"\t"; //Observers may note that this code is for positive numbers
cout<<"0 ends the program";
do
{
cin>>a;
if(a%2==0)
{
if (a>b)
b=a;
}
else
if(a>c)
c=a;
} while(a!=0);
cout<<"Largest Even Number"<<b;
cout<<"Largest Odd Number"<<c;
getch();
}
Current Number Of Codes In Blog : 8
To jump to the code you need press "Ctrl + G" and type heading or use the navbar.
------------------------------------------------------------------------------------------------------
ABC Section
To Show Average of Five Entries
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,c,d,e,f; //Here float is used to include numbers with decimal points
cout<<"Enter Values":
cin>>a>>b>>c>>d>>e;
f=a+b+c+d+e/5;
cout<<"Average Marks is";
cout<<f;
getch();
}
------------------------------------------------------------------------------------------------------------
To Find ASCII Code for the given character
Note: Almost all characters on your keyboard have a ASCII code in C++ ranging from 0 to 265. >Eg 'A' has ASCII code 65
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr()
char n;
int x;
cout<<"Enter a character";
cin>>n;
x=n;
cout<<"ASCII Code is "<<x;
getch()
}
---------------------------------------------------------------------------------------------------
Largest Among Four Numbers Entered
Note- An improvement of this code is in the loop section
void main()
{
clrscr();
int a,b,c,d,e=0,f=0;
cout<<"Enter 4 numbers";
cin>>a>>b>>c>>d;
if (a>e)
e=a;
if (b>e)
e=b;
if (c>e)
e=c;
if (d>e)
e=d;
cout<<"Largest Number Is"<<e;
if((a!=e)&&(a>f))
f=a;
if((b!=e)&&(b>f))
f=b;
if((c!=e)&&(c>f))
f=c;
if((d!=e)&&(d>f))
f=d;
cout<<"2nd Largest Number Is"<<f;
getch();
}
----------------------------------------------------------------------------------------------------
Loop-A-Loop Section
Fibonacci Series Till N Numbers
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b=1,c,n;
cin<<n; //For The Range
cout<<a<<"\n"<<b<<"\n";
do
{ //You can also use 'for' loop
c=a+b;
a=b;
b=c;
cout<<c<<"\n";
} while(c<n);
getch();
}
-----------------------------------------------------------------------------------------------------
To Reverse The Digits Of A Number
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c=0;
cin>>a; //The Digit We Want To Reverse
do
{ b=a%10;
a=a/10;
c=c*10+b;
} while(a!=0);
cout<<c;
getch();
}
-------------------------------------------------------------------------------------------------
HCF Among Two Numbers
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,r,k,x;
cin>>a>>b;
if(a>b)
{
k=b;
}
else
{
k=a;
}
for(r=1;r<=k;r++)
{
if((a%r==0)&&(b%r==0))
x=r;
}
cout<<"HCF"<<x;
getch();
}
--------------------------------------------------------------------------------------------------
Largest Even And Odd Numbers Among The Numbers Entered
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b=0,c=1;
cout<<"Enter Number"<<"\t"; //Observers may note that this code is for positive numbers
cout<<"0 ends the program";
do
{
cin>>a;
if(a%2==0)
{
if (a>b)
b=a;
}
else
if(a>c)
c=a;
} while(a!=0);
cout<<"Largest Even Number"<<b;
cout<<"Largest Odd Number"<<c;
getch();
}