0% found this document useful (0 votes)
9 views

C Programming Tasks

This document contains code snippets and results from 4 questions. Question 1 calculates values for y and n using mathematical operations on input x. Question 2 calculates vacant flats and total people using total flats and occupied flats as input. Question 3 increases salary by a percentage based on salary ranges, using salary as input. Question 4 checks if an integer is divisible by 5, using the integer as input.

Uploaded by

Sayaf Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

C Programming Tasks

This document contains code snippets and results from 4 questions. Question 1 calculates values for y and n using mathematical operations on input x. Question 2 calculates vacant flats and total people using total flats and occupied flats as input. Question 3 increases salary by a percentage based on salary ranges, using salary as input. Question 4 checks if an integer is divisible by 5, using the integer as input.

Uploaded by

Sayaf Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Table of Contents

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:

You might also like