Fundamentals of Programming ITCS 231 Assignment 2: Prepared by
Fundamentals of Programming ITCS 231 Assignment 2: Prepared by
231 Assignment 2
Prepared By
Name ID no
1. Woderyelesh Assefa CDE 04-43-06
2. Eyassu Demissew CDE 04-05-06
1)The program will tell you if the value currently stored in x is positive, negative
#include<iostream.h>
void main()
{
int x ;
cout<<"Enter the value of the number \n";cin>>x;
if( x>=0){
cout<<"The number you entered is positive number \n"<<x;
}
else if(x<0)
{
cout<<"The number you entered is negative number \n"<<x;
}
2) Countdown program n to 0
#include <iostream.h>
void main ()
{
int countDown= 0;
} }
3c) #include<iostream.h>
void main() Output
{
*
int i,j,k,n=6;
for(i=0;i<n;i++) ***
{
for(j=i;j<n;j++) ******
{
cout<<" "; *******
}
*********
for(k=0;k<2*i-1;k++)
{
cout<<"*";
}
cout<<endl;
}
}
4) Calculator Program
#include<iostream.h>
void main()
{
float num1,num2,add,sub,div,mul;
char opr;
cout<<"Please Enter the operator\n'+','-','*','/'";
cin>>opr;
cout<<"You have Selected This Operator"<<opr<<endl;
cout<<"Enter num 1\n";
cin>>num1;
cout<<"enter num 2\n";
cin>>num2;
add=num1+num2;
sub=num1-num2;
div=num1/num2;
mul=num1*num2;
if(opr=='+')
cout<<add;
else if(opr=='-')
cout<<sub;
else if(opr=='*'||opr=='x')
cout<<mul;
else if(opr=='/')
cout<<div;
#include<iostream.h>
void main()
{
for(int i = 0; i <=20;i+=2){
cout << i << " ";
}
}
#include<iostream.h>
int main()
{
int num,factorial=1;
cout<<" Enter Number To Find Its Factorial: ";
cin>>num;
for(int a=1;a<=num;a++)
{
factorial=factorial*a;
}
cout<<"Factorial of Given Number is ="<<factorial<<endl;
return 0;
}