PPA Lab
PPA Lab
Explanation:
Explanation:
return 0;
}
Explanation:
● Input: Numbers entered by the user are stored in num1 and num2.
● Processing: sum = num1 + num2 calculates the sum.
● Output: Displays the result using printf.
return 0;
}
Explanation:
● Logic:
1. Add a and b and store in a (a = a + b).
2. Subtract the new a with b to get the original a in b.
3. Subtract the new b from a to get the original b in a.
return 0;
}
Explanation:
● Logic:
○ Extract the last digit using num % 10.
○ Add the digit to sum.
○ Remove the last digit by dividing num by 10.
○ Repeat until num becomes 0.
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
if (num % 2 == 0)
else
return 0;
Explanation:
● num % 2 == 0: Checks if the number is divisible by 2 (even). If true, it prints "even";
otherwise, it prints "odd".
Lab-7: WAP to Check Whether the Given Year is Leap Year or Not
#include <stdio.h>
int main() {
int year;
scanf("%d", &year);
else
return 0;
Explanation:
● A year is a leap year if it is divisible by 400, or if divisible by 4 but not divisible by 100.
Lab-8: WAP to Find Out the Greatest Number Among 3 Numbers
#include <stdio.h>
int main() {
int a, b, c;
else
return 0;
}
Explanation:
● The program compares the three numbers to find the greatest using conditional
if-else statements.
Lab-9: WAP to Check Whether the Given Character is a Vowel or Not Using
Switch Case
#include <stdio.h>
int main() {
char ch;
scanf("%c", &ch);
switch(ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
break;
default:
return 0;
Explanation:
● The program uses a switch statement to check if the entered character is a vowel (both
lowercase and uppercase).
#include <stdio.h>
int main() {
scanf("%d", &num);
for (int i = 1; i <= num; i++) {
return 0;
Explanation:
● The program uses a loop to multiply all integers from 1 to num to compute the factorial.
#include <stdio.h>
int main() {
scanf("%d", &n);
scanf("%d", &num);
sum += num;
return 0;
Explanation:
● The program prompts the user for n numbers and adds them together using a for loop.
#include <stdio.h>
int main() {
scanf("%d", &num);
while (num != 0) {
reversed = reversed * 10 + num % 10; // Get the last digit and
build the reverse
return 0;
Explanation:
● This program reverses the number by extracting its digits and building the reversed
number.
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
return 0;
Explanation:
● This program prints the multiplication table of a given number from 1 to 10.
#include <stdio.h>
int main() {
scanf("%d", &num);
if (num <= 1) {
return 0;
}
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
break;
if (is_prime)
else
return 0;
Explanation:
● This program checks if a number is prime by dividing it by all numbers from 2 to num/2.
#include <stdio.h>
#include <math.h>
int main() {
scanf("%d", &num);
temp = num;
while (temp != 0) {
temp /= 10;
count++;
temp = num;
while (temp != 0) {
temp /= 10;
if (sum == num)
return 0;
Explanation:
● An Armstrong number is a number that is equal to the sum of its own digits raised to the
power of the number of digits.
#include <stdio.h>
int main() {
scanf("%d", &n);
next = i;
else {
first = second;
second = next;
return 0;
Explanation:
● The program calculates the Fibonacci series, where each term is the sum of the two
preceding ones. The first two terms are 0 and 1, and then the program prints the next
terms based on the sum.
// Program to print the sine and cosine series for a given angle
#include <stdio.h>
#include <math.h>
int main() {
scanf("%lf", &angle);
sine_value = sin(angle);
cosine_value = cos(angle);
return 0;
Explanation:
● This program calculates the sine and cosine values for a given angle in degrees by
converting it to radians first using the formula (degrees * π) / 180.
#include <stdio.h>
int factorial(int num) {
int fact = 1;
fact *= i;
return fact;
int main() {
int n, r;
return 0;
Explanation:
● The program calculates the combination nCr using the formula nCr = n! / (r! *
(n - r)!), where n! is the factorial of n.
#include <stdio.h>
int fact = 1;
fact *= i;
return fact;
int main() {
int rows;
scanf("%d", &rows);
printf("\n");
return 0;
Explanation:
● The program prints Pascal’s triangle using the combination formula nCr for each
element in the triangle. It loops through rows and columns to generate the values.
#include <stdio.h>
int main() {
scanf("%d", &num);
if (num % i == 0)
sum += i; // Sum of divisors
if (sum == num)
else
return 0;
Explanation:
● A perfect number is a number that is equal to the sum of its proper divisors (excluding
the number itself). This program checks for this property.
#include <stdio.h>
if (b == 0)
return a;
}
int main() {
return 0;
Explanation:
● The program uses the Euclidean algorithm to calculate the GCD (Greatest Common
Divisor) of two numbers recursively.
#include <stdio.h>
int main() {
while (num != 0) {
count++;
return 0;
Explanation:
● This program uses a while loop to repeatedly divide the number by 10 until it becomes
zero, counting how many digits the number has.
#include <stdio.h>
if (num == 0 || num == 1)
return 1;
int main() {
int num;
scanf("%d", &num);
return 0;
Explanation:
● The program uses recursion to calculate the factorial. The base case is when num is 0 or
1, which returns 1.
#include <stdio.h>
int sum = a + b;
int main() {
int x = 5, y = 3;
return 0;
Explanation:
● In Call by Value, the actual values of x and y are passed to the function add. The
function performs the addition, but the values in the main function remain unchanged.
#include <stdio.h>
}
int main() {
int x = 5, y = 3;
return 0;
Explanation:
● In Call by Reference, the addresses of x and y are passed to the function. The function
can modify the actual values of x and y.