Task 1 & Task 2
Task 1: Write a program that prints a text of 4 lines consisting of characters , integer values and floating point values using cout statement
Code:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//initialize variables
int n=80;
float f=80.5555;
char c='A';
//print the text using cout statement
cout<<"I am Code Seeker !\n";
cout<<"I Scored "<<n<<" Marks in Programming\n";
//set precision is used to set decimal places in floating point... this function comes under headerfile iomanip
cout<<"My Overall Percentage was "<<setprecision(5)<<f<<endl;
cout<<"My Grade is "<<c<<endl;
return 0;
// \n is used to move to next line and endl is used to end the line..
}
Output:
I am Code Seeker !
I Scored 80 Marks in Programming
My Overall Percentage was 80.555
My Grade is A
Task 2: Write a Program that inputs radius of sphere from user. It calculates Circumference and surface area using the formula
Area = A=4pir^2
Circumference = C =4/3(pi*r^3)
Where Pi = 3.1416
Answer should be upto 3 decimal digits.
Code:
Write a Program that inputs radius of sphere from user.
It calculates Circumference and surface area using the formula
Area = A=4*pi*r^2
Circumference = C =4/3(pi*r^3)
Where ?? = 3.1416
Answer should be upto 3 decimal digits.
*/
#include<iostream>
using namespace std;
int main()
{
//declaring variables
float pi=3.1416;
float r;
//taking input from user ...cin for input
cout<<"Enter Radius of Sphere : ";
cin>>r;
//variables in which we have to store the result of Area and circum..
float A=4*pi*r*r;
float C=4/3*pi*r*r*r;
cout<<"\nArea is : "<<A<<endl;
cout<<"\nCircumference is : "<<C<<endl;
return 0;
}
Output:
Enter Radius of Sphere : 3.6
Area is : 162.861
Circumference is : 146.574
3 Comments