Professional Documents
Culture Documents
Programs
Contents
1.Program to print the largest and smallest no. from the array given by user .......................................... 2
2.Program to print the average and total sales of month taken from user through array........................ 3
3.Program to print the sum of 2 array taken from the user........................................................................ 4
4.Program to reverse the string enter by the user. ..................................................................................... 6
6.Program to print the cube of the no. enter ed by user ............................................................................. 8
7.Program to illustrate the call by value method of function invoking....................................................... 9
8.Program to print the square of no. given by the user ............................................................................. 10
9.Program to swap two values ................................................................................................................... 11
10.Program to take roll no. and name and from the user using the structure. ........................................ 12
11. Program to print member type of a gym member................................................................................ 13
12.Program to take feet and inches from the user and find the total. ...................................................... 14
13.Program to search an element in the array entered by the user. ........................................................ 15
14.Simple program of structure. ................................................................................................................ 16
15.Program to take name and type of the movie from the user and his and check that he is eligible for
the movie..................................................................................................................................................... 18
Program to print the largest and smallest number of the array given by user.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int v[50],large,small;
int i,n;
cout<<"Enter how many elements ? \n";
cin>>n;
cout<<"Enter values in the vector \n";
for(i=0;i<n;i++)
cin>>v[i];
large=v[1];
small=v[1];
for(i=0;i<n;i++)
{
if(v[i]<large)
large =v[i];
else if(v[i]<small)
small=v[i];
}
cout<<"\nLargest Element ="<<large ;
cout<<"\nSmallest Element ="<<small ;
}
Output:
Program to print the average and total sales of month taken from user through
array
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
const int size=3 ;
float sales[size],avg=0,total=0 ;
for(int i=0;i<size;i++)
{
cout<<"enter sales made on day"<<i+1<<":";
cin>>sales[i];
total+=sales[i];
}
avg=total/size;
cout<<"\n Total sales ="<<total<<"\n";
cout<<"Average sales ="<<avg<<"\n";
return 0;
}
Output:
5
{
for(int j=0;j<=3;j++)
{
cout<<sum[i][j];
}
}
getch();
}
Output:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
void main()
{
clrscr();
char str[80];
int i :
cout<<"\n Enter any string (max 80 chars) :";
gets(str);
str[0]=toupper(str[0]);
for(i=0;str[i]!='\0';i++)
if(str[i]=='')
str[i+1]=toupper(str[i+1]);
cout<<"\nUpdated string is:"<<str;
getch();
}
Output:
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
float cube(float);
float x, y;
cout<<"\n Enter number whose cube is to be calculated : \n";
cin>>x;
y=cube(x);
cout<<"\n The cube of "<<x<<"is "<<y<<"\n";
getch();
return 0;
}
float cube(float a)
{
float n;
n=a*a*a;
return(n);
}
Output:
10
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
float sqaure(float);
float x, y;
cout<<"\n Enter number whose sqaure is to be calculated : \n";
cin>>x;
y=sqaure(x);
cout<<"\n The sqaure of "<<x<<"is "<<y<<"\n";
getch();
return 0;
}
float sqaure(float a)
{
float n;
n=a*a;
return(n);
}
Output:
11
12
Program to take roll no. and name and from the user using the structure.
#include<iostream.h>
#include<conio.h>
struct student
{
float m1, m2, m3, total, per;
int roll;
char name[10];
};
void main( )
{
student st;
cout<<"Enter name: ";
cin>>st.name;
cout<<"Enter roll number: ";
cin>>st.roll;
cout<<"Enter marks of 3 subjects: ";
cin>>st.m1>>st.m2>>st.m3;
st.total=st.m1+st.m2+st.m3;
st.per=st.total/3;
cout<<"Total: "<<st.total;
cout<<"Percentage is: "<<st.per;
getch( );
}
Output:
13
14
Program to take feet and inches from the user and find the total.
#include<iostream.h>
#include<conio.h>
struct distance
{
int feet;
int inches;
};
int main()
{
clrscr();
Distance length1,lenght2;
distance l3;
l3.feet=l1.feet+l2.feet+(l1.inches+l2.inches)/12;
l3.inches=(l1.inches+l2.inches)%12;
cout<<\n \n Total Inches :<<l3.inches;
return ;
}
Output:
15
16
getch();
}
}
Output:
17
int X,Y;
};
void main (Point P)
{
cout<< P.X<<':'<<P.Y<<endl;
}
void main()
{
Point U={20,10},V,W;
V=U;
V.X+=20;
W=V;
U.Y+=10;
U.X+=5;
W.X-=5;
Show (U);
Show (V);
Show (W);
}
Output:
18
Program to take name and type of the movie from the user and his and check that
he is eligible for the movie.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
struct movie
{
char movie_name[20];
char movie_type;
int ticket_cost;
int age;
} MOVIE;
char a,u;
MOVIE.ticket_cost=100;
cout<<"Enter the name of movie";
gets(MOVIE.movie_name);
cout<<"Enter the Type of Movie (u/a):";
cin>>MOVIE.movie_type;
cout<<"Enter Your Age :";
cin>>MOVIE.age;
if (MOVIE.movie_type==a)
cout<<"This movie is adult.";
else if (MOVIE.age<18)
cout<<"The movie is not for you.";
else if (MOVIE.age>18)
cout<<"The movie is for you.";
19
else
cout<<"Enjoy!";
if(MOVIE.movie_type==u)
cout<<you can watch this movie;
else
cout<<Enjoy!!!;
}
Output: