0% found this document useful (0 votes)
14 views

C Programs Soln 2021-22

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)
14 views

C Programs Soln 2021-22

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/ 26

B.V.V.S.

Basaveshwar Engineering College (Autonomous), Bagalkote


21UCS109L : Programming Practice Using C

Following is the finalized Program List for preparation of PPC Lab journal.

Part – A

1. Write a C program that aid in evaluating return on investment of Principal amount for 3 years at
9% rate of interest using simple interest and compound interest. SI=PTR/100 and
CI=P[1+R/100]t-P.

2. Mr. Robert’s basic salary is read as input. His dearness allowance is 40% of basic salary and
house rent allowance is 20% of basic salary. The income tax that he is paying is 12% of gross
salary. Write a program to calculate his net (take home) salary.

3. If a four-digit number is input through the keyboard, write a program to calculate the sum of
its digits.

4. A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is
input through the keyboard. Help the cashier to find the total number of currency notes of each
denomination to be given to the customer.

5. Write a C program to determine whether a seller has made the profit or incurred the loss and
display the amount and percentage of profit or loss.

6. Write a C program to identify whether the entered character belongs to an alphabet, digit or
special character.

7. Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics
and Computer. Calculate percentage and display the grade according to following:

Percentage Grade
More than or equal to 90% S
Between 80% - 89.99% A
Between 70%-79.99% B
Between 60%-69.99% C
Between 40%-59.99% D
Between 35%-40% E
Below 35% F

8. Write a C program, to check whether a person is eligible for the marriage or not.

9. Write a C program to identify the quadrant of a point, when coordinates (x,y) are given.

10. Write a C program to compute area of the following of geometric objects based on user’s
preference using switch case:
i. Circle
ii. Triangle
iii. Parallelogram
iv. Square
Part - B

11. Write a C program to check whether the given number is palindrome or not.

12. Write a C program to generate the prime numbers between 1 to n.

13. Write a C program to sort the given list using selection sort technique.

14. Write a C program to find the sum of rows and columns of the given matrix.

15. Write a C Program to check whether given string is palindrome or not.

16. Write a C Program to append the contents of one string to the other string without using
string handling functions.

17. Write a C program to find the value of an using user-defined function.

18. Write a C program to find the factorial of a number using recursive function.

19. Write a C program that defines the Employee structure with the following properties:
Employee id, Employee name, Basic Salary, Date of birth. Read the details of 3 employees,
calculate the Net salary and display the same.

20. Write a C program to read two numbers and swap them with help of function through call
by reference method.
B.V.V.S.

Basaveshwar Engineering College (Autonomous), Bagalkote


21UCS109L : Programming Practice Using C

Following is the at least expected program for each of above problem titles in the PPC
journal.

Note that,

Each of following program is at least expected code.

Still there exists scope to include documentation section, comments for different lines of
code, comments to highlight the logic in the code.

There may exist different form to solve the problem.

Each solution should be checked before inclusion and should be supported by at least 3
outputs and include your observation.

Part – A

1. Write a C program that aid in evaluating return on investment of Principal amount for 3
years at 9% rate of interest using simple interest and compound interest. SI=PTR/100 and
CI=P[1+R/100]t.

#include<stdio.h>
#include<math.h>
int main()
{
float p, r=9.0, t=3.0, si, ci;
printf("Enter Principle\n");
scanf("%f",&p);

si=(p*r*t)/100;

printf("Simple Interest=%f\n",si);
ci = p*(pow((1 + r / 100), t))-p;
printf("Compound Interest=%f",ci);
printf("\nMy evaluation is, CI yield is better than SI.");
return 0;
}
2. Mr. Robert’s basic salary is read as input. His dearness allowance is 40% of basic salary and
house rent allowance is 20% of basic salary. The income tax that he is paying is 12% of
gross salary. Write a program to calculate his net (take home) salary.

#include<stdio.h>
int main()
{
float bs, da, hra,it,gs,ns;
printf("Enter Basic Salary of Mr. Robert\n");
scanf("%f",&bs);

da = bs*0.4;
hra = bs*0.2;

gs = bs+da+hra;

it=gs*0.12;

ns=gs-it;

printf("\n Basic Salary of Robert=\t%.2f",bs);


printf("\n Dearness Allowance=\t\t%.2f",da);
printf("\n House Rent=\t\t\t%.2f",hra);
printf("\n\n Gross Salary=\t\t\t%.2f",gs);
printf("\n\n Income Tax=\t\t\t%.2f",it);
printf("\n\n Net Salary (Take Home Salary)=%.2f",ns);

return 0;
}
3. If a four-digit number is input through the keyboard, write a program to calculate the sum of
its digits.

