AKTU PROGRAMING FOR PROBLEM SOLVING LAB ( ALL QUESTION )
Download Your File
Click the button below to download your PDF file:
📄 Download PDFDownload All Question In PDF Form.
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(){int m, p, c, h, e;printf("Enter Math Marks: ");scanf("%d", &m);printf("Enter Physics Marks: ");scanf("%d", &p);printf("Enter Chemestry Marks: ");scanf("%d", &c);printf("Enter English Marks: ");scanf("%d", &e);printf("Enter Hindi Marks: ");scanf("%d", &h);int total = m + p + c + h + e;printf("Total Marks Obtained = %d", total);float avg = total / 5.00;printf("\nAverage of Marks = %.2f %%", avg);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() {
int p, n,option;
float r, t;
printf("Enter the Principal amount: ");
scanf("%d", &p);
printf("Enter the Interest rate(%): ");
scanf("%f", &r);
printf("Enter the Time (years): ");
scanf("%f", &t);
printf("Enter the frequency: ");
scanf("%d", &n);
float CI = p * (pow((1 + r / (100.0 * n)), n * t) - 1);
float SI = (p * r * t) / 100.0;
float total_CI = p + CI; // Total amount for CI
float total_SI = p + SI; // Total amount for SI
printf("\nChoose Compound Interest (1) or Simple Interest (2): ");
scanf("%d", &option);
if (option == 1) {
printf("Compound interest of %d Rs is %.2f Rs\n", p, CI);
printf("Total Amount Payable is %.2f Rs\n", total_CI);
} else if (option == 2) {
printf("Simple interest of %d Rs is %.2f Rs\n", p, SI);
printf("Total Amount Payable is %.2f Rs\n", total_SI);
} else {
printf("Invalid input! Try entering 'c' for Compound Interest or 's' for Simple Interest.\n");
}
return 0;
}
3. WAP to calculate the area and circumference of a circle.
#include <stdio.h>
int main()
{
float pie = 22.0 / 7.0, r;
printf("Enter radius(in meter): ");
scanf("%f", &r);
float circumference = 2 * pie * r;
float area = pie * r * r;
printf("The circle having radius %.2f has area = %.2f m² and circumference = %.2f m\n", r, area, circumference);
return 0;
}
4. WAP that accepts the temperature in Centigrade and converts into Fahrenheit using the formula C/5=(F
4. WAP that accepts the temperature in Centigrade and converts into Fahrenheit using the formula C/5=(F
32)/9.
#include <stdio.h>
int main()
{
int f, c;
printf("Enter temperature in deg Centigrade: ");
scanf("%d", &c);
f = (9.0 / 5.0 * c) + 32;
printf("%d degC is equal to %d degF", c, f);
return 0;
}
#include <stdio.h>
int main()
{
int a,b;
printf("Enter number a = ");
scanf("%d",&a);
printf("Enter number b = ");
scanf("%d",&b);
int c = a;
a = b;
b = c;
printf("a = %d, b = %d", a, b);
return 0;
}
6. WAP that checks whether the two numbers entered by the user are
equal or not.
#include <stdio.h>
int main()
{
int a, b;
printf("Enter two numbers a & b: ");
scanf("%d %d", &a, &b);
if (a == b)
{
printf("Both Numbers are EQUAL");
}
else
{
printf("Both Numbers are NOT EQUAL");
}
return 0;
}
7. WAP to find the greatest of three numbers.
#include <stdio.h>
int main()
{
int a, b, c;
printf("Enter number a = ");
scanf("%d", &a);
printf("Enter number b = ");
scanf("%d", &b);
printf("Enter number c = ");
scanf("%d", &c);
if (a > b)
{
(a > c) ? printf("a is largest") : printf("c is largest");
}
else
{
(b > c) ? printf("b is largest") : printf("c is largest");
}
return 0;
}
8. WAP that finds 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("Your number is EVEN");
}
else
{
printf("Your number is ODD");
}
return 0;
}
9. WAP that tells whether a given year is a leap year or not.
#include <stdio.h>
int main()
{
int year;
printf("Enter year: ");
scanf("%d", &year);
if (year % 4 == 0)
{
printf("%d is leap year.", year);
}
else
{
printf("%d is not a leap year.", year);
}
return 0;
}
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>
int main()
{
int m, p, c, h, e;
printf("Enter Math Marks: ");
scanf("%d", &m);
printf("Enter Physics Marks: ");
scanf("%d", &p);
printf("Enter Chemestry Marks: ");
scanf("%d", &c);
printf("Enter English Marks: ");
scanf("%d", &e);
printf("Enter Hindi Marks: ");
scanf("%d", &h);
int total = m + p + c + h + e;
float avg = total / 5.00;
printf("\nPercentage Obtained = %.2f%% \n", avg);
if (avg >= 90)
{
printf("You scored A grade.");
}
else if (avg >= 80)
{
printf("You scored B grade.");
}
else if (avg >= 60)
{
printf("You scored C grade.");
}
else
{
printf("You scored D grade.");
}
return 0;
}
11. WAP that takes two operands and one operator from the user and
perform the operation and prints the result by using Switch
statement.
#include <stdio.h>
int main()
{
int a, b;
char operator;
printf("Enter a number a = ");
scanf("%d", &a);
printf("Enter a number b = ");
scanf("%d", &b);
getchar();
printf("Enter the Operation(+,-,/,*) = ");
scanf("%c", &operator);
switch (operator)
{
case '+':
printf("%d %c %d = %d", a, operator, b, a + b);
break;
case '-':
printf("%d %c %d = %d", a, operator, b, a - b);
break;
case '*':
printf("%d %c %d = %d", a, operator, b, a * b);
break;
case '/':
printf("%d %c %d = %.2f", a, operator, b, (float)a / b);
break;
default:
printf("Try to Enter(+,-,/,*)");
break;
}
return 0;
}
12. WAP to print the sum of all numbers up to a
given number.
#include <stdio.h>
int main()
{
int sum = 0,n;
printf("Enter number: ");
scanf("%d",&n);
printf("the first %d natural number is\n",n);
for (int i = 1; i <= n; i++)
{
printf("%d ",i);
sum += i;
}
printf("\nThe sum of first %d natural number is %d",n,sum);
return 0;
}
13. WAP to find the factorial of a given number.
#include<stdio.h>
int main () {
int num,fac = 1;
printf("Enter a num: ");
scanf("%d",&num);
for (int i = num; i > 0; i--)
{
fac *= i;
}
printf("Factorial of %d is %d",num,fac);
return 0;
}
14. WAP to print sum of even and odd numbers
from 1 to N numbers.
#include <stdio.h>
int main()
{
int num, evensum = 0, oddsum = 0;
printf("Enter a number = ");
scanf("%d", &num);
for (int i = 1; i <= num; i++)
{
if(i % 2 == 0){
evensum += i;
}else{
oddsum += i;
}
}
printf("Sum of all odd numbers from 0 to %d is %d.",num,oddsum);
printf("\nSum of all even numbers from 0 to %d is %d.",num,evensum);
return 0;
}
15. WAP to print the Fibonacci series.
#include <stdio.h>
int main()
{
int num, a = 0,b = 1,c;
printf("Enter number of terms = ");
scanf("%d", &num);
printf("FIBONCCI Series up to %d term:-\n",num);
for (int i = 0; i < num; i++)
{
printf("%d ",a);
c = a + b;
a = b;
b = c;
}
return 0;
}
16. WAP to check whether the entered number
is prime or not.
#include <stdio.h>
int main()
{
int num, count = 0;
printf("Enter a number = ");
scanf("%d", &num);
for (int i = 1; i <= num; i++)
{
int r = num % i;
if (r == 0)
{
count++;
}
}
if (count > 2)
{
printf("%d is not a PRIME NUMBER", num);
}
else
{
printf("%d is a PRIME NUMBER", num);
}
return 0;
}
17. WAP to find the sum of digits of the
entered number.
#include<stdio.h>
int main () {
int num,sum = 0;
printf("Enter a num: ");
scanf("%d",&num);
for (int i = num; i > 0; i /= 10)
{
int r = i % 10;
sum += r;
}
printf("Sum of digits of %d is %d",num,sum);
return 0;
}
18. WAP to find the reverse of a number.
#include<stdio.h>
int main () {
int num,rev = 0;
printf("Enter a num: ");
scanf("%d",&num);
for (int i = num; i > 0; i /= 10)
{
int r = i % 10;
rev = 10 * rev + r;
}
printf("Reverse of the %d is %d",num,rev);
return 0;
}
19. WAP to print Armstrong numbers
from 1 to 1000.
#include <stdio.h>
#include <math.h>
int main()
{
printf("Armstrong number from 0 to 100 are:-\n");
for (int num = 1; num <= 1000; num ++)
{
int count = 0, temp = 0, sum = 0;
temp = num;
while (temp > 0)
{
count++;
temp /= 10;
}
temp = num;
for (temp; temp > 0; temp /= 10)
{
int rem = temp % 10;
sum += pow(rem, count);
}
if (sum == num)
{
printf("%d ", num);
}
}
return 0;
}
20. WAP to convert binary number into
decimal number and vice versa.
#include <stdio.h>
int main()
{
int binary = 0, rem = 0, base = 1, deci = 0, option;
printf("Enter \"1\" for binary to decimal and \"2\" for decimal to binary: ");
scanf("%d", &option);
if (option == 1)
{
printf("Enter any binary number: ");
scanf("%d", &binary);
int temp = binary;
while (temp > 0)
{
rem = temp % 10;
deci += rem * base;
base *= 2;
temp /= 10;
}
}
else
{
printf("Enter a number: ");
scanf("%d", &deci);
int temp = deci;
while (temp > 0)
{
rem = temp % 2;
binary += rem * base;
base *= 10;
temp /= 2;
}
}
printf("Decimal number %d is equal to %d Binary number.", deci,binary);
return 0;
}