0% found this document useful (0 votes)
39 views7 pages

#Include #Include #Include Using Namespace Void Int For Int

The document contains 4 C++ programs that demonstrate: 1) Storing and displaying user input ages using arrays 2) Calculating the sum and average of sales figures input over 10 days using arrays 3) Storing and displaying a user-input string using character arrays 4) Implementing a sequential search on an integer array to find a user-input number

Uploaded by

wajid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views7 pages

#Include #Include #Include Using Namespace Void Int For Int

The document contains 4 C++ programs that demonstrate: 1) Storing and displaying user input ages using arrays 2) Calculating the sum and average of sales figures input over 10 days using arrays 3) Storing and displaying a user-input string using character arrays 4) Implementing a sequential search on an integer array to find a user-input number

Uploaded by

wajid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

#include <iostream>

#include <conio.h>
#include <iomanip>

using namespace std;

void main()
{
int age[4];
for(int i=0;i<4;i++)
{
cout<<"your the age: ";
cin>>age[i];
}
cout<<"Displaying Data: "<<endl;
for(int j=0; j<4; j++)
{
cout<<"your entered: "<<age[j]<<endl;
}

getch();
}
#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

void main()
{
double sales[10];
int i;
double sum=0;
double average;

cout<<"Enter your sale for 10 days: "<<endl;


for(i=0;i<10;i++)
{
cin>>sales[i];
}
cout<<endl;

cout<<"your sale for 10 days: "<<endl;


for(i=0;i<10;i++)
{
cout<<sales[i]<<endl;
}
cout<<endl;
// calculating sum

for(i=0;i<10;i++)
{
sum=sum+sales[i];
}
average=sum/10;
cout<<endl;
cout<<"The sum of sale is: "<<sum<<endl;
cout<<"The average sale is: "<<average<<endl;
getch();
}

#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

void main()
{
char str[80]; //character array
cout<<"Enter character: "<<endl;
cin.get(str,80);
cout<<"You entered: "<<str<<endl;
getch();
}
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <string>
using namespace std;

int seqSearch(int list[],int length,int searchItem)


{
int loc;
bool found=false;
for(loc=0;loc<length;loc++)
if(list[loc]==searchItem)
{
found=true;
break;

}
if (found)

return loc;

else

return -1;
}
void main()
{
int list[5];
int number,index;
for(index=0;index<5;index++)
{
cout<<"Enter an array of 5 integer: "<<endl;
cin>>list[index];
}
cout<<"Enter number to be Searched: "<<endl;
cin>>number;
cout<<endl;

int location;
location=seqSearch(list,5,number);

if(location!=-1)
cout<<"The Number is found at position: "<<location<<endl;
else
cout<<"The number is not found in the list: "<<endl;
getch();
}

LAB TASKS
Q1
#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

void main()
{
int i , j ;
int product [10][10];

for(i = 1 ; i < 10 ; i++)


for(j = 1 ; j < 10 ; j++)
product[i][j] = i*j;

for(i = 1 ; i < 10 ; i++)


{
for(j = 1 ; j < 10 ; j++)
cout << product[i][j] <<" \t";
cout << endl;
}

getch();
}

Q2:
#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

void main()
{
int list[5];
int sum = 0 , average , large = 0;

cout<<"Enter the five numbers "<<endl;


for (int i = 0 ; i < 5 ; i++)
{
cin>>list[i];
}
cout<<endl;
cout<<"print five number "<<endl;
for (int i = 0 ; i < 5 ; i++)
{
cout<<list[i]<<endl;
}
cout<<endl;
cout<<"largest number is= "<<endl;
for (int i = 0 ; i < 5 ; i++)
{
if (large < list[i])
large = list[i];

}
cout<<large<<endl;
cout<<"Enter the sum "<<endl;
for (int i = 0 ; i < 5 ; i++)
{
sum = sum + list[i];
}
cout<<sum<<endl;
cout<<"average is "<<endl;
average = sum / 5;
cout<<average<<endl;

cout<<"print number in reverse "<<endl;

for (int i = 4 ; i >= 0 ; i--)


{
cout << list[i];
}
getch();
}

You might also like