#include <stdio.h>

int main()
{
int a,b,c,d,e,sum;
printf("Enter four digit integer\n");
scanf("%d",&a);

b=a/1000;
a=a%1000;
c=a/100;
a=a%100;
d=a/10;
e=a%10;

sum=b+c+d+e;

printf ("Sum of digits of above integer is %d\n",sum);


return 0;
}
4. A cashier has currency notes of denominations 10, 50 and 100. If the amount to be
withdrawn is input through the keyboard. Help the cashier to find the total number of
currency notes of each denomination to be given to the customer.

#include<stdio.h>
int main()
{
int amt,hn,fn,tn,coins;
printf("Enter Amount to be Withdrawn\n");
scanf("%d",&amt);

hn=amt/100;
amt=amt%100;
fn=amt/50;
amt=amt%50;
tn=amt/10;
amt=amt%10;
coins=amt;

printf("100 Rs note : %d\n",hn);


printf("50 Rs note : %d\n",fn);
printf("10 Rs note : %d\n",tn);
printf("And coins : %d\n",coins);
return 0;

}
5. Write a C program to determine whether a seller has made the profit or incurred the loss and
display the amount and percentage of profit or loss.

#include<stdio.h>

int main()
{
float cp, sp, profit, loss;

printf("Enter the cost price of an item\n");


scanf("%f", &cp);

printf("Enter the selling price of an item\n");


scanf("%f", &sp);

if (sp>cp)
{
profit = sp-cp;
printf("\nProfit is %.2f by selling an item\nPorfit percntage is %.2f", profit,(profit/sp)*100);

else if (sp<cp)
{
loss = cp-sp;
printf("\nLoss is %.2f by selling an item\nLoss percntage is %.2f", loss,(loss/sp)*100);
}

else
printf("\nNo Profit/Loss by selling item");

return 0;

}
6. Write a C program to identify whether the entered character belongs to an alphabet, digit or
special character.

#include <stdio.h>

int main()
{
char ch;

printf("Enter any character\n");


scanf("%c", &ch);

if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is an Alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is a Digit.", ch);
}
else
{
printf("'%c' is a Special Character.", ch);
}

return 0;
}
7. Write a C program to input marks of five subjects Physics, Chemistry, Biology,
Mathematics and Computer. Calculate percentage and display the grade according to
following:
Percentage Grade

More than or equal to 90% S

Between 80% - 89.99% A

Between 70%-79.99% B

Between 60%-69.99% C

Between 40%-59.99% D

Between 35%-40% E

Below 35% F

#include <stdio.h>

int main()
{
int p,c,b,m,cs;
float per;

printf("Enter five subjects (P,C,M,B,CS) marks\n");


scanf("%d%d%d%d%d",&p,&c,&m,&b,&cs);

per = (p+c+m+b+cs)/5.0;

if(p<35||c<35||m<35||b<35||cs<35)
{
printf("Result Failed");
return 0;
}
else
{
printf("Percentage = %.2f\n", per);

if(per >= 90)


{
printf("Grade S");
}
else if(per >= 80)
{
printf("Grade A");
}
else if(per >= 70)
{
printf("Grade B");
}
else if(per >= 60)
{
printf("Grade C");
}
else if(per >= 40)
{
printf("Grade D");
}
else if(per >= 35)
{
printf("Grade E");
}
else
{
printf("Grade F");
}
}

return 0;
}
8. Write a C program, to check whether a person is eligible for the marriage or not.

#include<stdio.h>

int main()
{
int age;
char gender;

printf("Enter Gender(m/f) and Age\n");


scanf("%c%d",&gender,&age);

if(gender=='m')
{
if(age>=21)
printf("You can marry");
else
printf("You can not marry");
}
else if(gender=='f')
{
if(age>=18)
printf("You can marry");
else
printf("You can not marry");
}
else
printf("Invalid input Gender");

return 0;
}
9. Write a C program to identify the quadrant of a point, when coordinates (x,y) are given.

