C Programming Tasks
C Programming Tasks
Question 1 ....................................................................................................................................... 2
Code: ........................................................................................................................................... 2
Result: ......................................................................................................................................... 2
Question 2 ....................................................................................................................................... 2
Code: ........................................................................................................................................... 2
Result: ......................................................................................................................................... 3
Question 3 ....................................................................................................................................... 4
Flowchart: ................................................................................................................................... 4
Code: ........................................................................................................................................... 4
Result: ......................................................................................................................................... 5
Question 4 ....................................................................................................................................... 6
Code: ........................................................................................................................................... 6
Result: ......................................................................................................................................... 6
Question 1
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
float y ,x , n;
printf("\nEnter value for x: ");
scanf("%f", &x);
y = 3*x*x+pow(2,x);
n = pow(x,2.5)+sqrt(x+pow(3,x));
printf("y = %f n = %f",y,n);
return 0;
}
Result:
Question 2
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,k, vacant, people;
while(1)
{
printf("\nEnter Total Number of Flats and flats occupied ");
scanf("%d%d", &n, &k);
vacant = n-k;
people = 3*k;
printf("\nThe number of vacant flats are %d",vacant);
printf("\nTotal number of people staying in the building %d",people);
}
return 0;
}
Result:
Question 3
Flowchart:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int salary;
while(1)
{
printf("\nEnter Salary: ");
scanf("%d", &salary);
if (salary < 500)
{
salary = salary + 0.15*salary;
printf("%d",salary);
}
else if (salary >= 500 && salary <= 800)
{
salary = salary + 0.10*salary;
printf("%d",salary);
}
else if (salary >= 801 && salary <= 1200)
{
salary = salary + 0.05*salary;
printf("%d",salary);
}
else if (salary > 1200)
{
printf("%d",salary);
}
}
return 0;
}
Result:
Question 4
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x;
while(1)
{
printf("\nEnter Integer: ");
scanf("%d", &x);
if (x%5 == 0)
{
printf("Yes it is multiple of 5");
}
else
{
printf("No it is not multiple of 5");
}
}
return 0;
}
Result: