Icp Assignment#4 Wasim

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

INTRO TO

COMPUTER
PROGRAMMING
COURCE CODE#CSC102

ASSIGNMENT#4
SUBMITTED TO: SIR NASIR MEHDI

SUBMITTED BY: WASEEM AKRAM


Roll No# SP19-MCS-029
INTRO TO COMPUTER PROGRAMMING

Q.NO 1
#include <iostream>

using namespace std;

int main()

double alpha[50],sqr,cube;

int i,j,d;

for (i = 0; i < 25; i++)

alpha[i] = i * i;

sqr+=alpha[i];

for (d = 25; d < 50; d++)

alpha[d] = d * d * d;

cube+=alpha[d];

}
INTRO TO COMPUTER PROGRAMMING
int a=0;

for (i = 0; i < 5; i++)

for (j = 0; j < 10; j++)

cout << alpha[a] << " ";

a++;

cout << endl;

cout << endl;

cout << "The square of the first 25 numbers is: " << sqr << endl;

cout << "The triple of the last 25 numbers is: " << cube << endl;

system("pause");

return 0;

Q.NO2
#include <iostream>

using namespace std;


INTRO TO COMPUTER PROGRAMMING

int main()

float avg;

string name[100];

int marks[100],i,sum=0,n;

cout<<"Enter the number of students you have to enter the name and
mark\n";

cin>>n;

for(i=0;i<=n;i++)

cout<<"Enter the name of "<<i+1<< " student :";

cin>>name[i];

cout<<"Enter the marks of "<<i+1<< " student :";

cin>>marks[i];

sum+=marks[i];

avg=sum/n;

cout<<"Average of class ="<<avg<<endl;

cout<<"\nName and marks of all the students whose test scores are below the
class average\n";

for(i=0;i<=n;i++)
INTRO TO COMPUTER PROGRAMMING
{

if(marks[i]<avg)

cout<<name[i]<<" "<<marks[i]<<endl;

cout<<"Name and marks of all the students having the highest score class
Average\n";

for(i=0;i<=n;i++)

if(marks[i]>avg)

cout<<name[i]<<" "<<marks[i]<<endl;

Q.NO3
#include <iostream>

using namespace std;

void AddArrays(int a1[],int a2[],int a3[]);


INTRO TO COMPUTER PROGRAMMING
int main()

int i,arr1[100],arr2[100],arr3[100],n1,n2;

AddArrays(arr1,arr2,arr3);

void AddArrays(int a1[],int a2[],int a3[])

int a,i,n1,n2,n3;

cout<<"Enter the length of 1st arry :";

cin>>n1;

cout<<"Enter the value in 1st arry \n";

for(i=0;i<n1;i++)

cout<<"Enter "<<i+1<<" arry value :";

cin>>a1[i];

cout<<"Enter the length of 2nd arry :";

cin>>n2;

cout<<"Enter the value in 2nd arry \n";


INTRO TO COMPUTER PROGRAMMING
for(i=0;i<n2;i++)

cout<<"Enter "<<i+1<<" arry value :";

cin>>a2[i];

for(i=0;i<n1;i++)

a3[i]=a1[i];

for(a=1;a<n2;a++,i++)

a3[i]=a2[a];

n3=n1+n2;

cout<<"Value of third arry \n";

for(i=0;i<n3;i++)

cout<<i+1<<"Value "<<a3[i]<<"\n";

}
INTRO TO COMPUTER PROGRAMMING
Q.NO4
#include <iostream>

using namespace std;

int main()

int ar[3][7],row,col,sum,t=0,least,greatest,avrg[7],avg;

for(row=0;row<3;row++)

cout<<"\nEnter the data of "<<row+1<<" Monkey \n";

for(col=0;col<7;col++)

cout<<col+1<<" day enter food of pounds";

cin>>ar[row][col];

for(row=0;row<3;row++,t++)

for(col=0;col<7;col++)

{
INTRO TO COMPUTER PROGRAMMING
sum+=ar[row][col];

avg=sum/7;

avrg[t]=avg;

least=greatest=avrg[0];

for(int i=0;i<7;i++)

if(least>avrg[i])

least=avrg[i];

if(greatest<avrg[i])

greatest=avrg[i];

cout<<"\nAverage amount of food eaten per day by the whole family of


monkeys\n";

for(int i=0;i<7;i++)

cout<<i+1<<" day averg food="<<avrg[i]<<"\n";

cout<<"\nThe least amount of food eaten during the week by any one
monkey = "<<least;
INTRO TO COMPUTER PROGRAMMING
cout<<"\nThe greatest amount of food eaten during the week by any one
monkey ="<<greatest;

Q.NO5
#include <iostream>

using namespace std;

int arr[100];

int maxint(int ar[],int n)

int i;

int max=ar[0],index=-1;

for(i=0;i<n;i++)

if(max<ar[i])

index=i;

return index;

int main()
INTRO TO COMPUTER PROGRAMMING
{

int i,n,mx;

cout<<"Enter the size of array:";

cin>>n;

cout<<"\nEnter the value of array\n";

for(i=0;i<n;i++)

cout<<i+1<<" value enter :";

cin>>arr[i];

mx=maxint(arr,n);

cout<<"\nMaximum value = "<<arr[mx]<<" on index = "<<mx<<endl;