Assignment 1 (24bsit039)
Assignment 1 (24bsit039)
B.SC. IT Semester – II
Student id – 24BSIT018
return 0;
}
Output:
4. Write a program to find the area of circle. (Formula: Area = PI * r * r )
Code:
#include<iostream>
using namespace std;
int main()
{
int r;
float area;
cout<<"Enter a radious : ";
cin>>r;
area=(22*r*r)/7;
cout<<"area of circle : "<<area;
return 0;
}
Output:
5. Write a program to calculate simple interest. (Formula: SI = (P * R * N)
100)
Code:
#include<iostream>
using namespace std;
int main()
{
int p,r,n,si;
cout<<"Enter a principal : ";
cin>>p;
cout<<"Enter a rate of interest : ";
cin>>r;
cout<<"Enter a rate of time : ";
cin>>n;
si=(p*r*n)/100;
cout<<"simple interest : "<<si;
return 0;
}
Output:
return 0;
}
Output:
return 0;
}
Output:
12. Write a program to input five numbers into an array and display them.
Code:
#include<iostream>
using namespace std;
int main()
{
int n[5],i;
for(int i=0; i<5; i++)
{
cin>>n[i];
}
for(int i=0; i<5; i++)
{
cout<<"\n numbers : "<<n[i];
}
return 0;
}
Output:
13. Write a program to input five subject marks into an array, then display
the total marks and average marks.
Code:
#include<iostream>
using namespace std;
int main()
{
int marks[5],i,total=0;
float avg;
return 0;
}
Output:
14. Write a program to find the maximum number in an array.
Code:
#include <iostream>
using namespace std;
int main()
{
int n,x[n],i;
cout << "Enter the numbers: ";
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x[i];
}
int max = x[0];
for (int i = 1; i < n; i++)
{
if (x[i] > max)
{
max = x[i];
}
}
cout << "The maximum number in the array is: " << max;
return 0;
}
Output:
15. Write a menu-driven program using a switch case to input two numbers
from the user and perform all the basic arithmetic operations.
Code:
#include <iostream>
using namespace std;
int main()
{
int a,b,choice;
float res;
cout<<"enter the first number : ";
cin>>a;
cout<<"enter the second number : ";
cin>>b;
cout<<"enter the choice from below \n1 for addition \n2 for
subtraction \n3 for multiplication \n4division ";
cout<<"\nenter the choice : ";
cin>>choice;
switch(choice)
{
case 1:res=a+b;
cout<<"\naddition = "<<res;
case 2:res=a-b;
cout<<"\nsubtraction = "<<res;
case 3:res=a*b;
cout<<"\nmultiplication = "<<res;
case 4:res=a/b;
cout<<"\ndivision = "<<res;
default : cout<<"\ninvaidoparater";
}
return 0;
}
Output: