0% found this document useful (0 votes)
4 views14 pages

PF Lab Task 4..............

The document contains a series of programming assignments submitted by a student named Khadija for the Programming Fundamentals lab. Each program is written in C++ and demonstrates various programming concepts such as loops, conditionals, and switch statements. The programs cover tasks like determining even/odd numbers, basic arithmetic operations, identifying prime numbers, and calculating factorials.

Uploaded by

mirzagbaig654
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)
4 views14 pages

PF Lab Task 4..............

The document contains a series of programming assignments submitted by a student named Khadija for the Programming Fundamentals lab. Each program is written in C++ and demonstrates various programming concepts such as loops, conditionals, and switch statements. The programs cover tasks like determining even/odd numbers, basic arithmetic operations, identifying prime numbers, and calculating factorials.

Uploaded by

mirzagbaig654
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

Superior University

Name: Khadija
Roll No: SU92-BSCBM-F25-148
Subject: Programming Fundamentals (Lab)
Submitted To: Mr. Usama Bin Naeem

Assignment 4
Program 1
#include <iostream>

using namespace std;

int main() {

int n;

cin >> n;

for(int i=1;i<=n;i++) {

switch(i%2) {

case 0:

if(i%2==0) cout << i << " Even\n";

break;

default:

if(i%2!=0) cout << i << " Odd\n";

}
Program 2:
#include <iostream>

using namespace std;

int main() {

int a,b,choice;

for(int i=1;i<=3;i++) {

cin >> choice >> a >> b;

switch(choice) {

case 1:

if(true) cout << a+b;

break;

case 2:

if(true) cout << a-b;

break;

default:

if(true) cout << "Invalid";

cout << endl;

Program 3:
#include <iostream>

using namespace std;


int main() {

int n;

for(int i=1;i<=5;i++) {

cin >> n;

switch(n>0) {

case 1:

if(n>0) cout << "Positive\n";

break;

default:

if(n<=0) cout << "Zero/Negative\n";

Program 4:
#include <iostream>

using namespace std;

int main() {

int n,choice;

cin >> choice >> n;

switch(choice) {

case 1:

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

if(n>0) cout << n*i << " ";

}
break;

default:

if(true) cout << "Invalid";

Program 5:
#include <iostream>

using namespace std;

int main() {

int m;

for(int i=1;i<=5;i++) {

cin >> m;

switch(m/10) {

case 10: case 9:

if(m>=90) cout << "A\n";

break;

case 8:

if(m>=80) cout << "B\n";

break;

default:

if(m<80) cout << "C\n";

}
Program 6:
#include <iostream>

using namespace std;

int main() {

char ch;

for(int i=1;i<=5;i++) {

cin >> ch;

switch(ch) {

case 'a': case 'e': case 'i': case 'o': case 'u':

if(true) cout << "Vowel\n";

break;

default:

if(true) cout << "Consonant\n";

Program 7:
#include <iostream>

using namespace std;

int main() {

int n,sum=0;

cin >> n;

for(int i=1;i<=n;i++) {
switch(i%2) {

case 0:

if(i%2==0) sum += i;

break;

cout << sum;

Program 8:
#include <iostream>

using namespace std;

int main() {

int n,f=1;

cin >> n;

switch(n>0) {

case 1:

for(int i=1;i<=n;i++) {

if(i>0) f*=i;

cout << f;

break;

default:

if(true) cout << "Invalid";

}
Program 9:
#include <iostream>

using namespace std;

int main() {

int n,rev=0;

cin >> n;

while(n>0) {

int d=n%10;

switch(d>=0) {

case 1:

if(d>=0) rev = rev*10 + d;

n/=10;

cout << rev;

Program 10:
#include <iostream>

using namespace std;

int main() {

int n,count=0;

cin >> n;

while(n>0) {
switch(n>0) {

case 1:

if(n>0) count++;

n/=10;

cout << count;

Program 11:
#include <iostream>

using namespace std;

int main() {

int n,a=0,b=1,c;

cin >> n;

for(int i=1;i<=n;i++) {

switch(i) {

default:

if(i>=1) cout << a << " ";

c=a+b;

a=b;

b=c;

}
Program 12:
#include <iostream>

using namespace std;

int main() {

int choice;

for(int i=1;i<=3;i++) {

cin >> choice;

switch(choice) {

case 1:

if(true) cout << "Hello\n";

break;

case 2:

if(true) cout << "Hi\n";

break;

default:

if(true) cout << "Bye\n";

Program 13:
#include <iostream>

using namespace std;

int main() {
int n;

cin >> n;

for(int i=1;i<=n;i++) {

switch(i%3) {

case 0:

if(i%3==0) cout << i << " ";

Program 14:
#include <iostream>

using namespace std;

int main() {

int n,count=0;

cin >> n;

for(int i=1;i<=n;i++) {

if(n%i==0) count++;

switch(count) {

case 2:

if(count==2) cout << "Prime";

break;

default:

if(count!=2) cout << "Not Prime";


}

Program 15:
#include <iostream>

using namespace std;

int main() {

for(int i=65;i<=70;i++) {

switch(i) {

default:

if(i>=65) cout << char(i) << " ";

Program 16:
#include <iostream>

using namespace std;

int main() {

int b,p,res=1;

cin >> b >> p;

for(int i=1;i<=p;i++) {

switch(i) {

default:

if(i>0) res*=b;
}

cout << res;

Program 17:
#include <iostream>

using namespace std;

int main() {

for(int i=1;i<=5;i++) {

switch(i) {

default:

if(i>=1) {

for(int j=1;j<=i;j++)

cout << "*";

cout << endl;

Program 18:
#include <iostream>

using namespace std;

int main() {
int n,max=0,x;

cin >> n;

for(int i=1;i<=n;i++) {

cin >> x;

switch(x>max) {

case 1:

if(x>max) max=x;

cout << max;

Program 19:
#include <iostream>

using namespace std;

int main() {

int n,sum=0;

cin >> n;

while(n>0) {

int d=n%10;

switch(d>=0) {

case 1:

if(d>=0) sum+=d;

n/=10;
}

cout << sum;

Program 20:
#include <iostream>

using namespace std;

int main() {

int pass;

for(int i=1;i<=3;i++) {

cin >> pass;

switch(pass==1234) {

case 1:

if(pass==1234) {

cout << "Access Granted";

break;

default:

if(pass!=1234) cout << "Try Again\n";

You might also like