Study
Study
Formula:
C Code:
#include <stdio.h>
#include <math.h>
int main() {
scanf("%f", &x1);
scanf("%f", &y1);
scanf("%f", &x2);
scanf("%f", &y2);
gdistance = ((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1));
printf("\n");
return 0;
Copy
Sample Output:
Input x1: 25
Input y1: 15
Input x2: 35
Input y2: 10
Distance between the said points: 11.1803
2. Write a C program to convert specified days into years, weeks
and days.
C Code:
#include <stdio.h>
int main()
days = 1329;
years = days/365;
return 0;
Copy
Sample Output:
Years: 3
Weeks: 33
Days: 3
3. Write a C program to read an amount (integer value) and break
the amount into smallest possible number of bank notes.
Note: The possible banknotes are 100, 50, 20, 10, 5, 2 and 1.
C Code:
#include <stdio.h>
int main() {
int amt, total;
printf("Input the amount: ");
scanf("%d",&amt);
total = (int)amt/100;
amt = amt-(total*100);
total = (int)amt/50;
amt = amt-(total*50);
total = (int)amt/20;
amt = amt-(total*20);
total = (int)amt/10;
amt = amt-(total*10);
total = (int)amt/5;
amt = amt-(total*5);
total = (int)amt/2;
amt = amt-(total*2);
total = (int)amt/1;
return 0;
}
Copy
Sample Output:
Input the amount: 375
There are:
3 Note(s) of 100.00
1 Note(s) of 50.00
1 Note(s) of 20.00
0 Note(s) of 10.00
1 Note(s) of 5.00
0 Note(s) of 2.00
0 Note(s) of 1.00
int main() {
int sec, h, m, s;
scanf("%d", &sec);
h = (sec/3600);
m = (sec -(3600*h))/60;
s = (sec -(3600*h)-(m*60));
printf("H:M:S - %d:%d:%d\n",h,m,s);
return 0;
Copy
Sample Output:
Input seconds: 25300
H:M:S - 7:1:40
5. Write a C program that read 5 numbers and sum of all odd
values between them.
C Code:
#include <stdio.h>
int main() {
int j, numbers[5],total=0;
scanf("%d", &numbers[0]);
scanf("%d", &numbers[1]);
scanf("%d", &numbers[2]);
scanf("%d", &numbers[3]);
scanf("%d", &numbers[4]);
if((numbers[j]%2) != 0)
total += numbers[j];
printf("\n");
return 0;
Copy
Sample Output:
Input the first number: 11
6. write a c program that will compute the final price of a product after putting
the original price and percentage of discount.
7. write a c program that will convert inches to centimetre and vice versa
#include <stdio.h>
#include <stdlib.h>
int main()
{
float in_cm;
char in_inches[4];
in_cm = atoi(in_inches)*2.54;
}
To compile the code with gcc:
Exmaple run:
$ ./inches_cm
Convert inches: 12
30.48 cm
$ ./inches_cm
1431234.12 cm
8. write a c program that will convert meter to kilometer and vice versa
Centimeter to meter and centimeter to kilometer conversion formula is given by -
#include <stdio.h>
int main()
{
float cm, meter, km;
return 0;
}
Example
Input
Enter length in centimeter = 1000
Output
Length in meter = 10 m
Length in kilometer = 0.01 km
9. C program to convert pounds to kilograms
#include <stdio.h>
#define POUNDTOKG 0.453592
int main() {
float pound, kilogram;
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter weight in pound:2.20462
2.20 pound = 1.00 KiloGram
C program to find the mean,median and mode of a
set of numbers
Share16
#include<stdio.h>
main()
{
int i,j,a[20]={0},sum=0,n,t,b[20]={0},k=0,c=1,max=0,mode;
float x=0.0,y=0.0;
printf("\nEnter the limit\n");
scanf("%d",&n);
printf("Enter the set of numbers\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
x=(float)sum/(float)n;
printf("Mean\t= %f",x);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
if(n%2==0)
y=(float)(a[n/2]+a[(n-1)/2])/2;
else
y=a[(n-1)/2];
printf("\nMedian\t= %f",y);
for(i=0;i<n-1;i++)
{
mode=0;
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
{
mode++;
}
}
if((mode>max)&&(mode!=0))
{
k=0;
max=mode;
b[k]=a[i];
k++;
}
else if(mode==max)
{
b[k]=a[i];
k++;
}
}
for(i=0;i<n;i++)
{
if(a[i]==b[i])
c++;
}
if(c==n)
printf("\nThere is no mode");
else
{
printf("\nMode\t= ");
for(i=0;i<k;i++)
printf("%d ",b[i]);
}
}
C Program to Calculate the Mean, Variance & Standard
Deviation
#include <stdio.h>
#include <math.h>
#define MAXSIZE 10
void main()
{
float x[MAXSIZE];
int i, n;
float average, variance, std_deviation, sum = 0, sum1 = 0;
$ cc pgm23.c -lm
$ a.out
Enter the value of N
5
Enter 5 real numbers
34
88
32
12
10
Average of all elements = 35.20
variance of all elements = 794.56
Standard deviation = 28.19