Professional Documents
Culture Documents
Fall-2020
Task 1
#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
#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
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
#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
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);
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);
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);
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
#include<stdio>
14 | P a g e
int main()
{
int num,digit1,digit2,digit3;
int sum;
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
#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