Download - ShareStudies.com

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
LIU Collage
Name:
ID:
Class: CSCI 250-Introduction to Programming
Section: E
Date: 16/4/2009
Assignment: Third Assignment
Number 1:
#include<iostream>
using namespace std;
int main()
{
int x,sum=0;
char z;
cout<<"write numbers to find the products , only + and - are used:\n";
do{
cin>>x;
cin>>z;
if(z=='+')
sum=sum+x;
else if(z=='-')
sum=sum-x;
}
while(z!='=');
if(z=='=')
cout<<"="<<sum<<endl;
else cout<<"error"<<endl;
return 0;
}
Number 2:
#include<iostream>
using namespace std;
int main()
{
int n = 0, number;
unsigned factorial = 1;
do {cout << "Enter a positive integer: ";cin >> number;}
while ( number < 0 );
while ( n++ < number )
factorial *= n == 0 ? 1 : n;
cout << number << "! is " << factorial << endl;
return 0;
}
Number 3:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double ladder,angle_in_degrees,angle_in_radians,height,pi=3.14159;
while(1)
{
cout<<"Write the ladder length(Type negative length to quit):";
cin>>ladder;
if (ladder<0)
break;
cout<<"Write the angle in degree: ";
cin>>angle_in_degrees;
angle_in_radians = angle_in_degrees*pi/180;
height=ladder*sin(angle_in_radians);
cout<<"Height is: "<<height<<endl;
}
return 0;
}
Number 4:
#include<iostream>
using namespace std;
int main()
{
int side, rowPosition, size;
cout << "Enter the square side: ";
cin >> side;
size = side;
while ( side > 0 )
{
rowPosition = size;
while ( rowPosition > 0 )
{
if ( size == side || side == 1 || rowPosition == 1 ||
rowPosition == size )
cout << '*';
else
cout << ' ';
--rowPosition;
}
cout << '\n';
--side;
}
cout << endl;
return 0;
}
Number 5:
#include<iostream>
using namespace std;
int main()
{ int x,x1,x2,x3,x4,x5;
cout<<"Write 5 digit numbers and i will tell you if its palindrome";
cin>>x;
x1=x/10000;
x2=x%10000/1000;
x3=((x%10000)%1000)/100;
x4=(((x%10000)%1000)%100)/10;
x5=(((x%10000)%1000)%100)%10;
if (x1==x5&&x2==x4)
cout<<"This number is palindrome\n";
else cout<<"This number is not palindrome\n";
return 0;
}
Number 6:
#include<iostream>
using namespace std;
int main()
{ int i=1,j=2,k=3,m=2;
cout<<(i==1)<<endl;
cout<<(j==3)<<endl;
cout<<(i>=1&&j<4)<<endl;
cout<<(m<=99&&k<m)<<endl;
cout<<(j>=i||k==m)<<endl;
cout<<(k+m<j||3-j>=k)<<endl;
cout<<(!m)<<endl;
cout<<(!(j-m))<<endl;
cout<<(!(k>m))<<endl;
return 0;
}
(parentheses are not necessary)
(parentheses are not necessary)
(parentheses are not necessary)
Number 7:
#include<iostream>
using namespace std;
int main()
{ int x,y;
cout<<"Writ 2 integers to tell you if the first is the multible of the second:";
cin>>x>>y;
if (x%y==0)
cout<<"The first is the multible of the second"<<endl;
else cout<<"The first is not the multible of the second"<<endl;
return 0;
}
Related documents