TCS Practical

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

** Write a program in C to display “Hello World” on the output

screen.**
/* Name : ayush saklani
Section :I
Roll no : 21011352
Date : 19/12/2021
*/
#include <stdio.h>
int main()
{
printf("Hello world");
return 0;
}

Output -
Hello world
**Write a C Program to convert temperature from degrees
Fahrenheit to degrees Centigrade.**

/* Name : ayush saklani


Section :I
Roll no : 21011352
Date : 19/12/2021
*/
#include <stdio.h>

int main()
{
float celsius, fahrenheit;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("%.2f Fahrenheit = %.2f Celsius",
fahrenheit, celsius);
return 0;
}

Input Output
90 32.22
100 37.78
157 69.44
**Write a C Program to swap two numbers with third variable.**
/* Name : ayush saklani
Section :I
Roll no : 21011352
Date : 19/12/2021
*/
#include<stdio.h>
int main() {
double first, second, temp;
printf("Enter first number: ");
scanf("%lf", &first);
printf("Enter second number: ");
scanf("%lf", &second);
temp = first;
first = second;
second = temp;
printf("\nAfter swapping, first number = %.2lf\n",
first);
printf("After swapping, second number = %.2lf",
second);
return 0;
}

Input Output
10 20 20 10
30 40 40 30
12 23 23 12
**Write a C Program to swap two numbers without using third
variable.**
/*Name : ayush saklani
Section :I
Roll no : 21011352
Date : 19/12/2021
*/
#include <stdio.h>
int main() {
double a, b;
printf("Enter a: ");
scanf("%lf", &a);
printf("Enter b: ");
scanf("%lf", &b);
a = a - b;
b = a + b;
a = b - a;
printf("After swapping, a = %.2lf\n", a);
printf("After swapping, b = %.2lf", b);
return 0;
}

Input Output
10 20 20 10
30 40 40 30
12 23 23 12
** Write a C program to compute the Net Salary of an employee,
(NS=BP+HRA+TA+DA)**
where 'BP' is Basic Pay, 'HRA' is House Rent Allowance, 'TA' is
Travelling Allowance and 'DA' is Dearness Allowance. 
HRA=10% of BP , TA=5%of BP & DA=15%of BP
'BP' is accepted from the keyboard as input.
0 < BP <= 100000
/* Name : ayush saklani
Section :I
Roll no : 21011352
Date : 19/12/2021
*/
#include <stdio.h>
int main() {
double bp,hra,ta,da,ns;
printf("enter basic pay :");
scanf("%lf",&bp);
if(bp>0 && bp<=100000)
{
hra=0.1*bp;
ta=0.05*bp;
da=0.15*bp;
ns=bp+hra+ta+da;
printf("net salary of the employee id
%0.2lf",ns);
}
return 0;
}
Input Output
10000 13000.00
25000 32500.00
35641 46333.30
**Write a C program to calculate the value of f(x) if x has different
ranges of value as given below**
F(x) =x2+2 If 0<=x<=10
F(x) =x2+2x If 11<=x<=20
3
F(x) =x +2x2 If 21<=x<=30
F(x) =0 If X>30

/* Name : ayush saklani


Section :I
Roll no : 21011352
Date : 19/12/2021
*/
#include <stdio.h>
int main()
{
int f,x;
printf("enter the value of x :");
scanf("%d",&x);
if(x>=0&&x<=10)
{
f=x*x +2;
}
else if(x>=11&&x<=20)
{
f=x*x +2*x;
}
else if(x>=21&&x<=30)
{
f=x*x*x + 4;
}
else if(x>30)
{
f=0;
}
printf("the value of f(x) is %d",f);
return 0;
}

Input Output
0 2
25 15629
58 0
**Write a C program to input a character and check whether it is
number, alphabet or a special symbol and display the message
accordingly**
/* Name : ayush saklani
Section :I
Roll no : 21011352
Date : 19/12/2021
*/
#include <stdio.h>
int main() {
char ch;
printf("enter a character:");
scanf("%c",&ch);
if((ch>='a' && ch<='z')||(ch>='A' && ch<='Z'))
{
printf("'%c' is an alphabet.",ch);
}
else if(ch>='0' && ch<='9')
{
printf("'%c' is a digit.",ch);
}
else
{
printf("'%c' is a special character.",ch);
}
return 0;
}
Input Output
a ‘a’ is an alphabet
5 ‘5’ is a digit
+ ‘+’ is a special symbol
**Write a program to input principle, rate and time and find the
simple interest.**

Constraints:
1<=p<=105
1<=r<=10
1<=t<=50
/*Name : ayush saklani
Section :I
Roll no : 21011352
Date : 19/12/2021
*/
#include <stdio.h>
int main() {
float p,r,t,si;
printf("enter the principle ammount :");
scanf("%f",&p);
printf("enter the number of years :");
scanf("%f",&t);
printf("enter the rate of interest :");
scanf("%f",&r);
if(p>=1&&p<=100000&&r>=1&&r<=10t>=1&&t<=50)
{
si=(p*r*t)/100;
printf("\n simple interest : %0.2f",si);
}
return 0;
}
Input Output
10000 5 8 4000.00

15000 6 9 8100.00

55442 6 11.3 37589.68


**Write a program to calculate the area & perimeter of the
rectangle, and the area & circumference of the circle.The length &
breadth of a rectangle and radius of a circle are inputs through the
keyboard.**
Constraints:
1<=l<=50
1<=b<=50
1<=r<=50
/* Name : ayush saklani
Section :I
Roll no : 21011352
Date : 19/12/2021
*/
#include <stdio.h>
int main() {
float l,b,r,ca,cc,ra,rp;
printf("enter the length of rectangle :");
scanf("%f",&l);
printf("enter the breadth of rectangle :");
scanf("%f",&b);
printf("enter the radius of circle :");
scanf("%f",&r);
if(l>=1 && l<=50 && b>=1 && b<=50 && r>=1 &&
r<=50)
{
ra=l*b;
rp=2*(l+b);
ca=3.142*r*r;
cc=2*3.142*r;
printf("\n The area of the rectangle is :
%0.2f",ra);
printf("\n The perimeter of the rectangle is :
%0.2f",rp);
printf("\n The area of the circle is :
%0.2f",ca);
printf("\n The circumference of the circle :
%0.2f",cc);
}
return 0;
}

Input Output
10 5 8 50.00 30.00 201.09 50.27

15 2 5 30.00 34.00 78.55 31.42

22 6 2 132.00 56.00 12.57 12.57

You might also like