0% found this document useful (0 votes)
32 views18 pages

Pps Lab File Programs List

The document outlines a programming lab course (BCS151) with a list of 32 programming assignments designed to enhance problem-solving skills through coding. Each assignment includes tasks such as calculating marks, interest, geometric properties, and implementing algorithms for sorting, searching, and data manipulation. Additionally, it covers basic programming concepts like functions, structures, and file handling in C language.

Uploaded by

krishkumar5362
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views18 pages

Pps Lab File Programs List

The document outlines a programming lab course (BCS151) with a list of 32 programming assignments designed to enhance problem-solving skills through coding. Each assignment includes tasks such as calculating marks, interest, geometric properties, and implementing algorithms for sorting, searching, and data manipulation. Additionally, it covers basic programming concepts like functions, structures, and file handling in C language.

Uploaded by

krishkumar5362
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

BCS151: PROGRAMMING FOR PROBLEM SOLVING LAB

List of Programs

1. WAP that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the student.

2. WAP that calculates the Simple Interest and Compound Interest. The Principal, Amount, Rate of Interest and Time
are entered through the keyboard.

3. WAP to calculate the area and circumference of a circle.

4. WAP that accepts the temperature in Centigrade and converts into Fahrenheit using the formula C/5=(F-32)/9.

5. WAP that swaps values of two variables using a third variable.

6. WAP that checks whether the two numbers entered by the user are equal or not.

7. WAP to find the greatest of three numbers.

8. WAP that finds whether a given number is even or odd.

9. WAP that tells whether a given year is a leap year or not.

10.WAP that accepts marks of five subjects and finds percentage and prints grades according to the following
criteria:

Between 90-100%-----Print ‘A’

80-90%-----------------Print ‘B’

60-80%-----------------Print ‘C’

Below 60%-------------Print ‘D’

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.

14.WAP to print sum of even and odd numbers from 1 to N numbers.

15. WAP to print the Fibonacci series.

16.WAP to check whether the entered number is prime or not.

17. WAP to find the sum of digits of the entered number.

18.WAP to find the reverse of a number.

19.WAP to print Armstrong numbers from 1 to 100.

20.WAP to convert binary number into decimal number and vice versa.

21. WAP that simply takes elements of the array from the user and finds the sum of these elements. 22.WAP that
inputs two arrays and saves sum of corresponding elements of these arrays in a third array and prints them.

23.WAP to find the minimum and maximum element of the array.

24.WAP to search an element in a array using Linear Search.

25.WAP to sort the elements of the array in ascending order using Bubble Sort technique. Page 33 of 40

26.WAP to add and multiply two matrices of order nxn.

27.WAP that finds the sum of diagonal elements of a mxn matrix.


28.WAP to implement strlen (), strcat (),strcpy () using the 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 obtained by the student.
#include <stdio.h>
int main()
{
float subject1, subject2, subject3, subject4, subject5, total_marks, percentage;
printf("Enter marks for subject 1: ");
scanf("%f", &subject1);
printf("Enter marks for subject 2: ");
scanf("%f", &subject2);
printf("Enter marks for subject 3: ");
scanf("%f", &subject3);
printf("Enter marks for subject 4: ");
scanf("%f", &subject4);
printf("Enter marks for subject 5: ");
scanf("%f", &subject5);
total_marks = subject1 + subject2 + subject3 + subject4 + subject5;
percentage = (total_marks / 500) * 100;
printf("\nTotal marks obtained: %.2f\n", total_marks);
printf("Percentage obtained: %.2f%%\n", percentage);
return 0;
}
2. WAP that calculates the Simple Interest and Compound Interest. The Principal, Amount, Rate of
Interest and Time are entered through the keyboard.

