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

By Switch

This C++ program uses a switch statement to allow a user to select from 10 options numbered 1-9 and 0. Each numbered case performs a different calculation or check - such as calculating power, the Fibonacci series, prime numbers, even/odd, attendance percentage, and mathematical operations like addition, subtraction, multiplication and division. The user is prompted to enter relevant numbers needed for the calculation selected before the output is displayed. Case 0 provides an exit from the program.

Uploaded by

Asad
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)
38 views

By Switch

This C++ program uses a switch statement to allow a user to select from 10 options numbered 1-9 and 0. Each numbered case performs a different calculation or check - such as calculating power, the Fibonacci series, prime numbers, even/odd, attendance percentage, and mathematical operations like addition, subtraction, multiplication and division. The user is prompted to enter relevant numbers needed for the calculation selected before the output is displayed. Case 0 provides an exit from the program.

Uploaded by

Asad
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/ 6

HUSNAIN SARFRAZ

70067973

SECTION – T

ASSIGNMENT PF-1 (LAB)


Q No 1 :
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,b,num;
cout<<"Press 1 for Power calculate "<<endl;
cout<<"Press 2 for Fabonacci series "<<endl;
cout<<"Press 3 for Prime number "<<endl;
cout<<"Press 4 for Even and Odd "<<endl;
cout<<"Press 5 for Attendance checking "<<endl;
cout<<"Press 6 for Sum of two numbers "<<endl;
cout<<"Press 7 for Subtraction of two numbers "<<endl;
cout<<"Press 8 for Multiplication of two numbers "<<endl;
cout<<"Press 9 for Division of two numbers "<<endl;
cout<<"Press 0 to Exit from program "<<endl;
cout<<"-------------------------------------------------"<<endl;
cin>>num;

switch(num)
{
case 1:
{
int a,b;
cout<<"Enter a Base =";
cin>>a;
cout<<"Enter a power =";
cin>>b;
cout<<pow(a,b);
}
break;

case 2:
{
int n, c, a= 0, b= 1, d;
cout <<"Enter the number of terms of Fibonacci series"<< endl;
cin >> n;
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
d=c;
else
{
d=a+b;
a=b;
b=next;
}
cout<<d<<endl;
}
}
break;

case 3:
{
int x;
cout<<"Enter the number =";
cin>>x;
for(int i=2;i<x;i++)
{
if(x%i==0)
{
cout<<"Not Prime";
}
}
}
break;

case 4:
{
int a,b;
cout<<"Enter a Number =";
cin>>a;
if(a%2==0)
{
cout<<"Number is Even";
}
else
{
cout<<"Number is odd";
}
}
break;

case 5:
{
float attendance,total=32,a;
cout<<"Enter Attendance =";
cin>>attendance;
a=(attendance/total)*100;
cout<<"Percentage of student attendance ="<<a<<endl;
if(a<75)
{
cout<<"Not allow ";
}
else
{
cout<<"Allow ";
}
}
break;

case 6:
{
int a,b,sum;
cout<<"Enter first number =";
cin>>a;
cout<<"Enter second number =";
cin>>b;
sum=a+b;
cout<<"sum is "<<sum<<endl;
}
break;

case 7:
{
int a,b,Sub;
cout<<"Enter first number =";
cin>>a;
cout<<"Enter second number =";
cin>>b;
Sub=a-b;
cout<<"Sub is "<<Sub<<endl;
}
break;

case 8:
{
int a,b,Mult;
cout<<"Enter first number =";
cin>>a;
cout<<"Enter second number =";
cin>>b;
Mult=a*b;
cout<<"Mult is "<<Mult<<endl;
}
break;

case 9:
{
int a,b,Div;
cout<<"Enter first number =";
cin>>a;
cout<<"Enter second number =";
cin>>b;
Div=a/b;
cout<<"Div is "<<Div<<endl;
}
break;

case 0:
{
if(num==0)
{
break;
}
}

You might also like