TCS Practical
TCS Practical
TCS Practical
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.**
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
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
Input Output
10 5 8 50.00 30.00 201.09 50.27