#include <stdio.h>
#include <math.h>
int main()
{
float principal, rate, time, simple_interest, compound_interest, amount;
printf("Enter Principal: ");
scanf("%f", &principal);
printf("Enter Rate of Interest (in percentage): ");
scanf("%f", &rate);
printf("Enter Time (in years): ");
scanf("%f", &time);
simple_interest = (principal * rate * time) / 100;
amount = principal * pow((1 + rate / 100), time);
compound_interest = amount - principal;
printf("\nSimple Interest: %.2f\n", simple_interest);
printf("Compound Interest: %.2f\n", compound_interest);
return 0;
}
2. WAP to calculate the area and circumference of a circle.

3. #include <stdio.h>
4. #define PI 3.14159
5. int main() {
6. double radius, area, circumference;
7. printf("Enter the radius of the circle: ");
8. scanf("%lf", &radius);
9. area = PI * radius * radius;
10. circumference = 2 * PI * radius;
11. printf("Area of the circle: %.2lf\n", area);
12. printf("Circumference of the circle: %.2lf\n", circumference);
13. return 0;
14. }

4. WAP that accepts the temperature in Centigrade and converts into Fahrenheit using the formula C/5=(F-32)/9.

1. #include<stdio.h>
2. int main()
3. {
4. float fahrenheit, celsius;
5. celsius = 24;
6. fahrenheit =( (celsius*9)/5)+32;
7. printf("\n\n Temperature in fahrenheit is: %f",fahrenheit);
8. return (0);
9. }

5. WAP that swaps values of two variables using a third variable.

#include<stdio.h>
/*5. WAP that swaps values of two variables using a third variable. */
void main()
{
int a,b,temp;
printf("Enter a=");
scanf("%d",&a);
printf("Enter b=");
scanf("%d",&b);

temp=a;
a=b;
b=temp;
printf("\nAfter swapping");
printf("\na=%d",a);
printf("\nb=%d",b);
}
6. WAP that checks whether the two numbers entered by the user are equal or not.
#include<stdio.h>
/*WAP that checks whether the two numbers entered by the user are equal or not. */
void main()
{
int a,b;
printf("Enter a=");
scanf("%d",&a);
printf("Enter b=");
scanf("%d",&b);

if(a==b)
{
printf("\na and b are equal.");
}
else
{
printf("\na and b are not equal.");
}
}
7. WAP to find the greatest of three numbers.
#include<stdio.h>
/*WAP to find the greatest of three numbers. */
void main()
{
int a,b,c;
printf("Enter a=");
scanf("%d",&a);
printf("Enter b=");
scanf("%d",&b);
printf("Enter c=");
scanf("%d",&c);

if(a>b)
{
if(a>c)
{
printf("\n a is greatest.");
}
else
{
printf("\n c is greatest.");
}
}
else
{
if(b>c)
{
printf("\n b is greatest.");
}
else
{
printf("\n c is greatest.");
}
}
}

8. WAP that finds whether a given number is even or odd.


#include<stdio.h>
/*WAP that finds whether a given number is even or odd. */
void main()
{
int n;
printf("Enter a number=");
scanf("%d",&n);

if(n%2==0)
{
printf("\n n is even number.");
}
else
{
printf("\n n is odd number.");
}
}
9. WAP that tells whether a given year is a leap year or not.
#include<stdio.h>
/* WAP that tells whether a given year is a leap year or not. */
void main()
{
int year;
printf("Enter a number=");
scanf("%d",&year);

if((year%4==0||year%400==0)&&year%100!=0)
{
printf("\nYear is leap year.");
}
else
{
printf("\nYear is not leap year.");
}
9. }

10. WAP that accepts marks of five subjects and finds percentage and prints grades according to
the following criteria:
Between 90-100%————–Print „A‟
80-90%—————————-Print „B‟
60-80%—————————Print „C‟
Below 60%———————-Print „D‟

