#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x[50],i,n,sum=0;
float avg;
cout<<"value of n=";
cin>>n;
cout<<"enter the elements:";
for(i=0;i<n;i++)
{
cin>>x[i];
}
for(i=0;i<n;i++)
{
cout<<"x["<<i<<"]="<<x[i]<<endl;
sum=sum+x[i];
}
cout<<"avg=";
avg=sum/n;
cout<<avg;
getch();
}
- Upinder Singh Dhami
- Bangalore, Karnataka, India
- Extending one hand to help someone has more value rather than joining two hands for prayer
average of n numbers
Tuesday, September 1, 2009Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
calulate gain in amount by adding 11 % interst per year within 10 years
#include<stdio.h>
#include<conio.h>
#define interest 11
#define period 10
void main()
{
clrscr();
float amount=5000;
int duration=0;
while(duration<=period)
{
printf("%2d %8.2f\n",duration,amount);
amount=amount+amount*interest/100;
duration++;
}
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
evalute z+z*z/2 +z*z*z/3 +z*z*z*z/4
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float x,y,z;
clrscr();
cout<<"enter the value of x ";
cin>>x;
z=x/(x+1);
y=z+pow(z,2)/2+pow(z,3)/3+pow(z,4)/4;
cout<<"value of y=";
cout<<y;
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
range of integer value
#include<iostream.h>
#include<conio.h>
#include<limits.h>
void main()
{
clrscr();
cout<<"minimum value of int="<<INT_MIN<<"\n";
cout<<"maximum value of int="<<INT_MAX<<"\n";
cout<<"maximum value of unsigned int="<<UINT_MAX<<"\n";
cout<<"maximum value of long int="<<LONG_MAX<<"\n";
cout<<"minimum value of long int="<<LONG_MIN<<"\n";
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
how to use recursion
#include<iostream.h>
#include<conio.h>
void f(int);
void main()
{
clrscr();
f(5);
getch();
}
void f(int x)
{ cout<<"hello"<<'\t';
if(x>0)
f(x-1);
cout<<"world"<<'\t';
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
input, output two dimensional array
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x[10][10],m,n;
cout<<"number of rows and colomns:"<<endl;
cin>>m>>n;
cout<<"enter the elements";
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)//if we put braces here then int j is defined
// in another line otherwise not
cin>>x[i][j];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<x[i][j]<<"\t";
cout<<endl;
}
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
importance of getche()
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char z;
z=getche();
cout<<z;
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
importance of getchar()
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char xy;
xy=getchar();
cout<<xy;
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
importance of getch() & clrscr()
#include<iostream.h>
#include<conio.h>
void main()
{
cout<<"1"<<endl;
getch();
clrscr();
cout<<"2"<<endl;
getch();
clrscr();
cout<<"3"<<endl;
getch();
clrscr();
cout<<"4";
getch();
clrscr();
cout<<"5"<<endl;
getch();
clrscr();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
print a heart
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" * * * * "<<endl;
cout<<" * * * * "<<endl;
cout<<" * * * * "<<endl;
cout<<" * * * "<<endl;
cout<<" * * "<<endl;
cout<<" * * "<<endl;
cout<<" * * "<<endl;
cout<<" * * "<<endl;
cout<<" * * "<<endl;
cout<<" * * "<<endl;
cout<<" * * "<<endl;
cout<<" * * "<<endl;
cout<<" * * "<<endl;
cout<<" * "<<endl;
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
print a car
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" ^ "<<endl;
cout<<" (*) "<<endl;
cout<<" /^\\ "<<endl;
cout<<" /~~~\\ "<<endl;
cout<<" /-----\\"<<endl;
cout<<" |DHAMI| "<<endl;
cout<<" | CAR | "<<endl;
cout<<" ----- "<<endl;
cout<<"() ()"<<endl;
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
fundamentals of signed and unsigned numbers
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i=32000;
cout<<i<<endl;
i=40000;
cout<<i<<endl;
signed k=40000;
cout<<k<<endl;
unsigned j=40000;
cout<<j<<endl;
float l=50000;
cout<<l<<endl;
l=555.57;
cout<<l<<endl;
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs
sum of two numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,sum;
clrscr;
cout<<"enter the value of a";
cin>>a;
cout<<"enter the value of b";
cin>>b;
sum=a+b;
cout<<"sum=";
cout<<sum;
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: basic programs