WRITE A PROGRAM TO CALCULATE THE DISTANCE BETWEEN TWO POINTS.
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
int x1, x2, y1, y2 ;
int distance;
printf("\n Eenter the x and y coordiantes of the first point (x1): ") ;
scanf("%d", &x1) ;
printf("\n Eenter the x and y coordiantes of the first point ( y1): ") ;
scanf("%d", &y1) ;
printf("\n Eenter the x and y coordiantes of the second point (x2): ") ;
scanf("%d", &x2) ;
printf("\n Enter the x and y coordiantes of the second point ( y2): ") ;
scanf("%d", &y2) ;
//sqrt and pow are mathematical functions defined in math.h header file
distance =sqrt(pow((x2-x1), 2) + pow((y2-y1), 2)) ;
printf ("\n Distance = %d", distance) ;
return 0;
}
WRITE A PROGRAM TO DEMONSTRATE THE USE OF printf OF VALUES OF VARIABLES OF DIFFERENT
DATA TYPS
#include <stdio.h>
main()
//Declare and initialize variabels
int num = 7 ;
float amt = 123.45 ;
char code = 'A' ;
double pi = 3.1415926536 ;
long int population_of_india = 10000000000 ;
char msg[] = "Hi"
//prient the values of variables
printf("\n NUM = %d \t AMT = %f \t CODE = %c \n PI = %e \t POPULATION OF INDIA = %ld \n
MESSAGE = %s" , num, amt, code, pi, population_of_india, msg) ;
return 0;
Write a program. to calculate the area of a triangle using heros fourmula .
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
float a, b, c, area, S;
printf("\n Enter the lengths of the first sides of the triangle :");
scanf("%f", &a);
printf("\n Enter the lengths of the second sides of the triangle :");
scanf("%f", &b);
printf("\n Enter the lengths of the third sides of the triangle :");
scanf("%f", &c);
S = (a + b + c)/2;
//sqrt is a methematical function defined in matn.h header file
area = sqrt (S* (S-a)*(S-b)*(S-c));
printf("\n Area + %f", area);
return 0;
Write a program to perform addition, subtraction, division, integer division, multiplication, and
modulo division on two integer numbers.
#include <stdio.h>
#include <conio.h>
int main()
int num1, num2;
int add_res = 0, sub_res = 0, mul_res = 0, idiv_res = 0, modiv_res = 0;
float fdiv_res = 0.0;
printf("\n Enter the first number : ") ;
scanf("%d" , &num1) ;
printf("\n Enter the second number : ") ;
scanf("%d" , &num2) ;
add_res = num1 + num2;
sub_res = num1 - num2;
mul_res = num1 * num2;
idiv_res = num1 / num2;
modiv_res = num1 % num2;
fdiv_res = (float)num1 / num2;
printf("\n %d + %d = %d",num1 , num2, add_res);
printf("\n %d - %d = %d",num1 , num2, sub_res);
printf("\n %d * %d = %d",num1 , num2, mul_res),
printf("\n %d / %d = %d (Integer division)", num1, num2, idiv_res);
printf("\n %d %% %d = %d (Moduluo division)", num1, num2, modiv_res);
printf("\n %d / %d = %.2f (Normal division)", num1, num2, fdiv_res);
return 0;
}
Write a program to perform addition, subtraction, division, and multiplication on two floating
point numbers
#include <stdio.h>
#include <conio.h>
int main()
float num1, num2;
printf("\n Enter the first number: ");
scanf("%f", &num1);
printf("\n Enter the second number: ");
scanf("%f", &num2);
printf("\n %f + %f = %f", num1, num2, num1 + num2);
printf("\n %f - %f = %f", num1, num2, num1 - num2);
printf("\n %f * %f = %f", num1, num2, num1 * num2) ;
printf("\n %f / %f = %f ", num1, num2, num1 / num2);
return 0;
}
WRITE A PROGRAM TO SUBTRACT TWO LONG INTEGERS.
#include <stdio.h>
#include <conio.h>
int main()
long int num1 = 123456 , num2, diff = 0;
printf("/n Enter the number:");
scanf("%ld" , &num2);
diff = num1 - num2;
printf("\n Differnce = %ld", diff);
return 0;
}
Write a program to illustrate the use of unary prefix increment and decrement opreators.
#include <stdio.h>
main()
int num = 3;
//Using unary prefix increment opretor
printf("\n The value of num = %d",num);
printf("\n The value of ++num = %d",++num);
printf("\n The new value of num = %d",num);
//using unary prefix decrement operator
printf("\n\n The value of num = %d",num);
printf("\n The value of --num = %d",--num);
printf("\n The new value of num = %d",num);
return 0;
}
Write a program to find the largest of two numbers using the ternary operators.
#include <stdio.h>
#include <conio.h>
int main()
int num1, num2, large;
printf("\n Enter the first number: ");
scanf("%d", &num1);
printf("\n Enter the second number: ");
scanf("%d", &num2);
large = num1>num2? num1: num2;
printf("\n The largest number is: %d", large);
return 0;
}
Write a program to calculate the area of the circle
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
float radius,area;
printf("\n Enter the radius of the circle:");
scanf("%f",&radius);
area = 3.14 * radius * radius;
printf("\n Area = %f", area);
return 0;
}
Write a program to find Uppercase
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
char ch;
printf("\n Enter the Upper case char:");
scanf("%c", &ch);
ch=ch-32;
printf("\n Enter the lower case char:% c",ch);
return 0;
}
Write a program to swap two number using a temporary variable.
#include <stdio.h>
#include <conio.h>
int main()
int num1, num2, temp;
printf("\n Enter the first number:");
scanf("%d", &num1);
printf("\n Enter the second number:");
scanf("%d", &num2);
temp = num1;
num1 = num2;
num2 = temp;
printf("\nThe first number is %d",num1);
printf("\nThe second number is %d",num2);
return 0;
}
Write a program to swap two number with using a temporary variable.
#include <stdio.h>
#include <conio.h>
int main()
int num1, num2;
printf("\n Enter the first number:");
scanf("%d", &num1);
printf("\n Enter the second number:");
scanf("%d", &num2);
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;
printf("\nThe first number is %d",num1);
printf("\nThe second number is %d",num2);
return 0;
}
Write a program to convert an intiger in to the corresponding floating point number.
#include <stdio.h>
#include <conio.h>
int main()
float f_num;
int i_num;
printf("\n Enter eney integer");
scanf("%d",&i_num);
f_num = (float) i_num;
printf("\n enter the floting point variable %d is = %f",f_num, i_num);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
int num, pow;
int result = 1;
int i;
printf("Enter number: ");
scanf("%d", &num);
printf("Enter power: ");
scanf("%d", &pow);
for (i=1; i<=pow; i++)
result = result * num;
printf("%d in the Power of %d = %d\n", num, pow, result);
return 0;
}
Write a program to find whether the given number is even or odd
#include <stdio.h>
#include <conio.h>
int main()
int num;
printf("\n Eter any number ");
scanf("%d", &num);
{if(num %2 == 0)
printf("\n %d is an even number ", num);
else
printf("\n %d is an odd number", num);
return 0;
}
Write a program that accepts a number from 1 to [Link] whether the number is even or odd
using a switch case construct
#include <stdio.h>
Int main()
int num;
printf("\n Enter eney number (1 to 10): ");
scanf("%d", &num);
switch(num)
case 1:
case 3:
case 5:
case 7:
case 9:
printf("\n ODD");
break;
case 2:
case 4:
case 6:
case 8:
case 10:
printf("\n EVEN");
default:
printf("\n INVALID INPUT");
break;
return 0;