#include<stdio.h>
/*WAP that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the student.*/
void main()
{
int hindi, english, science,math,computer,sum ;
float per;
printf("Enter marks of Hindi=");
scanf("%d",&hindi);
printf("Enter marks of English=");
scanf("%d",&english);
printf("Enter marks of Science=");
scanf("%d",&science);
printf("Enter marks of Math=");
scanf("%d",&math);
printf("Enter marks of Computer=");
scanf("%d",&computer);

sum=hindi+english+science+math+computer;
printf("\nSum of marks=%d",sum);

per=(float)sum/5;
printf("\nPercentage of marks=%f",per);

if(per>=90&&per<=100)
{
printf("\nGrade A");
}
else if(per>=80&&per<90)
{
printf("\nGrade B");
}
else if(per>=60&&per<80)
{
printf("\nGrade C");
}
else if(per<60)
{
printf("\nGrade D");
}
}

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>
void main()
{
int choice,a,b;
printf("Select your choice:\n");
printf("1- Add:\n");
printf("2- Sub:\n");
printf("3- Mul:\n");
printf("4- Div:\n");
printf("5- Mod:\n");
printf("Enter number a=");
scanf("%d",&a);
printf("Enter number b=");
scanf("%d",&b);
printf("Enter your choice=");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Add of a and b %d",(a+b));
break;
case 2:
printf("Sub of a and b %d",(a-b));
break;
case 3:
printf("Mul of a and b %d",(a*b));
break;
case 4:
printf("Div of a and b %d",(a/b));
break;
case 5:
printf("Mod of a and b %d",(a%b));
break;
default:
printf("Wronf choice.");

}
}

12. WAP to print the sum of all numbers up to a given number.


13. WAP to find the factorial of a given number.

14.WAP to print sum of even and odd numbers from 1 to N numbers.


#include<stdio.h>
void main()
{
int i,n,sumEven=0,sumOdd=0;
printf("Enter number=");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{
sumEven=sumEven+i;
}
else
{
sumOdd=sumOdd+i;
}
}
printf("\nSum of even numbers=%d",sumEven);
printf("\nSum of odd numbers=%d",sumOdd);
}

15. WAP to print the Fibonacci series.

16.WAP to check whether the entered number is prime or not.


#include<stdio.h>
void main()
{
int i,n,prime=1;
printf("Enter number=");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
prime=0;
break;
}
}
if(prime==1)
{
printf("Prime Number");
}
else
{
printf("Not Prime Number");
}
}

17. WAP to find the sum of digits of the entered number.


#include<stdio.h>
void main()
{
int n,r,sumDigits=0;
printf("Enter number=");
scanf("%d",&n);
while(n>0)
{
r=n%10;
sumDigits=sumDigits+r;
n=n/10;
}
printf("Sum of Digits=%d",sumDigits);
}
18.WAP to find the reverse of a number.
#include<stdio.h>
void main()
{
int n,r,rev=0;
printf("Enter number=");
scanf("%d",&n);
while(n>0)
{
r=n%10;
rev=rev*10+r;
n=n/10;
}
printf("Reverse number=%d",rev);
}

19.WAP to print Armstrong numbers from 1 to 100.


#include<stdio.h>
void main()
{
int i=1,r,aNum=0,num;
for(i=1;i<=100;i++)
{
num=i;
aNum=0;
while(num>0)
{
r=num%10;
aNum=aNum+r*r*r;
num=num/10;
}
if(i==aNum)
{
printf("Armstrong Number=%d\n",i);
}
}
}

20.WAP to convert binary number into decimal number.


#include<stdio.h>
#include

void main()
{ int n,r,rev=0,p=0;
printf("Enter binary number=");
scanf("%d",&n);
while(n>0)
{ r=n%10;
if(r!=0)
{ rev= rev+(int)pow(2,p);
}
n=n/10; p++;
}
printf("Decimal number=%d",rev);
}
21. WAP that simply takes elements of the array from the user and finds the sum of these elements.

#include<stdio.h>

