You are on page 1of 9

Lab Manual

Computer Fundamentals and Programming

Report: Lab Task 5 “Computer Fundamentals”


Lab Task -01
Write a program in C to find the square of any number using the function.
Test Data :
Input any number for square : 20
Expected Output :
The square of 20 is : 400.00
CODE:
#include <stdio.h>
float square(float);
int main()
{
float number;
printf ("Input an number for square : ");
scanf ("%f",&number);
printf ("The square of %f is : %f",number,square(number));
getchar();getchar();
return 0;
}
float square(float x)
{
return x*x;
}
Here is shown the screenshot of the above program and its executable file.

Figure 1Screenshot of above program

Here is shown the executable file of the above program.

Figure 2.exe file

1|Page
Lab Task -02
1. Write a program that calls print line function 5 times using a loop.

2. Write a function void evenOdd(int), the function should print even or odd according to the
number passed. Call this function in main and show the output.

3. Write a program that prints the status of 10 numbers as even or odd using your evenOdd()
function, the numbers can be as simple as 1-10 or can be between two numbers A and B
provided by the user.

1) Code:
#include <stdio.h>

void printline(void);

int main()

int i;

for (i=0;i<5;i++)

printline();

getchar();getchar();

return 0;

void printline(void)

printf("\n**************************************************\n");

2|Page
Here is shown the screenshot of the above program and its executable file.

Figure 3Screenshot of above program

Here is shown the executable file of the above program.

3|Page
2) Code:
#include <stdio.h>
void evenOdd(int);
int main()
{
int number;
printf ("Enter a number : ");
scanf("%d",&number);
evenOdd(number);
getchar();getchar();
return 0;
}
void evenOdd(int x)
{
if (x%2==0)
printf ("\nNumber is even.");
else
printf ("\nNumber is odd.");
}
Here is shown the screenshot of the above program and its executable file.

Figure 4Screenshot of above program

4|Page
Here is shown the executable file of the above program.

5|Page
3) Code:
#include <stdio.h>
void evenOdd(int);
int main()
{
int a,b;
printf ("Please enter the lower limit: ");
scanf ("%d",&a);
printf ("Please enter the upper limit: ");
scanf ("%d",&b);

if (b-a>9) //replace > with != if range can’t be less than 10


printf ("Invalid range (must be equal to 10.)");
else
for (a;a<=b;a++)
evenOdd(a);

getchar();getchar();
return 0;
}
void evenOdd(int x)
{
if (x%2==0)
printf ("%d is even.\n\n",x);
else
printf ("%d is odd.\n\n",x);
}

6|Page
Here is shown the screenshot of the above program and its executable file.

Figure 5Screenshot of above program

7|Page
Here is shown the executable file of the above program.

8|Page

You might also like