Ayush Pps FILE
Ayush Pps FILE
Ayush Pps FILE
(LAB FILE)
11. WAP that takes two operands and one operator from the
user, perform the operation, and prints the result by using
Switch statement.
12. WAP to print the sum of all numbers up to a given number.
13. WAP to find the factorial of a given number.
INDEX
concept of Functions.
29. Define a structure data type TRAIN_INFO. The type contain
Train No.: integer type Train name: string Departure Time:
aggregate type TIME Arrival Time: aggregate type TIME Start
station: string End station: string The structure type Time
contains two integer members: hour and minute. Maintain a
train timetable and implement the following operations:
a. List all the trains (sorted according to train number)
that depart from a particular section.
b. List all the trains that depart from a particular
station at a particular time.
c. List all he trains that depart from a particular station
within the next one hour of a given time.
d. List all the trains between a pair of start station and
end station.
30. WAP to swap two elements using the concept of pointers.
31. WAP to compare the contents of two files and determine
whether they are same or not.
32. WAP to check whether a given word exists in a file or not. If
yes then find the number of times it occurs.
1. WAP that accepts the marks of 5 subjects and finds the sum and percentage
marks otained by the student.
#include<stdio.h>
int main()
{
int hindi, eng, math, phy, chem, total;
float per;
printf("Enter the mark of Hindi:");
scanf("%d", &hindi);
printf("Enter the mark of English:");
scanf("%d", &eng);
printf("Enter the mark of Math:");
scanf("%d", &math);
printf("Enter the mark of Physics:");
scanf("%d", &phy);
printf("Enter the mark of Chemistry:");
scanf("%d", &chem);
total = hindi + eng + math + phy + chem;
printf("total
mark: %d", total); per = total
/ 5; printf("percentage:
%f", per);
return 0;
}
OUTPUT
OUTPUT
#include <stdio.h>
#include <math.h>
int main()
{
float r, area, cirf;
printf("enter the redius of circle=
"); scanf("%f", &r); area = 3.14 *
r * r; printf("area of circle %f\n",
area); cirf = 2 * 3.14 * r;
printf("circumference of circle %f", cirf);
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
float c, f;
printf("Enter Temperture in Fahrenheit: ");
scanf("%f", &f); c = (f - 32) * 5 / 9;
printf("Fahrenheit to celsius is
= %f", c); return 0;
}
OUTPUT
OUTPUT
6. WAP that cheak wheather the two numbers entered by the user are equal or not.
#include <stdio.h>
int main()
{
int x, y;
printf("Enter Value of x,y\n");
scanf("%d%d", &x, &y);
if (x == y)
{
printf("x and y are equal\n");
}
else
{
printf("x and y are not equal\n");
}
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
int a, b, c, great;
printf("Enter three Number :");
scanf("%d%d%d", &a, &b, &c);
great = a;
if (b > great)
{
great = b;
}
if (c > great)
{
great = c;
}
printf("\n Greatest Number is %d", great);
return 0;
}
OUTPUT
8.WAP
the find whether a given number is even or odd.
#include <stdio.h>
int main()
{
int a;
printf("Enter a
number:"); scanf("%d",
&a); if (a % 2 == 0)
{
printf("Number=%d is even", a);
}
else
{
printf("Number=%d is odd", a);
}
return
0;
}
OUTPUT
#include <stdio.h>
int main()
{ int
year;
9.WAP
printf("Enter Any Year: ");
scanf("%d", &year);
if (year % 4 == 0)
{
printf("Year is Leap Year");
}
else
{
printf("Year is not Leap Year");
}
return 0;
}
OUTPUT
that accepts marks of five subjects and finds percentage and prints
grades according to the following ceriteria: Between 90-100% Print'A'
80-90% Print'B' 60-80%
Print'C'
Below 60% Print'D'.
#include <stdio.h>
int main()
{
int hindi, eng, math, phy, chem, total;
float per;
printf("Enter marks of five Subjects; \n");
scanf("%d%d%d%d%d", &hindi, &eng, &math, &phy, &chem);
10.WAP
total = hindi + eng + math + phy +
chem; printf("Total Marks : %d\n", total);
per = total / 5; printf("Percentage
:%f\n", per); if (per > 90 && per <= 100)
{
printf("\n Grade A");
} else if (per > 80 && per
<= 90)
{
printf("\n Grade B");
} else if (per > 60 && per
<= 80)
{
printf("\n Grade C");
}
else
{ printf("\n Grade D");
}
return 0;
}
OUTPUT
11.WAP that takes two operands and one operator from the user, perform the
operation, and prints the result by using switch statement.
#include <stdio.h>
int main()
{
float a, b, k;
char op;
printf("enter the operator(+,-,*,/):");
scanf("%c", &op);
printf("enter two number a and b:\n");
scanf("%f%f", &a, &b);
switch (op)
{
case '+':
k = a + b;
printf("Addition is %f",
k); break; case '-':
:
k = a - b;
printf("Substraction is %f",
k); break; case '*':
k = a * b;
printf("Multiplication is %f",
k); break; case '/':
}
k = a / b;
printf("Divide is %f", k);
return 0;
}
OUTPUT
12.WAP to print the sum of all numbers up to a given number.
#include <stdio.h>
int main()
{ int a, b, sum =
1;
printf("enter:a");
scanf("%d", &a);
for (b = 0; b <= a; b++)
{
sum = sum + b;
}
OUTPUT
#include <stdio.h>
int main()
{
int n, i, fact = 1;
printf("Enter a
number:"); scanf("%d",
&n); for (i = 1; i <= n;
i++)
{
fact = fact * i;
}
printf("Factorial of %d=%d", n, fact);
return 0;
}
OUTPUT
#include <stdio.h>
int main() {
int a = 0, b = 1, c, k;
printf("Enter the turms to print:");
scanf("%d", &k);
printf("%d\n%d", a, b); int j = 1;
#include <stdio.h>
int main()
{
int a, i, count = 0;
printf("Enter Any Number: ");
scanf("%d", &a);
for (i = 1; i <= a; i++)
{
if (a % i == 0)
{
count++;
}
} if (count
== 2)
printf("%d is Prime Number", a);
else
printf("%d is Not Prime Number", a);
return 0;
}
OUTPUT
16.WAP to find the sum of digits of the entered number.
#include <stdio.h>
int main()
{
int n, r, sum = 0;
printf("Enter Any Number: ");
scanf("%d", &n);
while (n > 0)
{
r = n % 10;
sum = sum + r;
n = n / 10;
}
printf("Sum Of Digits:%d", sum);
return 0;
}
OUTPUT
n = n / 10;
}
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
int i, n, r, arm = 0, a;
for (i = 1; i <= 100; i++)
{
arm = 0;
n = i; a = n;
while (n > 0)
{ r=
n % 10; n
= n / 10;
arm = arm + (r * r * r);
}
if (arm == a)
{
printf("%d : is Armstrong Number\n", a);
}
}
return 0;
}
OUTPUT
19. WAP to convert binary number into decimal number and vice versa.
#include <stdio.h>
int main()
{
int n, rem, d = 0, base = 1;
printf("Enter Binary Noumber: ");
scanf("%d", &n); while (n > 0)
{
rem = n % 10;
d = d + rem * base;
n = n / 10; base =
base * 2;
}
printf("Decimal Number %d", d);
return 0;
}
OUTPUT
20.WAP that simply takes elements of the array from the user and finds the sum
of these elements.
#include <stdio.h>
int main()
{
int a[6], i, sum = 0;
printf("Enter the array Element:");
for (i = 0; i < 6; i++)
{
scanf("%d", &a[i]);
}
printf("Sum of array element:");
OUTPUT
21.WAP that input two array and saves sum of corresponding elements of these
arrays in a third array and prints them.
#include <stdio.h>
int main()
{
int a[6], b[6], sum[6], i;
#include <stdio.h>
int main()
{
int a[50], size, max, min, i;
printf("Enter the size array:");
scanf("%d", &size);
printf("Enter value of array:");
for (i = 0; i < size; i++)
{
scanf("%d", &a[i]);
}
max = a[0]; for (i =
0; i < size; i++)
{
if (a[i] > max)
{
max = a[i];
}
}
printf("Maximum value of array: %d\n", max);
min = a[0];
for (i = 0; i < size; i++)
{
if (a[i] < min)
{
min = a[i];
}
}
printf("Minimum value of array: %d", min);
return 0;
} OUTPUT
#include <stdio.h>
int main()
{
int a[5], n, i, loc = 0, s;
printf("Enter the number of elements in array :\n");
scanf("%d", &n);
printf("Enter :%d number \n", n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("Enter the numbar to
search:\n"); scanf("%d", &s); for (i =
0; i < n; i++)
{
if (a[i] == s)
{
loc = i + 1;
break;
}
}
if (loc > 0)
printf("%d is present at location :%d\n", s, loc);
else
OUTPUT
24.WAP to sort the element of the array in ascending order using Bubble Sort
technique.
#include <stdio.h>
int main()
{
int a[10] = {2, 5, 6, 7, 1, 9, 3, 7, 4, 2},
i, j, temp; for (i = 0; i < 10; i++)
for (i = 0; i < 10; i++)
{
for (j = i; j < 10; j++)
{
if (a[i] > a[j])
{
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
printf("Asecending order array element: ");
for (i = 0; i < 10; i++)
{
printf("%d", a[i]);
}
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
int a[3][3], b[3][3], sum[3][3], multi[3][3], i, j, n,
k;
printf("Enetr the order of
the matix: \n");
{
for (j = 0; j < n; j++)
{
printf(" %d", sum[i][j]);
}
printf("\n");
}
for (i =
0; i < n; i++)
{
for (j = 0; j < n; j++)
{
multi[i][j] = 0;
for (k = 0; k < n; k++)
{
multi[i][j] += a[i][k] * b[k][j];
}
}
}
printf("Multiplication of the Matrices: \n");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
printf(" %d", multi[i][j]);
}
printf("\n");
}
return 0;
}
OUTPUT
#include <stdio.h>
#include <string.h>
int main()
{
int n;
28. Define a structure data type TRAIN_INFO. The type contains Train No.:
integer type, Train name: string, Departure Time: aggregate type TIME, Arrival
Time: aggregate type TIME, Start station: string, End station: string. The
structure type TIME contains two integer members: hour and minute.
Maintain a train timetable and implement the following operations: (i) List all
the trains (sorted according to train number) that depart from a particular
station.
(ii) List all the trains that depart from a particular station at a particular time.
(iii) List all the trains that depart from a particular station within the next one
hour of a given time.
(iv) List all the trains between a pair of start station and end station.
#include <stdio.h>
#include <string.h> struct
stu
{
int roll;
char name[50];
} st1, st2;
int main()
{
st1.roll = 101; strcpy(st1.name,
"Amit");
st2.roll = 102;
strcpy(st2.name, "Ankit");
printf("student 1 roll : %d\n", st1.roll);
printf("student 1 name : %s\n", st1.name);
return 0;
}
OUTPUT
#include <stdio.h>
int temp;
temp = *x;
*x = *y;
*y = temp;
}
int main()
{
int a,
b;
swap(&a, &b);
printf("\nAfter swaping :a=%d,b=%d", a,
b); return 0; }
OUTPUT
30. Write a program to compare the contents of two files and determine
whether they are the same or not.
#include <stdio.h>
#include <string.h>
int main()
{
return 0;
}
OUTPUT
31. Write a program to remove all the blank space from the string & print it, also
count the no of characters.
#include <stdio.h>
#include <string.h>
int main()
char str[50];
int char_count;
int len;
int i, j;
gets(str);
len = strlen(str);
i = 0;
for (i = 0; i <= len - 1; i++)
{ if (str[i] == ' ' || str[i] ==
'\t')
{
for (j = i; j <= len - 2;
j++) str[j] = str[j + 1];
len--; i--;
}
}
str[len] = '\0';
OUTPUT