int main()
{
//let's assume the maximum array size as 100.
//initialize sum as 0. Otherwise, it will take some garbage value.
int arr[100], size, i, sum = 0;

//Get size input from user


printf("Enter array size\n");
scanf("%d",&size);

//Get all elements using for loop and store it in array


printf("Enter array elements\n");
for(i = 0; i < size; i++)
scanf("%d",&arr[i]);

//add all elements to the variable sum.


for(i = 0; i < size; i++)
sum = sum + arr[i]; // same as sum += arr[i];

//print the result


printf("Sum of the array = %d\n",sum);

return 0;
}

22.WAP that inputs two arrays and saves sum of corresponding elements of these arrays in a third array and prints
them.
#include<stdio.h>
void main()
{
int i,ar1[10],ar2[10],sum[10];
printf("Enter first array:-\n");
for(i=0;i<=9;i++)
{
printf("ar1[%d]=",i);
scanf("%d",&ar1[i]);
}
printf("Enter second array:-\n");
for(i=0;i<=9;i++)
{
printf("ar2[%d]=",i);
scanf("%d",&ar2[i]);
}
for(i=0;i<=9;i++)
{
sum[i]=ar1[i]+ar2[i];
}

printf("Sum of arrays:-");
for(i=0;i<=9;i++)
{
printf("\nsum[%d]=%d",i,sum[i]);
}

23.WAP to find the minimum and maximum element of the array.


#include<stdio.h>
void main()
{
int i,ar[10],min,max;
printf("Enter array:-\n");
for(i=0;i<=9;i++)
{
printf("ar[%d]=",i);
scanf("%d",&ar[i]);
}
min=ar[0];
max=ar[0];
for(i=0;i<=9;i++)
{
if(min > ar[i])
{
min=ar[i];
}
if(max < ar[i])
{
max=ar[i];
}
}
printf("\nMin=%d",min);
printf("\nMax=%d",max);
}

24.WAP to search an element in a array using Linear Search.


#include<stdio.h>
void main()
{
int i,ar[10],n,pos=-1;
printf("Enter array:-\n");
for(i=0;i<=9;i++)
{
printf("ar[%d]=",i);
scanf("%d",&ar[i]);
}
printf("Enter number to be search=");
scanf("%d",&n);
for(i=0;i<=9;i++)
{
if(n==ar[i])
{
pos=i+1;
}
}
if(pos==-1)
{
printf("Number not found.");
}
else
{
printf("Position=%d",pos);
}
}

25.WAP to sort the elements of the array in ascending order using Bubble Sort technique.
#include<stdio.h>

void main()

{ int i,j,ar[10],temp;

printf("Enter array:-\n");

for(i=0;i<=9;i++)

{ printf("ar[%d]=",i);

scanf("%d",&ar[i]); }

for(i=0;i<=9;i++)

{ for(j=0;j<=9-i;j++)

{ if(ar[j]>ar[j+1])

{ temp=ar[j];

ar[j]=ar[j+1];

ar[j+1]=temp; } } }

printf("Sorted array:-");

for(i=0;i<=9;i++)

{ printf("\n%d",ar[i]); }

26.WAP to add and multiply two matrices of order nxn.


#include<stdio.h>
void main()
{
int i,j,k,m1[3][3],m2[3][3],mul[3][3];
printf("Enter first matrix:-\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&m1[i][j]);
}
}
printf("Enter second matrix:-\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&m2[i][j]);
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
mul[i][j]=0;
for(k=0;k<=2;k++)
{
mul[i][j]=mul[i][j]+(m1[i][k]*m2[k][j]);
}
}
}
printf("Multiplication of metrices:-\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d ",mul[i][j]);
}
printf("\n");
}
}

27.WAP that finds the sum of diagonal elements of a mxn matrix.


#include<stdio.h>
void main()
{
int i,j,k,matrix[3][3],sum=0;
printf("Enter matrix:-\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&matrix[i][j]);
}
}
printf("Matrix is:-\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d ",matrix[i][j]);
}
printf("\n");
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(i==j)
{
sum = sum + matrix[i][j];
}
}
}
printf("Sum of diagonal is = %d ",sum);

}
28.WAP to implement strlen (), strcat (),strcpy () using the concept of Functions.
#include<stdio.h>

