C Pratical
C Pratical
Write
a program in c languge to computer b=2*p
#include<stdio.h>
#include<conio.h>
int main()
{ out put
const float p=3.1459; 6.29
float b;
b=2*p;
printf(" the value of b is % 5.2f",b);
getch();
}
Q2. write a program to input a number and check whether it is even or odd using if else
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter an integer\n");
scanf("%d", &n);
if (n%2 == 0)
printf("%d is Even\n",n);
else
printf("%d is Odd\n",n);
getch();
}
Q3. write a program that inputs salary and grade. it adds 50% bonus if the grade is
greater than 15 . it adds 25% bonus if the grade is 15 or less and then displays the total salary.
#include<stdio.h>
#include<conio.h>
int main()
{ float salary, bonus;
int grade;
printf("Enter your salary\n");
scanf("%f", &salary);
printf("Enter your grade\n");
scanf("%d ",&grade);
if (grade > 15)
bonus = salary * 50.0/100.0
else
bonus = salary * 25.0/100.0;
salary = salary+bonus;
printf ("Your total salary is Rs %2f", salary);
getche();
}
include<stdio.h>
#include<conio.h>
int main()
{
int i;
for(i = 1; i <= 10; i = i + 1)
{
printf("%d %d\n", i, i * i);
}
return 0;
1
Q5. Write a program that inputs temperature and displays a message follows
Temperature Message
Greater then 35 Hot day
Between 25 and 35 (inclusive) Pleasant day
Less than 25 Cool day
#include<stdio.h>
#include<conio.h>
int main()
float temp;
printf(" Enter Temperature");
scanf("%f",&temp);
if(temp>35)
printf("it is a Hot Day");
else if(temp<=35 && temp>=25)
printf("It is a Pleasant Day");
else
printf("Cool day");
getch();
Q6
write a program that inputs two numbers and one arithmetic operator applied arithmetic
operation on two numbers
#include<stdio.h>
#include<conio.h>
int main()
{
char op;
int a, b;
printf(" Enter 1st no1,operator,and No 2\n");
scanf("%d %c %d ", &a ,&op, &b);
switch(op)
{
case '+':
printf("%d+%d=%d", a,b,a+b);
break;
case '-':
printf("%d-%d=%d", a,b,a-b);
break;
case '*':
printf("%d*%d=%d", a,b,a*b);
break;
case '/':
printf("%d / %d=%d", a,b,a/b);
break;
case '%':
printf("%d %% %d=%d", a,b,a%b);
break;
defaulta
printf("Error! operator is not correct");
}
getch();
2
Q7..write a program in c to find out the minimum and maximum value enter through
keyboard.
#include <stdio.h>
int main()
{
double n1, n2, n3;
printf("Enter three different numbers: ");
scanf("%lf %lf %lf", &n1, &n2, &n3);
if( n1>=n2 && n1>=n3 )
printf("%.2f is the largest number.", n1);
if( n2>=n1 && n2>=n3 )
printf("%.2f is the largest number.", n2);
if( n3>=n1 && n3>=n2 )
printf("%.2f is the largest number.", n3);
if( n1<=n2 && n1<=n3 )
printf("%.2f is the smallest number.", n1);
if( n2<=n1 && n2<=n3 )
printf("%.2f is the smallest number.", n2);
if( n3<=n1 && n3<=n2 )
printf("%.2f is the smallest number.", n3);
return 0;
}
Q9.
While purchasing certain items, a discount of 10% is offered if the quantity purchased is
more than 1000. If quantity and price per item are input through the keyboard, write a
program to calculate the total expenses.
#include<stdio.h>
#include<conio.h>
int main()
{
int qty, dis = 0;
float rate, expense;
if (qty>1000)
dis = 10;
expense= (qty*rate) - (qty*rate*dis / 100);
printf("\nTotal Expenses = Rs. %f", expense);
getch(); }
3
Q10 C Program to Find all Roots of a Quadratic Equation
#include<stdio.h>
#include<conio.h>
int main()
{
int a, b, c, d;
double x1, x2;
printf("Enter a, b and c \n");
scanf("%d %d %d", &a, &b, &c);
d = b*b - 4*a*c;
if (d < 0) {
printf("both roots are imagery ");
}
else {
x1 = (-b + sqrt(d))/(2*a);
x2 = (-b - sqrt(d))/(2*a);
return 0;
}
#include<stdio.h>
#include<conio.h>
int main()
{
float cel, fh;
getch();
}
4
Q12. Write a program that finds sum of the square of integer while n is a positive number
entered by the user
#include<stdio.h>
#include<conio.h>
int main()
{
int n, c;
long int sum;
sum = 0;
printf("Enter a number: ");
scanf("%d",&n);
for(c= 1; c<=n; c++)
sum = sum + (c * c);
printf("Sum is %d \n", sum);
getch();
}
Q13
#include<stdio.h>
#include<conio.h>
#include <math.h>
int main()
{
int c, s, e;
printf("Enter starting number: ");
scanf("%d", &s);
printf("Enter ending number: ");
scanf("%d", &e);
c=s;
do
{ if(c%2!=0)
printf("%d\n",c);
c= c + 1;
}
while(c<=e);
getch();
}
5
Q15.write a program that inputs a number from the user and display a tables of that
number using while loop
#include<stdio.h>
#include<conio.h>
int main()
{ int n, c ;
c = 1;
printf("Enter a number: ");
scanf("%d",&n);
while(c <= 10)
{ printf(" %d * %d = %d \n", n,c, n*c);
c = c + 1;
}
getch(); }
Q16.
#include<stdio.h>
#include<conio.h>
int main()
{
int n, c, f;
c = 1;
f= 1 ;
printf("Enter a number: ");
scanf("%d",&n);
{
while(c <= n)
{
f= f*c;
c++;
}
printf ("Factorial of %d is %d", n,f);
} getch(); }
Q17
#include<stdio.h>
#include<conio.h>
#include <math.h>
int main()
{
float a, b, c; double s, area;
printf("Enter side A: ");
scanf("%f", &a);
printf("Enter side B: ");
scanf("%f", &b); printf("Enter side C: ");
scanf("%f", &c);
s = (a + b + c)/2.0;
area = sqrt(s * (s - a) * (s-b) * (s - c));
printf("Area of triangle is %f", area);
getch();
}
6
Q19.Display the following pattern
include<stdio.h>
#include<conio.h>
int main()
{ int i, j;
for(i=0;i<=5; i++)
{
for(j=0; j<=i; j++)
printf("%d", j);
printf("\n");
}
getch(); }
Q20.
#include<stdio.h>
#include<conio.h>
int main()
{
int x, y, temp;
printf("Enter two numbers:");
scanf("%d %d", &x, &y);
printf("Value in x: %d\n", x);
printf("Value in y: %d \n", y);
temp = x; x = y;
y = temp;
printf("Value in x after exchange: %d\n", x) ;
printf("Value in y after exchange: %d \n", y) ;
getche();
}
Q21. write a program in c to input three integers through keyboard. Check whether the
number are same or different
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf(" Enter the three numbers ");
scanf("%d %d %d",&a,&b,&c);
if (a==b&&b==c)
printf(" All three numbers are same");
else
printf(" All three numbers are differentl ");
getch();
7
Q22 the marks obtained by a student in five different subjects are input through the
keyboard write a program in c to calculate the division obtained by student
#include<stdio.h>
#include<conio.h>
int main ()
{
float a,b,c,d,e,f;
float p;
printf ("Enter marks of five subject: ");
scanf ("%f %f %f %f %f", &a,&b,&c,&d,&e);
p = ((a+b+c+d+e)/500)*100;
printf ("\nPercentage= %f \%",p);
if(p >= 60)
{
printf(" You got first devision");
}
else if ( p>=50)
{
printf(" You second devision");
}
else if ( p >=40)
{
printf(" You got third devion ");
}
else
if ( p < 40)
{
printf(" You Failed in this exam");
}
getch ();
}
#include<stdio.h>
#include<conio.h>
int main ()
{
int a,b,z;
printf ("Enter the value of a ");
scanf ("%d" ,&a);
printf ("Enter the value of b ");
scanf ("%d ",&b);
z=--a+b--;
printf (" the value of Expression is z= %d",z);
getch();
}
Out put
Enter the value of a 6
Enter the value of b 6
the value of Expression is z= 11
8
Q24 write a program in C language to input marks of Mathematics and English through
keyboard. It display GREAT if both are 80 or above .Good if only Mathematics is 80 or
above .and BAD other wise
#include<conio.h>
int main ()
{
int eng,math;
printf ("Enter marks of ENGLISH: ");
scanf ("%d",&eng);
printf ("Enter marks of Math: ");
scanf ("%d",&math);a
if(eng>= 80 && math>=80)
{
printf(" GREAT");
}
else if
(eng<80 && math>=80)
{
printf(" GOOD");
} else
{
printf(" BAD");
} getch (); }
Q24. C Program to Find the Volume of cylinder using constant qualifier
#include <stdio.h>
#include <math.h>
int main()
{
float radius, height;
const float p=3.1459;
float volume;
printf("Enter value for radius and height of a cylinder : \n");
scanf("%f%f", &radius, &height);
volume = p * radius * radius * height;
printf("\n Volume of cylinder is : %.3f", volume);
return 0;
}
Output
Enter value for radius and height of a cylinder
3
5
Volume of cylinder is 141.566
9
Q26. WRITE A PROGRAM TO PRINT THE SUM OF SERIES 1 + 1/2 + 1/3 + 1/4 + ... +
1/100.
#include<stdio.h>
#include<conio.h>
int main()
{
float sum=1.0,i
for(i=2;i<=100;i++)
{
sum = sum + (1/i);
}
printf("\n\n THE SUM OF THIS SERIES IS %.2lf",sum);
getch();
}
Output
THE SUM OF THIS SERIES IS 5.19
Q27. write a programming c to put a single digit (0-9) through keyborad display the value
in words
#include <stdio.h>
#include<conio.h>
int main()
{
int num ;
printf("Enter any number to print in words: ");
scanf("%d", &num);
switch(num)
{
case 0:
printf("Zero ");
break;
case 1:
printf("One ");
break;
case 2:
printf("Two ");
break;
case 3:
printf("Three ");
break;
case 4:
printf("Four ");
break;
case 5:
printf("Five ");
break;
case 6:
printf("Six ");
break;
case 7:
printf("Seven ");
break;
case 8:
printf("Eight ");
break;
case 9:
printf("Nine ");
break;
} }
10
Q28.
Write a program that a number. It displays first number is the square of second number ".
#include<stdio.h>
#include<conio.h>
int main( )
{ int n1,n2;
printf("Enter the first number: ");
scanf("%d",&n1);
printf("Enter second number: ");
scanf("%d",&n2);
if(n1==n2*n2)
printf (" the first number %d is the square of second number %d number ",n1,n2);
getch();
Q29 Write a program that a number. It displays square root of the number if the number
is positive. Otherwise the program displays a message 'invalid input".
#include<stdio.h>
#include<conio.h>
#include <math.h>
int main( )
{ int x = 0;
double sqroot=0.0;
printf("Enter a number: ");
scanf("%d",&x);
if(x>=0)
{ sqroot=sqrt(x);
printf ("The square root of %d is = %lf",x,sqroot);
} else printf("Invalid input.");
getch(); }
Q30.
Write a program in c to assign three values to three integer type variable x,y,z .Add values
of variable x,y and multiply their sum to the value of variable z
#include <stdio.h>
#include <conio.h>
int main()
{
int a,b,z,sum;
printf("Enter the number a :");
scanf("%d",&a);
printf("Enter the number b :");
scanf("%d",&b);
printf("Enter the number z :");
scanf("%d",&z);
sum=a+b;
z= sum*z;
printf("\n value of z after multiply with sum of %d is = %d",sum,z);
return 0;
}
11
Q31. Write a program in c to for producing integer in the range 0 TO N by using loop
structure .where n is a given number
#include <stdio.h>
#include <conio.h>
int main()
{
int n,c;
printf("Enter the number n :");
scanf("%d",&n);
c=0;
while(c<=n)
{
printf("%d\n",c);
c=c+1;
}
getch();
}
Q32. Program to print number of days in month
#include <stdio.h>
#include <conio.h>
int main()
{
int monno;
printf("Input Month No : ");
scanf("%d",&monno);
switch(monno)
{
case 1:
printf("January and days are 31 \n");
break;
case 2:
printf("February and days are 28 or 29 \n");
break;
case 3:
printf("Marchdays are 31\n");
break;
case 4:
printf("Aprildays are 30\n");
break;
case 5:
printf("Maydays are 31\n");
break;
case 6:
printf("Junedays are 30\n");
break;
case 7:
printf("Julydays are 31\n");
break;
case 8:
printf("Augustdays are 31\n");
break;
case 9:
printf("Septemberdays are 30\n");
break;
case 10:
printf("Octoberdays are 31\n");
break;
case 11:
printf("Novemberdays are 30\n");
break;
12
case 12:
printf("Decemberdays are 31\n");a
break;
default:
printf("invalid Month number. \nPlease try again ....\n");
break;
}
getch();
}
Write a program, that inputs radius of sphere from the user and display
volume and surface area using formula.
#include<stdio.h>
#include<conio.h>
int main()
{
Write a program that inputs table number and length of table and then displays the table
using for loop
#include<stdio.h>
#include<conio.h>
int main()
{
34. Write a program that inputs a year and finds whether it is a leap year or not using if-
else structure.
#include<stdio.h>
#include <conio.h>
int main()
{ int y;
printf("Enter a year: ");
scanf("%d",&y);
if(y % 4 == 0)
printf("%d is a leap year.",y);
else
printf("%d is not a leap year.",y);
getch(); }
13
14