0% found this document useful (0 votes)
65 views6 pages

Fundamentals of Programming ITCS 231 Assignment 2: Prepared by

This document contains 8 C++ programs that demonstrate different programming concepts. Program 1 checks if a number is positive or negative. Program 2 counts down from a user-input number to 0. Programs 3a, 3b, and 3c output triangle patterns using loops and formatting. Program 4 is a basic calculator. Program 5 checks if a character is a vowel or consonant. Program 6 outputs even numbers between 0 and 20. Program 7 finds the largest of three user-input numbers. Program 8 calculates the factorial of a user-input number.

Uploaded by

Abrham Dube
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views6 pages

Fundamentals of Programming ITCS 231 Assignment 2: Prepared by

This document contains 8 C++ programs that demonstrate different programming concepts. Program 1 checks if a number is positive or negative. Program 2 counts down from a user-input number to 0. Programs 3a, 3b, and 3c output triangle patterns using loops and formatting. Program 4 is a basic calculator. Program 5 checks if a character is a vowel or consonant. Program 6 outputs even numbers between 0 and 20. Program 7 finds the largest of three user-input numbers. Program 8 calculates the factorial of a user-input number.

Uploaded by

Abrham Dube
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Fundamentals of Programming ITCS

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;

cout <<"Enter the number you want to start from: ";


cin >>countDown;

for ( countDown; countDown >= 0; countDown--)


cout <<countDown<<", ";
}
3)A
#include<iostream.h>
void main() Output
{
*
int i,j,n=5;
for(i=0;i<n;i++) **
{
***
for(j=0;j<=i;j++)
{ ****
cout<<"*";
*****
}
cout<<endl;
}
}
3b)
#include<iostream.h>
Output
void main(){
for(int i=5; i>=1; i--) *****
{
****
for(int j=1; j<=i; j++)
{ ***
cout<<"*" ;
**
}
cout<<endl<<endl; *

} }
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;

5 Displays the character is vowel or consonant


#include<iostream.h>
void main()
{
char x;
cout<<"Please enter a character: ";
cin>>x;
if(x=='a'||x=='A'||x=='e'||x=='E'||x=='i'||x=='I'||x=='o'||x=='O'||x=='u'||x=='U')
cout<<x<<" is a Vowel :)";
else
cout<<x<<" is a consonant :)";
}
6) Displays even numbers found between 0 and 20

#include<iostream.h>
void main()
{
for(int i = 0; i <=20;i+=2){
cout << i << " ";
}
}

7) Displays the largest of the three numbers:


#include<iostream.h>
int main()
{
float num1,num2,num3;
cout<<"Enter value for first number";
cin>>num1;
cout<<"Enter value for second number";
cin>>num2;
cout<<"Enter value for third number";
cin>>num3;
if(num1>num2&&num1>num3)
{
cout<<"First number is greatest:"<<num1;
}
else if(num2>num1&&num2>num3)
{
cout<<"Second number is greatest"<<num2;
}
else
{
cout<<"Third number is greatest"<<endl<<num3;
}
return 0;
}
8 The following code calculates the factorial of a given number

#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;
}

You might also like