Computer Programming

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

ABDULLAH MUHAMMAD

BsCs (1st B)

COMPUTER
PROGRAMMING
Submitted to: Prof. Sohail Mumtaz

Problem No 1: Write a prescribed note on


a) Main data types in C++.

b) Binary Operators
c) Header Files
d) Compiler & Interpreter

a) main data type in C++ :


Char

Int

Short

Shortint

Long

Unsinged char

Unsinged int

Unsinged long

Unsinged short

b) binary operations :
Operator

Name

Comma

!=

Inequality

Modulus

%=

Modulus/assignment

&

Bitwise AND

&&

Logical AND

&=

Bitwise AND/assignment

Multiplication

*=

Multiplication/assignment

Addition

+=

Addition/assignment

Subtraction

Subtraction/assignment

>

Member selection

>*

Pointer-to-member selection

Division

/=

Division/assignment

<

Less than

<<

Left shift

<<=

Left shift/assignment

<=

Less than or equal to

Assignment

==

Equality

>

Greater than

>=

Greater than or equal to

>>

Right shift

>>=

Right shift/assignment

Exclusive OR

^=

Exclusive OR/assignment

Bitwise inclusive OR

|=

Bitwise inclusive OR/assignment

||

Logical OR

c) Header Files:
stdio.h
math.h

conio.h
graphics.h

iostreem.h
string.h

d) Compiler & Interpreter:


Compiler:
A compiler is a program that converts the instructions of a
high level language into a machine language as a whole. A program
written in high level language is called source program. Compiler
converts source program into machine code known as object
program.
Compiler also checks syntax errors in the program.
Source program compiler object program

Interpreter :
An interpreter is a program that converts one statement of a
program at one time. It executes this statements before
translating the next statement of the source program. If there
is an error in the statements, the interpreter stops working
and displays an error messages.

Problem No 3: Write a program to print the


followingseries in same pattern.
2, 4, 8, 16, 32, 64 1024

// series of 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
int a;
a=2;
while (a<=1024)
{
cout<< "\t " << a;
a=a+1;
}
getch ();
return 0;
}

Problem No 4: Write a program to display the factorial of


the number given by user.
// Factorial True

#include<iostream>
#include<conio.h>
using namespace std;
int factorial(int n);
int main()
{
int n;
cout<< "Enter a positive integer: ";
cin>> n;
cout<< "Factorial of " << n << " = " << factorial(n);
getch();
return 0;
}
int factorial(int n)
{
if(n!=1)
return n*factorial(n-1);
}

Problem No 5: Write a program to display 2xwhere user


will input the value in x.
//Power of 2

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

using namespace std;

int main()
{
inta,b;
long p;
cout<< "enter any number " <<endl;
cin>> b;
p=pow(2,b);
cout<< "power" << p;
getch();
return 0;
}

Problem No 6: Write a program to display yxwhere user


will input the value in
x& y.
// Power of x and y

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

using namespace std;

int main()
{
intx,y;
long p;
cout<< "Enter a value " <<endl;
cin>> x;
cout<< "Enter a power " <<endl;
cin>> y;
p=pow(x,y);
cout<< "Answer " << p;
getch();
return 0;
}

Problem No 7: Write a program to display all even


numbers till 150.
//Divisible of 7 till 150

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

using namespace std;

int main()
{
int a;
a=7;
while (a<=150)
{
if (a%7==0)
{
cout<< a << "\t" ;
}
a=a+1;
}
getch();

return 0;
}

Problem No 8: Write a program to display all odd


numbers till 100.
//Odd no. till 100

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

using namespace std;

int main()
{
int a;
a=1;
while (a<=100)
{
if (a%2==1)
{
cout<< a << "\t" ;
}
a=a+1;
}
getch();

return 0;
}

Problem No 9: Write a program to display all the devisors


of 7 till 150.
//Divisible of 7 till 150

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

using namespace std;

int main()
{
int a;
a=7;
while (a<=150)
{
if (a%7==0)
{
cout<< a << "\t" ;
}
a=a+1;
}
getch();

return 0;
}

Problem No 10: Find the youngest brother among Ali,


Asad&Fakhir, where user will input the age of them in years.
//Ages of three boys

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
inta,b,c;
cout<< "Enter age of Ali" <<endl;
cin>> a;
cout<< "Enter age of Asad" <<endl;
cin>> b;
cout<< "Enter age of Fakhir" <<endl;
cin>> c;
if (a>b)
{
if (b>c)
{
cout<< "Fakhir is youngest among all" <<endl;
}
}
else if (c>b)
{
if (b>a)
{
cout<< "Ali is youngest among all" <<endl;
}

}
else
if (a&&c>b)
{
cout<< "Asad is youngest among all" <<endl;
}
getch();
return 0;
}

Problem No 11: Write a computer program that prompts


the user to input elapsed time in seconds. The program then
outputs the elapsed time in hours, minutes and seconds.
(For example if the elapsed time is 9630 seconds, then the
output is 2 : 40 : 30).
// time program mine way

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{

longintinput_seconds;
int days, hours, minutes, seconds;

cout<< "Enter the number of seconds: ";


cin>>input_seconds;
days = input_seconds / 60 / 60/ 24;
hours = (input_seconds / 60 /60) % 24;
minutes = (input_seconds / 60) % 60;
seconds = input_seconds % 60;
cout<< "\n days = \t " << days << "\n hours =\t " << hours << "\n
minutes =\t " << minutes << "\n seconds =\t " << seconds;

getch();
return 0;
}

Problem No 12: Write a program to take the value of v, x, y,


z from user and calculates the following expression.
Ans= x3v2+xy3+xyz2
//Equation

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
long a;
intx,v,y,z;
cout<< "Enter x" <<endl;
cin>> x;
cout<< "Enter v" <<endl;
cin>> v;
cout<< "Enter y" <<endl;
cin>> y;
cout<< "Enter z" <<endl;
cin>> z;

a=(x*x*x)*(v*v)+x*(y*y*y)+x*y*(z*z);

cout<< "Answer " << a;


getch();
return 0;
}

You might also like