Friday, 9 March 2012

C++ Practice A-3

Hi,


            How are you? I was busy with my some assignments for last week.So what about your home work?
Did you try the exercises that I given in the last post? I am giving the syntax of that exercise below.






  1. Subtraction / multiplication / division with three numbers.(read &print) 
Subtraction
---------------


#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,sum;
clrscr();
cout<<"Enter First Number :";
cin>>a;
cout<<"Enter Second Number : ";
cin>>b;
sum=a-b;
cout<<"Sum :";
cout<<sum;
getch();
}

---------------
For multiplication and division you only need to change the line -   sum=a-b;   to-

sum=a*b;   &    sum=a/b; respectively.

      2. Write a program to input a radius and print the  Area Of a circle .

---------------


#include<iostream.h>
#include<conio.h>
void main()
{
int r; float p=3.14,area;
clrscr();
cout<<"Enter the radius :";
cin>>r;
area=p*r*r;
cout<<"Area of the circle :"<<area;
getch();
}

---------------

Formula-  3.14 * radius*radius. Here I declared two variable as float because they are carrying point.
   
     3. Write a program to input marks of  five subjects and print student name and his average.

---------------
#include<iostream.h>
#include<conio.h>
void main()
{
char name[20];
        int mark1,mark2,mark3,mark4,mark5,tot,ave;
clrscr();
cout<<"Enter name of the student:";
cin>>name;
cout<<"Mark 1 :";
cin>>mark1;
cout<<"Mark 2 :";
cin>>mark2;
cout<<"Mark 3 :";
cin>>mark3;
cout<<"Mark 4 :";
cin>>mark4;
cout<<"Mark 5 :";
cin>>mark5;
tot=mark1+mark2+mark3+mark4+mark5;
ave=tot/5;
cout<<"Student Name\tTotal Mark\tAverage Mark\n";
cout<<name<<"\t\t"<<tot<<"\t\t"<<ave;
getch();
}
--------------

Here I declared a variable(name) as char for adding student name. "char name" store only one letter, for storing more than one letter you have to declare the length. for example -    name[20]    - the variable can now store up to 20 letters.

Thanks,
Sidh.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Web Hosting Coupons