0% found this document useful (0 votes)
9 views

Lab Task PF

Uploaded by

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

Lab Task PF

Uploaded by

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

Lab Task:

subjecT: Programming FundamenTaL


name: abduLLah sajid, hassan amir
submiTTed To: ma’am isra naz

Question 1:
Code Source:
#include <iostream>
using namespace std;
int main() {
int roll_number[5], marks[5], i, max;
for (i = 0; i < 5; i++) {
cout << "Enter Your Roll Number: ";
cin >> roll_number[i];
}
for (i = 0; i < 5; i++) {
cout << "Enter Your Marks: ";
cin >> marks[i];
}
max = 0;
for (i = 1; i < 5; i++) {
if (marks[i] > marks[max]) {
max = i;
}
}
cout << "Roll Number: " << roll_number[max] << endl;
cout << "Highest Marks: " << marks[max] << endl;
return 0;
}
Output
Question 2:
Code Source:
#include <iostream>
using namespace std;
int main() {
int arr[5],i;
for(i=0; i<=4; i++) {
cout<<"Enter number: ";
cin>>arr[i];
}
for(i=0; i<=4; i++) {
if(arr[i]%2==0) {
cout<<"The Number "<< arr[i]<<" is Even" <<endl;
} else {
cout<<"The Number "<< arr[i] <<" is Odd" <<endl;
}
}
return 0;
}
Output:
Question 2:
Code Source:
#include <iostream>
using namespace std;
int main() {
int arr[5], i, sum = 0;
float avg = 0.0;
for(int i = 0; i < 5; i++) {
cout << "Enter number: ";
cin >> arr[i];
sum = sum + arr[i];
}
cout << "Sum = " << sum << endl;
avg = sum / 5.0;
cout << "Average = " << avg << endl;
return 0;
}
Output:

Question 3:
Code Source:
#include <iostream>
using namespace std;
int main() {
int arr[5], i;
for(i = 0; i < 5; i++) {
cout << "Enter Marks: ";
cin >> arr[i];
}
cout << "Entered Marks: ";
for(i = 0; i < 5; i++) {
cout << arr[i] << " ";
}
cout << arr[i]<<endl;
return 0;
}
Output:

Question 4:
Code source:
#include <iostream>
using namespace std;
int main() {
char name[20], address[30];
cout << "Enter Your Name: ";
cin >> name;
cout << "Enter Your Address: ";
cin.ignore();
cin.getline(address, 30);
cout << "Name is: " << name << endl;
cout << "Address is: " << address << endl;
return 0;
}
Output:

Question 5:
Code source:
&
Output:

You might also like