#include <string.h>

void main()

char st[20]={'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l','d', '\0'};

printf("Length of '%s'=: %d\n",st,strlen(st));

char wd1[10]={'h', 'e', 'l', 'l', 'o', '\0'};

char wd2[10]={'w', 'o', 'r', 'l','d', '\0'};

strcat(wd1,wd2);

printf("\nFirst word is: %s\n",wd1);

char st1[20]={'I', 'n', 'd', 'i', 'a', '\0'};

char st2[20];

strcpy(st2,st1);

printf("\nString2 is: %s",st2);

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.(Do it by yourself )

Example for structure:


#include<stdio.h>
#include <string.h>
struct stu
{ int roll;
char name[50];
}st1,st2; //declaring variables for structure
int main( )
{
//store first student information
st1.roll=101;
strcpy(st1.name, "Amit");

//store second student information


st2.roll=102;
strcpy(st2.name, "Manoj");
//printing first student information
printf( "student 1 roll : %d\n", st1.roll);
printf( "student 1 name : %s\n", st1.name);

//printing second student information


printf( "student 2 roll : %d\n", st2.roll);
printf( "student 2 name : %s\n", st2.name);
return 0;
}

30. WAP to swap two elements using the concept of pointers.


#include<stdio.h>
void swap(int *, int *); //prototype of the function
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(&a,&b);
printf("After swapping values in main a = %d, b = %d\n",a,b);
}
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a=*b;
*b=temp;
printf("After swapping values in function a = %d, b = %d\n",*a,*b);
}

31. WAP to compare the contents of two files and determine whether they are same or not.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void compareFiles(FILE *fp1, FILE *fp2)


{
// fetching character of two file
// in two variable ch1 and ch2
char ch1 = getc(fp1);
char ch2 = getc(fp2);

// error keeps track of number of errors


// pos keeps track of position of errors
// line keeps track of error line
int error = 0, pos = 0, line = 1;

// iterate loop till end of file


while (ch1 != EOF && ch2 != EOF)
{
pos++;

// if both variable encounters new


// line then line variable is incremented
// and pos variable is set to 0
if (ch1 == '\n' && ch2 == '\n')
{
line++;
pos = 0;
}
// if fetched data is not equal then
// error is incremented
if (ch1 != ch2)
{
error++;
printf("Line Number : %d \tError"
" Position : %d \n", line, pos);
}

// fetching character until end of file


ch1 = getc(fp1);
ch2 = getc(fp2);
}

printf("Total Errors : %d\t", error);


}

// Driver code
int main()
{
// opening both file in read only mode
FILE *fp1 = fopen("file1.txt", "r");
FILE *fp2 = fopen("file2.txt", "r");

if (fp1 == NULL || fp2 == NULL)


{
printf("Error : Files not open");
exit(0);
}

compareFiles(fp1, fp2);

// closing both file


fclose(fp1);
fclose(fp2);
return 0;
}

32. Write a program for Counting the vowels and consonants in a


String.
Program:
#include<stdio.h>
int main()
{
int vowels = 0, consonants = 0;

int i;
char ch,str[40];
printf(“enter the string=”);
scanf(“%s”,&str);
// Take each character from this string to check
for (i = 0; str[i] != '\0'; i++) {

ch = str[i]; //initialize the character variable ch

// If this character is a vowel,


// increment the count of vowels
if (ch == 'a' || ch == 'e'
|| ch == 'i' || ch == 'o'
|| ch == 'u' || ch == 'A'
|| ch == 'E' || ch == 'I'
|| ch == 'O' || ch == 'U')
vowels++;

// If this character is a space


// skip it
else if (ch == ' ')
continue;

else
// Else increment the count of consonants
consonants++;
}

// Print the total count of vowels and consonants


printf("\nVowels: %d", vowels);
printf("\nConsonants: %d", consonants);
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy