Wednesday, December 25, 2013

Assignment I : Variable, Operator & Expression Set I SOLUTIONS

1 Write a program to print HELLO WORLD on screen?

#include<iostream.h>
#include<conio.h>

int main()
{
 cout<<"Hello world";
 getch();
 return 0;
}

2
Write a program to display the following output using a single cout statement.
   Subject            Marks
   Mathematics     90 
   Computer         77 
   Chemistry        69
#include<iostream.h>
#include<conio.h>

int main()
{
 cout<<"subject " <<"\tmarks"<<"\nmathematic\t"
  <<90<<"\ncomputer\t"<<77<<"\nchemistry\t"<<69;

 getch();
 return 0;
}

3
Write a program which accept two numbers and print their sum. 
#include<iostream.h>
#include<conio.h>

int main()
{
 int a,b,c;
 cout<< "\nEnter first number : ";
 cin>>a;
 cout<<"\nEnter second number : ";
 cin>>b;
 c=a+b;
 cout<<"\nThe Sum is : "<<c;

 getch();
 return 0;
}

4
Write a program which accept temperature in Farenheit and print it in centigrade. 
#include<iostream.h>
#include<conio.h>

int main()
{
 float F,C;
 cout<< "\nEnter temperature in Farenheit : ";
 cin>>F;
 C=5*(F-32)/9;
 cout<<"Temperature in celcius is : "<<C;

 getch();
 return 0;
}


5
Write a program which accept principle, rate and time from user and print the simple interest. 
#include<iostream.h>
#include<conio.h>

int main()
{
 int p,r,t,i;
 cout<<"Enter Principle : ";
 cin>>p;
 cout<<"Enter Rate : ";
 cin>>r;
 cout<<"Enter Time : ";
 cin>>t;
 i=(p*r*t)/100;
 cout<<"Simple interest is : "<<i;

 getch();
 return 0;
}
6
Write a program which accepts a character and display its ASCII value. 
#include<iostream.h>
#include<conio.h>

int main()
{
 char ch;
 cout<< "\nEnter any character : ";
 cin>>ch;
 cout<<"ASCII equivalent is : "<<(int)ch;

 getch();
 return 0;
}
7
Write a program to swap the values of two variables. 
#include<iostream.h>
#include<conio.h>

int main()
{
 int a,b,temp;
 cout<<"\nEnter two numbers : ";
 cin>>a>>b;
 temp=a;
 a=b;
 b=temp;
 cout<<"\nAfter swapping numbers are : ";
 cout<<a<<" "<<b;

 getch();
 return 0;
}
8
Write a program to calculate area of circle. 
#include<iostream.h>
#include<conio.h>


int main()
{
 float r,area;
 cout<< "\nEnter radius of circle : ";

 cin>>r;
 area = 3.14*r*r;

 cout<<"Area of circle : "<<area;

 getch();
 return 0;
}
9
Write a program to check whether the given number is positive or negative (using ? : ternary operator )
#include<iostream.h>
#include<conio.h>

int main()
{
 int a;
 cout<<"Enter any non-zero Number : ";
 cin>>a;
 (a>0)?cout<<"Number is positive":cout<<"Number is negative";

 getch();
 return 0;
}
10
Write a program to check whether the given number is even or odd (using ? : ternary operator ) 
#include<iostream.h>
#include<conio.h>

int main()
{
 int a;
 cout<<"Enter the Number : ";
 cin>>a;
 (a%2==0)?cout<<"Number is even":cout<<"Number is odd";

 getch();
 return 0;
}

1 comment: