You are on page 1of 19

Lab Manual

Fall-2020

Computer Fundamentals and Programming

Submitted by: HAMMAD AHMAD ILTAF


HAMMAD AHMAD ILTAF BSMME section (A) BS-20-
LB-110932

Task 1

Write a program that performs all compound assignment operations on an integer.

#include<stdio.h>
int main()
{
int a=5;
printf("Before compound operater value of a = %d\n",a);

a+=5;
printf("Value of a after compound operater\na = %d\n",a); //a=a+5

a=5;
a-=5; //a=a-5;
printf("a = %d\n",a);

a=5;
a*=5; //a=a*5;
printf("a = %d\n",a);

a=5;
a/=5; //a=a/5
printf("a = %d\n",a);

a=5;
a%=5; //a=a%5
printf("a = %d\n",a);

getchar();
return 0;
}

1|Page
2|Page
TASK 2

Write a program that performs all above mentioned trigonometric operations

#include<stdio.h>
#include<math.h>
int main()
{
float y,deg,rad,deg_2; // y=function , deg = degree,rad =
radian
const float pi = 3.14; //declaring constant value of pi

deg = 30; // 30 degree assignedto programe

rad = (pi/180)*deg; //conversion of degree to radian

y = sin(rad); //sin(30)
printf("sin(%f) = %f\n",deg,y);

y = asin(rad); //asin(30)
printf("asin(%f) = %f\n",deg,y);

y = cos(rad); //cos(30)
printf("cos(%f) = %f\n",deg,y);

y = acos(rad); //acos(30)
printf("acos(%f) = %f\n",deg,y);

y = tan(rad); //tan(30)
printf("tan(%f) = %f\n",deg,y);

y = atan(rad); //atan(30)
printf("atan(%f) = %f\n",deg,y);

deg_2 = 60;
rad = (pi/180)*deg_2;

y = atan2(deg,deg_2); //atan2(30,60)
printf("atan2(%f,%f) = %f\n",deg,deg_2,y);

getchar();
return 0;
}

3|Page
4|Page
Task 3

Write a C program to read temperature in centigrade and display a suitable message according to

temperature state below:

Temp < 0 then Freezing weather

Temp 0-10 then Very Cold weather

Temp 10-20 then Cold weather

Temp 20-30 then Normal in Temp

Temp 30-40 then Its Hot

Temp >=40 then Its Very Hot

#include<stdio.h>
int main()
{
int temp;
printf("Type temperature in centigrade: ");
scanf("%d",&temp);

if(temp<=0)
printf("It's freezing water"); //less or equal to 0 deg
Centigrade

else if(temp>0 && temp<=10) //between 0 to 10 degree


centigrade
printf("It's freezing water");

else if(temp>10 && temp<=20) //between 10 to 20 degree


centigrade
printf("It's cold weather");

else if(temp>20 && temp<=30) //between 20 to 30 degree


centigrade
printf("It's Normal temperature");

else if(temp>30 && temp<=40) //between 30 to 40 degree


centigrade
printf("It's hot");

else
printf("It's very hot"); //above 40 degree
centigrade
getchar();
getchar();
return 0;
}

5|Page
Task 4

Write a C program to get three integers from user and find the greatest number among three numbers:

#include<stdio.h>
int main()
{
int x, y, z;
printf("This programe finds the greatest number among three integers\n");

6|Page
printf("Enter first integer: ");
scanf("%d",&x);

printf("Enter second integer: ");


scanf("%d",&y);

printf("Enter third integer: ");


scanf("%d",&z);

if (x>y && x>z)


printf("\nGreatest number is %d",x);

else if (y>x && y>z)


printf("\nGreatest number is %d",y);

else
printf("\nGreatest number is %d",z);

getchar();
getchar();
return 0;
}

7|Page
TASK 5

Write a C program to check sign of given number. Sample output is given below.

#include<stdio.h>
int main()
{
int num;
printf("This programe checks sign of number\n");

8|Page
printf("\nEnter the number: ");
scanf("%d",&num);

if (num>0)
printf("The number is positive");

else if (num==0)
printf("The number is nuetral");

else
printf("The number is negative");

getchar();
getchar();
return 0;
}

9|Page
Task 6

Write a program that lets user enter an integer value between 1 and 10, the program validates the
input, if the

value entered is between 1 and 10 the program prints the message “Valid Number” and value entered

10 | P a g e
otherwise the program should print message “Invalid Number” and value.

#include<stdio.h>
int main()
{
int x;
printf("Enter any number between 1 to 10: ");
scanf("%d",&x);

if(x>=1 && x<=10)


printf("Valid number %d",x);

else
printf("Invalid number %d",x);

getchar();
getchar();
return 0;
}

11 | P a g e
Task 7

Write a program that ask users to input marks of a subject and print the letter grade

#include<stdio.h>
int main()
{
int marks;

12 | P a g e
printf("Enter marks of a subject: ");
scanf("%d",&marks);

if(marks>=51 && marks<=60)


printf("Grade D");

else if(marks>=61 && marks<=70)


printf("Grade C");

else if(marks>=71 && marks<=80)


printf("Grade B");

else if(marks>=81 && marks<=100)


printf("Grade A");

else
printf("Invalid marks, no grades can be assigned");

getchar();
getchar();
return 0;
}

13 | P a g e
Task 8

Write a program that gets a three digit integer input and prints the sum of its digits. For example if user
enters

123 the program should calculate 1+2+3 = 6 as answer.

#include<stdio>

14 | P a g e
int main()
{
int num,digit1,digit2,digit3;
int sum;

printf("Enter a digit: ");


scanf("%d",&num);

digit1 = num%10;
digit2 = (num/10)%10;
digit3 = num/100;
sum = digit1 + digit2 + digit3;
printf("the sum of digits is = %d",sum);

getchar();
getchar();
return 0;
}

15 | P a g e
Activity 9

Write a C program to read the age of a candidate and determine whether it is eligible for

casting his/her own vote.

#include<stdio.h>
int main()
{
int age;

16 | P a g e
printf("Enter your age : ");
scanf("%d",&age);

if(age>=18)
printf("You are eligible for voting");

else
printf("Sorry, You are not eligible for voting");

getchar();
getchar();

return 0;

17 | P a g e
18 | P a g e

You might also like