#include <stdio.h>
int main()
{
int x,y;

printf("Input the values for X and Y coordinate\n");


scanf("%d %d",&x,&y);

if( x > 0 && y > 0)


printf("The coordinate point x=%d and y=%d lies in the First quandrant.\n",x,y);
else if( x < 0 && y > 0)
printf("The coordinate point x=%d and y=%d lies in the Second quandrant.\n",x,y);
else if( x < 0 && y < 0)
printf("The coordinate point x=%d and y=%d lies in the Third quandrant.\n",x,y);
else if( x > 0 && y < 0)
printf("The coordinate point x=%d and y=%d lies in the Fourth quandrant.\n",x,y);
else if( x == 0 && y == 0)
printf("The coordinate point x=%d and y=%d lies at the origin.\n",x,y);

return 0;
}
10. Write a C program to compute area of the following of geometric objects based on user’s
preference using switch case:
i. Circle
ii. Triangle
iii. Parallelogram
iv. Square

#include<stdio.h>
#include<math.h>
int main()
{
int choice;
printf("Enter You Choice\n1 to find area of Circle\n2 for finding area of Triangle\n3 for finding
area of Parallelogram\n4 for finding area of Square\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
float radius,area;
printf("Enter Radius of Circle\n");
scanf("%f",&radius);
area=3.14159*radius*radius;
printf("Area of Circle %f\n",area);
break;
}
case 2:
{
int a,b,c;
float s,area;
printf("Enter sides of triangle\n");
scanf("%d%d %d",&a,&b,&c);
s=(float)(a+b+c)/2;
area=(float)(sqrt(s*(s-a)*(s-b)*(s-c)));
printf("Area of Triangle is %f\n",area);
break;
}
case 3:
{
float base,height,area;
printf("Enter base and height of Parallelogram\n");
scanf("%f %f",&base,&height);
area=base*height;
printf("Enter area of Parallelogram is %f\n",area);
break;
}
case 4:
{
float side,area;
printf("Enter Sides of Square\n");
scanf("%f",&side);
area=side*side;
printf("Area of Square is %f\n",area);
break;

}
default:
{
printf("Invalid Choice\n");
break;
}
}
return 0;
}
Part - B

11. Write a C program to check whether the given number is palindrome or not.

#include <stdio.h>

int main()
{
int n, rev = 0, rem, orig;

printf("Enter an integer\n");
scanf("%d", &n);

orig=n;

while (n != 0)
{
rem = n % 10;
rev = rev * 10 + rem;
n = n/10;
}

if (orig == rev)
printf("%d is a palindrome.", orig);
else
printf("%d is not a palindrome.", orig);

return 0;
}
12. Write a C program to generate the prime numbers between 1 to n.

#include<stdio.h>

int main()
{
int i,j,count,n;
printf("Enter number to genetrate prime number between 2 and the number\n");
scanf("%d",&n);

for(i=2;i<=n;i++)
{
count = 0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
count++;
break;
}
}

if(count==0)
printf("%d ",i);
}

return 0;
}
13. Write a C program to sort the given list using selection sort technique.

#include <stdio.h>
int main()
{
int a[100],n,i,j,swap;

printf("Enter number of elements\n");


scanf("%d", &n);

printf("Enter %d Numbers\n",n);

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


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

for(i = 0; i < n - 1; i++)


{
for(j = i + 1; j < n; j++)
{
if(a[i] > a[j])
{
swap=a[i];
a[i]=a[j];
a[j]=swap;
}
}
}

printf("\nSorted Values in Ascending Order\n");

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


printf("%d\n", a[i]);

return 0;
}
14. Write a C program to find the sum of rows and columns of the given matrix.
#include <stdio.h>

int main()
{
int arr1[10][10], rsum[10], csum[10],r,c,i,j;

printf("Input the size of the square matrix : ");


scanf("%d %d", &r,&c);

printf("Input elements in the first matrix :\n");


for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("element - [%d],[%d] : ",i,j);
scanf("%d",&arr1[i][j]);
}
}

printf("The matrix is :\n");


for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("% 4d",arr1[i][j]);
printf("\n");
}

/* Sum of rows */
for(i=0;i<r;i++)
{
rsum[i]=0;
for(j=0;j<c;j++)
rsum[i]=rsum[i]+arr1[i][j];
}

