Professional Documents
Culture Documents
Question 1.
Code:
#include<stdio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
float a,b;
scanf("%f",&a);
b= a+ 0.6*a ;
printf(" Gross salary is : %.2f",b);
}
Output :
Question 2.
Aim: The distance between two cities (in km.) is input through
the keyboard. Write a program to convert and print this
distance in meters, feet, inches and centimeters .
Code :
#include<stdio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
float a;
scanf("%f",&a);
printf(" in m %.2f\n",a*1000);
printf("in feet %.2f\n",a*3281);
printf(" in inch %.2f\n",a*39370);
printf("in cm %.2f",a*100000);
}
Output :
Question 3.
Aim : If the marks obtained by a student in five different
subjects are input through the keyboard, find out the aggregate
marks and percentage marks obtained by the student. Assume
that the maximum marks that can be obtained by a student in
each subject is 100.
Code :
#include<stdio.h>
#include<conio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
float a,b,c,d,e;
printf("Enter the marks out of 100 in five subjects of the student : ");
scanf("%f%f%f%f%f", &a,&b,&c,&d,&e);
//his total marks
printf("\n%f is the aggregate marks obtained by him.", a+b+c+d+e);
//his percentage marks
printf("\n%f is the percentage marks obtained by him.", (a+b+c+d+e)/5);
getch();
return 0;
}
Output :
Question 4.
Aim : Temperature of a city in Fahrenheit degrees is input
through the keyboard. Write a program to convert this
temperature into Centigrade degrees.
Code :
#include<stdio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
float a;
scanf("%f",&a);
a=(a-32)*(5.0/9);
printf("%f",a);
}
Output :
Question 5.
Aim : The length & breadth of a rectangle and radius of a circle
are input through the keyboard. Write a program to calculate
the area & perimeter of the rectangle, and the area &
circumference of the circle
Code :
#include<stdio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
float a,b,c;
float k=3.14;
scanf("%f %f %f",&a,&b,&c);
printf(" The Area of rectangle is = %f\n The Perimeter of rectangle = %f\n
The Circumference of circle is = %f\n The Area of circle is = %f\n",a*b,2*(a+b
),2*k*c,k*c*c);
}
Output :
Question 6.
Aim : Two numbers are input through the keyboard into two
locations C and D. Write a program to interchange the contents
of C and D.
Code :
#include<stdio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
int c,d;
printf("Enter the value of C & D :");
scanf("%d %d",&c,&d);
c=c+d;
d=c-d;
c=c-d;
printf("%d %d",c,d);
}
Output :
Question 7.
Aim : If a five-digit number is input through the keyboard,
write a program to calculate the sum of its digits. (Hint: Use the
modulus operator ‘%’).
Code :
#include<stdio.h>
int main()
{
int num,sum,a,b,c,d,e,d1,d2,d3,d4,d5;
/*num=entered number,sum=sum of all digits,d1=1st digit,d2=2nd digit,d3=3rd
digit,d4=4th digit,d5=5th digit*/
printf(" Harsh Verma\n 20001016018\n -----------\n");
printf("Enter any five digit number : ");
scanf("%d",&num);
a=num/10;
d5=num%10;
b=a/10;
d4=a%10;
c=b/10;
d3=b%10;
d=c/10;
d2=c%10;
e=d/10;
d1=d%10;
sum=d1+d2+d3+d4+d5;
printf("\nSum of digits of given number is %d",sum);
}
Output :
Question 8.
Aim : If a five-digit number is input through the keyboard,
write a program to reverse the number.
Code :
#include<stdio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
printf("Enter a five digit number\n");
int a,r,sum=0;
scanf("%d",&a);
while(a>0)
{
r=a%10;
sum=sum*10 + r;
a=a/10;
}
printf("New reversed number is = " "%d",sum);
}
Output :
Question 9.
Aim : If a four-digit number is input through the keyboard,
write a program to obtain the sum of the first and last digit of
this number.
Code :
#include<stdio.h>
int main()
{
int num,sum,a,b,c,d,d1,d2,d3,d4;
printf(" Harsh Verma\n 20001016018\n -----------\n");
printf("Enter any four digit number : ");
scanf("%d",&num);
a=num/10;
d4=num%10;
b=a/10;
d3=a%10;
c=b/10;
d2=b%10;
d=c/10;
d1=c%10;
sum=d1+d4;
printf("Sum of 1st and 4th digit = %d",sum);
}
Output :
Question 10.
Aim : In a town, the percentage of men is 52. The percentage of
total literacy is 48. If total percentage of literate men is 35 of the
total population, write a program to find the total number of
illiterate men and women if the population of the town is
80,000.
Code :
#include<stdio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
float p=80000;
float m,n;
m=0.17*p;
n=0.35*p;
printf(" No. of Illitrate Men %f \n No. of Illitrate Women % f ",m,n);
}
Output :
Question 11.
Aim : A cashier has currency notes of denominations 10, 50
and 100. If the amount to be withdrawn is input through the
keyboard in hundreds, find the total number of currency notes
of each denomination the cashier will have to give to the
withdrawer.
Code :
#include<stdio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
int amnt,a,b,k;
scanf("%d",&amnt);
a=amnt/100;
amnt=amnt%100;
b=amnt/50;
amnt=amnt%50;
k=amnt/10;
amnt=amnt%10;
if(amnt!=0)
{
printf("-1");
}
else
{
printf("No. of notes of Rs.100: %d \n No. of notes of Rs.50: %d \n N
o. of notes of Rs.10: %d",a,b,k);
}
}
Output :
Question 12.
Aim : If the total selling price of 15 items and the total profit
earned on them is input through the keyboard, write a program
to find the cost price of one item.
Code :
#include<stdio.h>
int main()
{
int sp,tp,cp,cp1;
/*sp=selling price of 15 items,tp=total profit,
cp=cost price of 1 item,cp1=cost price of 1 item*/
printf(" Harsh Verma\n 20001016018\n -----------\n");
printf("Enter total selling price of 15 items : ");
scanf("%d",&sp);
printf("Enter profit on selling 15 items : ");
scanf("%d",&tp);
cp=sp-tp;
cp1=cp/15;
printf("Cost price of one item is %d",cp1);
}
Output :
Question 13.
Aim : If a five-digit number is input through the keyboard,
write a program to print a new number by adding one to each of
its digits. For example if the number that is input is 12391 then
the output should be displayed as 23402.
Code :
#include<stdio.h>
int main()
{
printf(" Harsh Verma\n 20001016018\n -----------\n");
int a,k,sum=0,r,temp=0;
scanf("%d",&a);
while(a>0)
{
k=a%10;
k=k+1;
if(k==10)
{
k=0;
}
sum=sum*10 +k;
a=a/10;
}
while(sum>0)
{
r=sum%10;
temp=temp*10 +r;
sum=sum/10;
}
printf("%d",temp);
}
Output :
int main(){
printf(" Harsh Verma\n 20001016018\n -----------\n");
float cp , sp ;
scanf("%f" , &cp ) ;
scanf("%f" , &sp ) ;
if(sp>=cp){
printf("You have made profit of %f \n" , sp-cp ) ;
}
else{
printf("You have made loss of %f \n" , cp-sp ) ;
}
return 0;
Output :
Question : 2
Aim : Any integer is input through the keyboard. Write a
program to find out whether it is an odd number or even
number.
Code :
#include<stdio.h>
int main(){
int num ;
scanf("%d", &num);
if(num%2==0)
printf("%d is an even number \n", num );
else
printf("%d is an odd number \n", num );
return 0;
Output :
Question : 3
Aim : Any year is input through the keyboard. Write a
program to determine whether the year is a leap year or not.
(Hint: Use the % (modulus) operator)
Code :
#include <stdio.h>
int main() {
int year;
scanf("%d",&year);
if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))
printf("%d is a leap year", year);
else
printf("%d is not a leap year", year);
return 0;
Output :
Question : 4
Aim : According to the Gregorian calendar, it was Monday on
the date 01/01/1900. If any year is input through the keyboard
write a program to find out what is the day on 1st January of
this year
Code :
#include <stdio.h>
int main()
int year, basic_year = 1900, leap_year, remaining_year, total_days, day;
printf("Enter the year: ");
scanf("%d", &year);
year = (year - 1) - basic_year;
leap_year = year / 4;
remaining_year = year - leap_year;
total_days = (remaining_year * 365) + (leap_year * 366) + 1;
day = total_days % 7;
if (day == 0)
printf("Monday");
else if (day == 1)
printf("Tuesday");
else if (day == 2)
printf("Wednesday");
else if (day == 3)
printf("Thursday");
else if (day == 4)
printf("Friday");
else if (day == 5)
printf("Saturday");
else if (day == 6)
printf("Sunday");
else
printf("Wrong Entry");
return 0;
Output :
Question : 5
Aim : A five-digit number is entered through the keyboard.
Write a program to obtain the reversed number and to
determine whether the original and reversed numbers are equal
or not.
Code :
#include <stdio.h>
int main()
int num, a, b, c, d, e, x;
printf("Enter a five digit number : ");
scanf("%d", &num)
e = num % 10;
d = (num / 10) % 10;
c = (num / 100) % 10;
b = (num / 1000) % 10;
a = (num / 10000);
x = e * 10000 + d * 1000 + c * 100 + b * 10 + a;
printf("\n%d", x);
if (x == num)
printf("\n\nThe reverse of the number %d is same as actual number.", n
um);
return 0;
Output :
Question : 6
Aim : If the ages of Ram, Shyam and Ajay are input through
the keyboard, write a program to determine the youngest of the
three.
Code :
#include <stdio.h>
int main()
int ram, shyam, ajay;
printf("Enter the age of Ram, Shyam and Ajay respectively : \n");
scanf("%d%d%d", &ram, ­am, &ajay);
if (ram < shyam && ram < ajay)
printf("Ram is youngest among all.");
else if (shyam < ram && shyam < ajay)
printf("Shyam is youngest among all.");
else
printf("Ajay is youngest among all.");
return 0;
Output :
Question : 7
Aim : Write a program to check whether a triangle is valid or
not, when the three angles of the triangle are entered through
the keyboard. A triangle is valid if the sum of all the three
angles is equal to 180 degrees.
Code :
#include <stdio.h>
int main()
int a1, a2 , a3;
printf("Enter the angles of Triangle in Degrees.\n");
scanf("%d %d %d", &a1, &a2, &a3);
if (a1 + a2 + a3 == 180)
{
printf("Triangle is Valid.");
}
else
{
printf("Triangle is Invalid.");
}
return 0;
Output :
Question : 8
Aim : Find the absolute value of a number entered through
the keyboard.
Code :
#include <stdio.h>
#include <math.h>
int main()
int number;
printf("Enter number\n");
scanf("%d", &number);
printf("Absolute value of %d is %d.", number, abs(number));
return 0;
Output :
Question : 9
Code :
#include <stdio.h>
int main()
int l, b;
printf("Enter length and breadth of rectangle\n");
scanf("%d %d", &l, &b);
if ((l * b) > (2 * (l + b)))
{
printf("Area is Greater than perimeter\n");
}
else
{
printf("Area is not Greater than perimeter\n");
}
return 0; }
Output :
Question : 10
Aim : Given three points (x1, y1), (x2, y2) and (x3, y3), write a
program to check if all the three points fall on one straight line.
Code :
#include <stdio.h>
int main()
float x1, y1, x2, y2, x3, y3;
printf("Enter coordinates (x1,y1)\n");
scanf("%f %f", &x1, &y1);
printf("Enter coordinates (x2,y2)\n");
scanf("%f %f", &x2, &y2);
printf("Enter coordinates (x3,y3)\n");
scanf("%f %f", &x3, &y3);
if ((y2 - y1) / (x2 - x1) == (y3 - y1) / (x3 - x1))
{
printf("Point lies on straight line");
}
else
{
printf("Points don't lie on straight line");
}
return 0;
Output :
Question : 11
Aim : Given the coordinates (x, y) of a center of a circle and
it’s radius, write a program which will determine whether a
point lies inside the circle, on the circle or outside the circle.
Code :
#include <stdio.h>
#include <math.h>
int main()
float cenx, ceny, radius, x, y, d;
printf("Enter Center x,y coodinate and radius\n");
scanf("%f %f %f", &cenx, &ceny, &radius);
printf("Enter coordinates of point\n");
scanf("%f %f", &x, &y);
d = sqrt(pow((cenx - x), 2.0) + pow((ceny - y), 2.0));
if (d < radius)
{
printf("Point is inside circle\n");
}
else if (d == radius)
{
printf("Point is on the circle\n");
}
else if (d > radius)
{
printf("Point is outside the circle\n");
}
return 0; }
Output :
Question : 12
Aim : Given a point (x, y), write a program to find out if it lies
on the x-axis, y-axis or at the origin, viz. (0, 0).
Code :
#include <stdio.h>
int main()
float x, y;
printf("Enter the x-y coordinates of the point : ");
scanf("%f%f", &x, &y);
if (x == 0 && y == 0)
printf("\nThe point is on the origin.");
if (x == 0 && y != 0)
printf("\nThe point lie on the y-axis");
if (x != 0 && y == 0)
printf("\nThe points lie on the x-axis");
if (x != 0 && y != 0)
printf("\nThe points lie on the plane");
return 0;
Output :
(F) Question : 1
Code :
#include <stdio.h>
int main() {
int year;
scanf("%d",&year);
if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))
printf("%d is a leap year", year);
else
printf("%d is not a leap year", year);
return 0;
Output :
Question : 2
Aim : Any character is entered through the keyboard, write a
program to determine whether the character entered is a capital
letter, a small case letter, a digit or a special symbol.
Code :
#include<stdio.h>
int main()
char ch;
int ascii;
printf("Enter a character: ");
scanf("%c", &ch);
ascii = ch;
if (ascii >= 65 && ascii <= 90)
printf("%c is a capital letter",ch);
else if (ascii >= 97 && ascii <=122)
printf("%c is a small letter",ch);
else if (ascii >=48 && ascii <= 57)
printf("%c is a digit",ch);
else if (ascii>=0 && ascii<=47 || ascii>=58 && ascii<=64 || ascii>=91 && a
scii<=96 || ascii>=123 && ascii<=127)
printf("%c is a special symbols",ch);
return 0;
Output :
Question : 3
Code :
#include <stdio.h>
int main()
char h, l, g;
int a;
printf("Enter Heath e For Excellent And p For Poor ");
scanf("%c", &h);
printf("Enter Location c For City And v For Village ");
scanf("\n%c", &l);
printf("Enter Gender m For Male And f For Female ");
scanf("\n%c", &g);
printf("Enter Age ");
scanf("\n%d", &a);
if ((h == 'e') && (l == 'c') && (g == 'm') && (a >= 25 || a <= 35))
printf("\nThe Premium Is Rs.4 Per Thousand And His Policy Cannot Excee
d Rs.2 Lakhs");
else if ((h == 'e') && (l == 'c') && (g == 'f') && (a >= 25 || a <= 35))
printf("\nThe Premium Is Rs.3 Per Thousand And Her Policy Cannot Excee
d Rs.1 Lakhs");
else if ((h == 'p') && (l == 'v') && (g == 'm') && (a >= 25 || a <= 35))
printf("\nThe Premium Is Rs.6 Per Thousand And Cannot Exceed Rs. 10,00
0");
else
printf("\n not Insured");
return 0;
Output :
Question : 4
Code :
#include<stdio.h>
int main()
float h, c, t;
int one = 0, two = 0, three = 0, grade;
printf("\nEnter the hardness, carbon content and tensile strength : ");
scanf("%f%f%f", &h, &c, &t);
if(h > 50)
one = 1;
if(c < 0.7)
two = 1;
if(t > 5600)
three = 1;
if(one && two && three)
grade = 10;
else if(one && two && !three)
grade = 9;
else if(two && three && !one)
grade = 8;
else if(one && three && !two)
grade = 7;
else if(one && !two && !three)
grade = 6;
else if(!one && !two && !three)
grade = 5;
printf("\nGrade of the steel : %d", grade);
return 0;
Output :
Question : 5
Aim : A library charges a fine for every book returned late. For
first 5 days the fine is 50 paise, for 6-10 days fine is one rupee
and above 10 days fine is 5 rupees. If you return the book after
30 days your membership will be cancelled. Write a program to
accept the number of days the member is late to return the
book and display the fine or the appropriate message.
Code :
#include<stdio.h>
int main()
int days;
float fine;
printf("Enter the number of days: ");
scanf("%d", &days);
if (days > 0 && days <= 5)
fine = 0.50 * days;
if (days >= 6 && days <= 10)
fine = 1 * days;
if (days > 10)
fine = 5 * days;
if (days > 30)
{
printf("Your membership would be canceled.\n");
}
printf("You have to pay Rs. %.2f fine.", fine);
return 0;
Output :
Question : 6
Code :
#include<stdio.h>
int main()
int x, y, z;
int max, valid;
printf("Enter the first side of triangle: ");
scanf("%d", &x);
printf("Enter the second side of triangle: ");
scanf("%d", &y);
printf("Enter the third side of triangle: ");
scanf("%d", &z);
max = x;
if(max<y)
max=y;
if(max<z)
max=z;
if(max == x && x < (y+z))
valid = 1;
if(max == y && y < (x+z))
valid = 1;
if(max == z && z < (x+y))
valid = 1;
if (valid==1)
printf("Triangle is valid");
else
printf("Triangle is not valid");
Output :
Question : 7
Code :
#include<stdio.h>
#include<math.h>
int main()
int x, y, z;
int max, flag=0;
printf("Enter the first side: ");
scanf("%d", &x);
printf("Enter the second side: ");
scanf("%d", &y);
printf("Enter the third side: ");
scanf("%d", &z);
if (x==y && x==z)
{
printf("Triangle is equilateral.");
}
else if (x==y || y==z || z==x)
{
printf("Triangle is isosceles.");
}
max = x;
if (y>max)
max = y;
if (z>max)
max = z;
if (max == x)
{
if(pow(max,2) == pow(y,2)+pow(z,2))
flag=1;
}
if (max == y)
{
if(pow(max,2) == pow(x,2)+pow(z,2))
flag=1;
}
if (max == z)
{
if(pow(max,2) == pow(x,2)+pow(y,2))
flag=1;
}
if(flag==1)
{
printf("Triangle is right angled");
}
return 0;
Output :
Question : 8
Aim : In a company, worker efficiency is determined on the
basis of the time required for a worker to complete a particular
job. If the time taken by the worker is between 2 – 3 hours, then
the worker is said to be highly efficient. If the time required by
the worker is between 3 – 4 hours, then the worker is ordered
to improve speed. If the time taken is between 4 – 5 hours, the
worker is given training to improve his speed, and if the time
taken by the worker is more than 5 hours, then the worker has
to leave the company. If the time taken by the worker is input
through the keyboard, find the efficiency of the worker.
Code :
#include<stdio.h>
int main()
{
printf(“ Harsh Verma\n 20001016018\n -----------\n”);
float hours;
printf("Input the time taken by worker: ");
scanf("%f", &hours);
if(hours>=2 && hours<=3)
printf("Worker is highly efficient");
if(hours>3 && hours <=4)
printf("Worker needs to improve speed");
if(hours>4 && hours <=5)
printf("Give training to worker");
if(hours>5)
printf("Worker is terminated");
return(0);
}
Output :
Question : 9
Code :
#include <stdio.h>
int main()
{
printf(“ Harsh Verma\n 20001016018\n -----------\n”);
int pera, perb;
printf("Enter percentage of A and B: ");
scanf("%d%d", &pera, &perb);
if (pera >= 55 && perb >= 45)
printf("\n Student is passed");
else if (pera >= 45 && pera < 55 && perb >= 55)
printf("\n Student is passed");
else if (perb < 45 && pera >= 65)
printf("Student is allowed to reappear in an exam");
else
printf("Student is failed");
return 0;
}
Output :
Question : 10
Code :
#include<stdio.h>
#include<conio.h>
int main()
{
int stock=100, order;
char credit;
printf("Enter the customer order: ");
scanf("%d", &order);
printf("Is his credit is ok? (Press y/n)\n");
credit = getch();
if(order<=stock && credit == 'y' || credit == 'Y')
printf("Sir,\n\t We supplied your requirement\n\t\t Quant
ity: %d",order);
else if(order>stock && credit == 'y' || credit == 'Y')
printf("Sir,\n\t We supplied %d products and balance will
be shipped later.",stock);
else
printf("Sir,\n\t Please first clear your credit, until we
can't supply you any more.");
}
Output :
Chapter 3: The Loop Control Structure
Question : 1
Code :
#include <stdio.h>
int main()
int i, hour, extra;
for (i = 1; i <= 10; i++)
{
printf("\n");
printf("Enter the working hour of the employ : ");
scanf("%d", &hour);
if (hour > 40)
{
extra = (hour - 40) * 12;
printf("\n%d Rs. is the overtime pay of employee\n", extra);
}
else
printf("\nThis employ has not done overtime.\n");
}
return 0;
Output :
Question : 2
Code :
#include <stdio.h>
int main()
int i, fact = 1, num;
printf("Ener a number = ");
scanf("%d", &num);
for (i = 0; i < num; i++)
{
fact *= (num-i);
}
printf("%d", fact);
return 0;
Output :
Question : 3
Code :
#include <stdio.h>
#include <math.h>
int main()
int base, power, d;
printf("Enter value of base = ");
scanf("%d", &base);
printf("Enter value of power = ");
scanf("%d", &power);
d = pow(base, power);
printf("%d", d);
return 0;
Output :
Question : 4
Aim : Write a program to print all the ASCII values and their
equivalent characters using a while loop. The ASCII values vary
from 0 to 255.
Code :
#include <stdio.h>
int main()
int i;
for(i = 0; i <= 255; i++)
printf("%d = %c , ", i, i);
return 0;
Output :
Question : 5
Code :
#include <stdio.h>
int main()
int i, rem, num = 0, x;
for (i = 1; i <= 500; i++)
{
num = 0;
x = i;
while (x)
{
rem = x % 10;
num = num + (rem * rem * rem);
x /= 10;
}
if (num == i)
printf("%d is a armstrong number\n", i);
}
return 0;
}
Output :
Question : 6
Code :
#include <stdio.h>
int main()
{
printf(“ Harsh Verma\n 20001016018\n -----------\n”);
int matchsticks = 21, user, computer;
printf("Numbers above 4 are invalid.");
while (matchsticks >= 1)
{
printf("\nNumber of matchsticks available right now is %d
.", matchsticks);
printf("\nYour Turn...");
printf("\nPick up the matchstick(s)-- (1-4): ");
scanf("%d", &user);
if (user > 4)
{
printf("Invalid Selection");
break;
}
computer = 5 - user;
printf("\nComputer's Turn..\n");
printf("\nComputer chooses:%d", computer);
matchsticks = matchsticks - user - computer;
continue;
if (matchsticks == 1)
break;
}
matchsticks--;
printf("\nComputer Wins");
return 0;
}
Output :
Question : 7
Code :
#include <stdio.h>
int main()
int num, pos = 0, neg = 0, zero = 0, choice ,n;
do
{
scanf("%d", &num);
if (num == 0)
zero++;
else if (n < 0)
neg++;
else if (n > 0)
pos++;
printf("Do you want to enter another number? (Enter 1 for yes & 0 for
no)");
scanf("%d", &choice);
} while (choice);
printf("Zeroes = %d\n", zero);
printf("Negatives = %d\n", neg);
printf("Positives = %d\n", pos);
return 0;
}
Output :
Question : 8
Aim : Write a program to find the octal equivalent of the
entered number
Code :
#include <stdio.h>
int main()
{
printf(“ Harsh Verma\n 20001016018\n -----------\n”);
int num, rem, oct = 0, rev = 0, rem1;
scanf("%d", &num);
while (num)
{
rem = num % 8;
oct = 10 * oct + rem;
num /= 8;
}
while (oct)
{
rem1 = oct % 10;
rev = rev * 10 + rem1;
oct /= 10;
}
printf("%d is octal equivalent", rev);
return 0;
}
Output :
Question : 9
Code :
#include <stdio.h>
int main()
int i, num, max, min, N, range;
printf("Enter how many number you want to enter : ");
scanf("%d", &N);
printf("Enter the number : ");
scanf("%d", &num);
max = min = num;
for (i = 1; i < N; i++)
{
printf("Enter the number : ");
scanf("%d", &num);
if (num > max)
max = num;
if (num < min)
min = num;
}
range = max - min;
printf("\n%d is the range of the data.", range);
return 0;
Output :