Professional Documents
Culture Documents
ASSIGN
MENT
Introductio
n to
Problem 1: NO 1
Computer
Programmin Solution
g
Sir I have seeked help from different websites and online tutorials for the cited task in
order to meet all the requirements of the program, I ended with the underlying program.
I’ll be at your debt if you rectify me after assignment if it’s found beyond the required
conditions so that I may have better understanding in future. Thanks
"ELEVEN","TWELEVE","THIRRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SE
VENTEEN","EIGHTEEN","NINETEEN"};
const char * const tens[10] = {"", "TEN", "TWENTY",
"THIRTY","FOURTY","FIFTY","SIXTY","SEVENTY",
"EIGHTY","NINETY"};
if(value<0)
{
printf(" Minus ");
expand(-value);
}
else if(value>=1000)
FA19-BEE-040
HAFIZ MUHAMMAD ARSLAN MUNIR
{
expand(value/1000);
printf(" THOUSAND ");
if(value % 1000)
{
if(value % 1000 < 100)
{
printf(" AND ");
}
printf(" ");
expand(value % 1000);
}
}
else if(value >= 100)
{
expand(value / 100);
printf(" HUNDRED ");
if(value % 100)
{
printf(" AND ");
expand (value % 100);
}
}
else if(value >= 20)
{
printf(tens[value / 10]);
if(value % 10)
FA19-BEE-040
HAFIZ MUHAMMAD ARSLAN MUNIR
{
printf(" ");
expand(value % 10);
}
}
else
{
printf(ones[value]);
}
return;
}
Problem 2:
Solution
/*FA19-BEE-040/LHR*/
FA19-BEE-040
HAFIZ MUHAMMAD ARSLAN MUNIR
/*HAFIZ MUHAMMAD ARSLAN MUNIR*/ /*TASK - 2*/
#include<stdio.h>
int validateInput()
{
int number;
do{
printf("Enter numbers:\n");
scanf("%d",&number);
}
while(number < 0);
return number;
}
void showInstructions()
{
}
long factorial(int number)
{
long fact = 1;
int count = 1;
for(count=1;count<=number;count++){
FA19-BEE-040
HAFIZ MUHAMMAD ARSLAN MUNIR
fact = fact + 1;
}
return fact;
}
int multiply(int n, int r)
{
return n*r;
}
long comb(int n, int r)
{
return (factorial(n)/(factorial(r)*factorial(n-r)));
}
long perm(int n, int r)
{
return (factorial(n)/factorial(n-r));
}
main()
{
int n = validateInput();
int r = validateInput();
showInstructions();
int choice;
scanf("%d",&choice);
if (choice == -1){
printf("Exited!");
FA19-BEE-040
HAFIZ MUHAMMAD ARSLAN MUNIR
}
else if (choice == 1){
int mul;
mul = multiply(n,r);
printf("%d",mul);
}
else if (choice == 2){
long ncr = comb(n,r);
printf("%dC%d = %ld", n, r, ncr);
}
else if (choice == 3){
long npr = perm(n,r);
printf("%dC%d = %ld", n,r,npr);
}
}
FA19-BEE-040
HAFIZ MUHAMMAD ARSLAN MUNIR
Problem 3:
Solution
/*FA19-BEE-040/LHR*/
/*HAFIZ MUHAMMAD ARSLAN MUNIR*/ /*TASK - 3*/
#include<stdio.h>
int main()
{
int number;
int prime(int number);
primefactor(number);
}
prime(int num)
{
int counter, is_prime;
FA19-BEE-040
HAFIZ MUHAMMAD ARSLAN MUNIR
for (counter=2; counter<=num-1; counter++)
{
if (num%counter==0)
{
is_prime=0;
}
else
is_prime=1;
}
return (is_prime);
}
primefactor(int num)
{
int factor,is_prime;
for (factor=2; factor<=num;)
{
prime(factor);
if (is_prime)
{
if (num%factor==0)
{
FA19-BEE-040
HAFIZ MUHAMMAD ARSLAN MUNIR
printf("%d \n", factor);
num=num/factor;
continue;
}
else
{
factor++;
}
}
}
return 0;
}