/* Sum of Column */
for(i=0;i<c;i++)
{
csum[i]=0;
for(j=0;j<r;j++)
csum[i]=csum[i]+arr1[j][i];
}

printf("The sum or rows and columns of the matrix is\n");


for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("% 4d",arr1[i][j]);
printf("% 8d",rsum[i]);
printf("\n");
}

printf("\n");

for(j=0;j<c;j++)
printf("% 4d",csum[j]);
printf("\n\n");

return 0;
}
15. Write a C Program to check whether given string is palindrome or not.

#include <stdio.h>
#include <string.h>

int main()
{
char string1[20];
int i, length;
int flag = 0;

printf("Enter a string\n");
scanf("%s", string1);

length = strlen(string1);

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


{
if(string1[i] != string1[length-i-1])
{
flag = 1;
break;
}
}

if (flag)
{
printf("%s is not a palindrome", string1);
}
else
{
printf("%s is a palindrome", string1);
}
return 0;
}
16. Write a C Program to append the contents of one string to the other string without using
string handling functions.

#include<stdio.h>

int main()
{

char str1[100], str2[100], str3[100];


int i = 0, j = 0;

printf("Enter First string\n");


gets(str1);

printf("Enter Second string\n");


gets(str2);

while (str1[i] != '\0')


{
str3[j] = str1[i];
i++;
j++;
}

i = 0;
while (str2[i] != '\0')
{
str3[j] = str2[i];
i++;
j++;
}

str3[j] = '\0';

printf("\nConcatenated string is %s", str3);

return 0;
}
17. Write a C program to find the value of an using user-defined function.

#include <stdio.h>

int power(int b, int e);

int main()
{
int base, exp, result;

printf("Enter base number\n ");


scanf("%d", &base);
printf("Enter power number(positive integer)\n");
scanf("%d", &exp);

result = power(base, exp);

printf("%d^%d = %d", base, exp, result);


return 0;
}

int power(int b, int e)


{
int i,res;
res=b;
for(i=1;i<e;i++)
res=res*b;
return res;
}
18. Write a C program to find the factorial of a number using recursive function.

#include<stdio.h>

int fact(int n);

int main()
{
int n,res;
printf("Enter a positive integer\n ");
scanf("%d",&n);

res=fact(n);

printf("Factorial of %d = %d", n, res);


return 0;
}

int fact(int n)
{
if (n>=1)
return n*fact(n-1);
else
return 1;
}
19. Write a C program that defines the Employee structure with the following properties:
Employee id, Employee name, Basic Salary, Date of birth.
Read the details of 3 employees, calculate the Net salary and display the same.

#include <stdio.h>

int main()
{
struct employee
{
int empid;
char name[30];
char dob[10];
int bs;
int ns;
} emp[3];

int i,gs;

printf("Enter 3 Employee Details \n \n");

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


{
printf("Enter %d Employee Details \n \n",i+1);

printf("Enter Employee ID\n");


scanf("%d",&emp[i].empid);

printf("Enter Name\n");
scanf("%s",emp[i].name);

printf("Enter Date of Birth\n");


scanf("%s",emp[i].dob);

printf("Enter Employee Basic Salary\n");


scanf("%d",&emp[i].bs);

gs=emp[i].bs+(emp[i].bs*0.4)+(emp[i].bs*0.2);

emp[i].ns=gs-gs*0.12;
printf("\n");
}

printf("-------------- All Emploeyees Details ---------------\n");


for(i=0; i<3; i++)
{
printf("Employee ID \t:%d\n",emp[i].empid);
printf("Employee Name\t:%s\n",emp[i].name);
printf("Employee DoB\t:%s\n",emp[i].dob);
printf("Employee Basic Salary\t:%d\n",emp[i].bs);
printf("Employee Net Salary\t:%d\n",emp[i].ns);
printf("\n");
}
return 0;
}
20. Write a C program to read two numbers and swap them with help of function through call
by reference method.

#include <stdio.h>

int swap(int*, int*);

int main()
{
int x, y;

printf("Enter the value of x and y\n");


scanf("%d %d",&x,&y);

printf("Values Before Swapping\nx = %d\ny = %d\n", x, y);

swap(&x, &y);

printf(“Values After Swapping\nx = %d\ny = %d\n", x, y);

return 0;
}

int swap(int *a, int *b)


{
int temp;

temp = *b;
*b = *a;
*a = temp;
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