Sr.
Date Contents Sign
No.
Write a program to find the square of a
01
number.
02 Write a program to find sum of the number.
Write a program to accept two integer numbers
03 find the greatest number using conditional
operator.
Write a program to execute basic salary from the
04 key word calculate the gross salary that includes
basic salary, 50% DA, 40% HRA, 30% TA of basic
salary.
Write a program to accept a number from the
05
user to calculate the area of the circle.
Write a program to convert temperature from
06
Fahrenheit to Celsius.
Write a program to swap two numbers using
07
third variable.
Write a program to find the factorial of a
08
number.
09 Write a program to display the first n elements
of Fibonacci series.
10 Write a program to check whether a given
string is palindrome or not.
INDEX
1. Write a program to find the square of a number.#include <stdio.h>
#include <conio.h>
void main()
{
int n, sqr;
clrscr();
printf("Enter the number:");
scanf("%d", &n);
sqr=n*n;
printf(“The sum of %d is %d”, n, sqr);
getch();
}
Output:
2. Write a program to find sum of the number.
//To find the sum of the number.
#include <stdio.h>
#include <conio.h>
void main(){
int n_1, n_2, sum;
clrscr();
printf("Enter the first number:");
scanf("%d", &n_1);
printf("Enter the second number:");
scanf("%d", &n_2);
sum=n_1+n_2;
printf("The sum of %d and %d is %d", n_1, n_2, sum);
getch();
}
Output:
3. Write a program to accept two integer numbers find the greatest number using
conditional operator.
//To find the greatest number using conditional operator
#include <stdio.h>
#include <conio.h>
void main(){
int n_1, n_2, great;
clrscr();
printf("Enter the first number:");
scanf("%d", &n_1);
printf("Enter the second number:");
scanf("%d", &n_2);
great=(n_1>n_2)?n_1:n_2;
printf("The greatest number is %d", great);
getch();
}
Output:
4. Write a program to accept a number from the user to calculate the area of the
circle.
//to calculate the area of the circle
#include <stdio.h>
#include <conio.h>
void main(){
float r, area;
clrscr();
printf("Enter the radius:");
scanf("%f", &r);
area=3.14*r*r;
printf(The area of the circle is %.2f.", area);
getch();
}
Output:
5. Write a program to convert temperature from Fahrenheit to Celsius.
//to find gross salary
#include <stdio.h>
#include <conio.h>
void main(){
float Bs, Da, Hra, Ta, Gs;
clrscr();
printf("Enter the Basic salary:");
scanf("%f", &Bs);
Da=.5*Bs;
Hra=.4*Bs;
Ta=.3*Bs;
Gs=Bs+Da+Hra+Ta;
printf("The gross salary is %.2f", Gs);
getch();
}
Output:
6. Write a program to swap two numbers using third variable.
//swap two integers using third variable
#include <stdio.h>
#include <conio.h>
void main(){
int a, b, c;
clrscr();
printf("Enter the first integer:");
scanf("%d", &b);
printf("Enter the second integer");
scanf("%d", &b);
c=a;
a=b;
b=c;
printf("After swapping\nfirst integer is %d\nsecond integer is %d", a, b);
getch();
}
Output:
7. Write a program to find the factorial of a number.
//to find the factorial of a number
#include <stdio.h>
#include <conio.h>
void main(){
int n, i, fact;
clrscr();
printf("Enter the number:");
scanf("%d", &n);
for(i=0, fact=1; i<n; i++){
fact=fact*i;
}
printf("Factorial of %d is %d", n, fact);
getch();
}
Output:
8. Write a program to display the first n elements of Fibonacci series.
//to display first n elements of fibonnaci series
#include <stdio.h>
#include <conio.h>
void main(){
int n, a=0, b=1, c, i;
clrscr();
printf("Enter the number of series:");
scanf("%d", &n);
printf("Fobonnaci series \n0\n1\n");
for(i=2; i<=n-2; i++){
c=a+b;
printf("%d\n", c);
a=b;
b=c;
}
getch();
}
Output:
9. Write a program to check whether a given string is palindrome or not.
//to check whether the string is palindrome or not
#include <stdio.h>
#include <conio.h>
void main(){
char str[100];
int len, revlen;
clrscr();
printf("Enter the string:");
scanf("%s", &str);
len=0;
revlen=strlen(str)-1;
while(len<revlen){
if(str[len++]!=str[revlen--]){
printf("%s is not a palindrome.", str);
}
else{
printf("%s is a palindrome.", str);
}
}
getch();
}
Output
10. Write a program to execute basic salary from the key word calculate
the gross salary that includes basic salary, 50% DA, 40% HRA, 30% TA of
basic salary.
//to find gross salary
#include <stdio.h>
#include <conio.h>
void main()
float Bs, Da, Hra, Ta, Gs;
clrscr();
printf("Enter the Basic salary:");
scanf("%f", &Bs);
Da=.5*Bs;
Hra=.4*Bs;
Ta=3*Bs;
Gs=Bs+Da+Hra+Ta;
printf("The gross salary is %.2f", Gs);
getch();