C Programs Soln 2021-22
C Programs Soln 2021-22
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.
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.
16. Write a C Program to append the contents of one string to the other string without using
string handling functions.
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.
Following is the at least expected program for each of above problem titles in the PPC
journal.
Note that,
Still there exists scope to include documentation section, comments for different lines of
code, comments to highlight the logic in the code.
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;
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;
#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;
}
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;
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;
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
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;
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);
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;
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;
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 %d Numbers\n",n);
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;
/* 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("\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);
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()
{
i = 0;
while (str2[i] != '\0')
{
str3[j] = str2[i];
i++;
j++;
}
str3[j] = '\0';
return 0;
}
17. Write a C program to find the value of an using user-defined function.
#include <stdio.h>
int main()
{
int base, exp, result;
#include<stdio.h>
int main()
{
int n,res;
printf("Enter a positive integer\n ");
scanf("%d",&n);
res=fact(n);
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 Name\n");
scanf("%s",emp[i].name);
gs=emp[i].bs+(emp[i].bs*0.4)+(emp[i].bs*0.2);
emp[i].ns=gs-gs*0.12;
printf("\n");
}
#include <stdio.h>
int main()
{
int x, y;
swap(&x, &y);
return 0;
}
temp = *b;
*b = *a;
*a = temp;
return 0;
}