0% found this document useful (0 votes)
1 views11 pages

PSPC Kavya Lab File

The document contains a series of C programming exercises, including self-introduction, calculations for simple interest, swapping numbers, finding the greatest of three numbers, checking even or odd numbers, performing arithmetic operations using switch-case, calculating areas of various shapes, and finding the factorial of a number. Each exercise is accompanied by code snippets and outputs. The author of the programs is consistently mentioned as 'kavya'.

Uploaded by

atharv rohilla
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)
1 views11 pages

PSPC Kavya Lab File

The document contains a series of C programming exercises, including self-introduction, calculations for simple interest, swapping numbers, finding the greatest of three numbers, checking even or odd numbers, performing arithmetic operations using switch-case, calculating areas of various shapes, and finding the factorial of a number. Each exercise is accompanied by code snippets and outputs. The author of the programs is consistently mentioned as 'kavya'.

Uploaded by

atharv rohilla
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

PSPC- LAB

1. Write a C program that prints a small demo/introduction of yourself


#include <stdio.h>

void main() {
printf("===== My Self Introduction =====\n\n");

printf("Hello, my name is kavya kumar pandey.\n");

printf("I am a day scholar");

printf(“my course is ai/ml”);

}
2. Write a C Program to calculate Simple Interest (SI) and Amount
Code:-

#include <stdio.h>

int main() {

float P, R, T, SI, Amount;

printf("Enter Principal: ");


scanf("%f", &P);

printf("Enter Rate of Interest: ");


scanf("%f", &R);

printf("Enter Time (in years): ");

scanf("%f", &T);

SI = (P * R * T) / 100;

Amount = P + SI;
printf("\n===== Simple Interest Calculation =====\n");

printf("Principal = %f \n", P);

printf("Rate = %\n", R);

printf("Time = %f years\n", T);

printf("Simple Interest = %f\n", SI);


printf("Total Amount = %f\n", Amount);

printf("made by kavya");

return 0;
}
3. WAP to Swap Two Numbers Using Third Variable

#include <stdio.h>

int main() {

int a, b, temp;

printf("Enter number for a: ");

scanf("%d", &a);
printf("Enter number for b: ");

scanf("%d", &b);

// Swap using third variable

temp = a;

a = b;

b = temp;

printf("After swapping: a = %d, b = %d\n", a, b);


printf("made by kavya");

return 0;

}
4. WAP to demonstrate Greatest of 3 numbers nos and to print the
given no in ascending order.
Code:-
#include <stdio.h>
int main() {

int a, b, c, temp;

// Input three numbers

printf("Enter three numbers: ");

scanf("%d %d %d", &a, &b, &c);

// Find the greatest number

if (a >= b && a >= c)


printf("Greatest number = %d\n", a);

else if (b >= a && b >= c)

printf("Greatest number = %d\n", b);

else

printf("Greatest number = %d\n", c);

// Arrange in ascending order

if (a > b) { temp = a; a = b; b = temp; }

if (a > c) { temp = a; a = c; c = temp; }


if (b > c) { temp = b; b = c; c = temp; }

printf("Numbers in ascending order: %d %d %d\n", a, b, c);

printf(“made by kavya”);

return 0;
}
5. WAP to check if the number is even or odd.
Code:-

#include <stdio.h>

int main() {

int num;

// Input a number

printf("Enter a number: ");


scanf("%d", &num);

// Check even or odd

if (num % 2 == 0)

printf("%d is Even\n", num);

else

printf("%d is Odd\n", num);

printf(“made by kavya”);
return 0;

}
6. WAP to perform arithmetic operations using Switch Case
statement.
Code:-
#include <stdio.h>

int main() {

int a, b, ch;

printf("Enter two numbers: ");

scanf("%d %d", &a, &b);

printf("[Link] [Link] [Link] [Link]\nEnter choice: ");


scanf("%d", &ch);

switch(ch) {

case 1: printf("Result = %d\n", a+b); break;

case 2: printf("Result = %d\n", a-b); break;

case 3: printf("Result = %d\n", a*b); break;

case 4: b!=0 ? printf("Result = %.2f\n",(float)a/b) : printf("Error: Divide by 0\n"); break;

default: printf("Invalid choice!\n");


}

Printf(“made by kavya”);
return 0;

}
7. WAP to calculate area of circle, rectangle, square and triangle using
Switch Case statement.
Code:
#include <stdio.h>

int main() {

int ch;

float area, r, l, b, s, h;

printf("[Link]\[Link]\[Link]\[Link]\nEnter choice: ");

scanf("%d", &ch);
switch(ch) {

case 1:

printf("Enter radius: ");

scanf("%f", &r);

area = 3.14 * r * r;

printf("Area of Circle = %.2f\n", area);

break;
case 2:

printf("Enter length and breadth: ");


scanf("%f %f", &l, &b);

area = l * b;

printf("Area of Rectangle = %.2f\n", area);

break;

case 3:
printf("Enter side: ");

scanf("%f", &s);

area = s * s;
printf("Area of Square = %.2f\n", area);
break;

case 4:

printf("Enter base and height: ");

scanf("%f %f", &b, &h);


area = 0.5 * b * h;

printf("Area of Triangle = %.2f\n", area);

break;

default:

printf("Invalid choice!\n");

Printf(“made by kavya”);

return 0;

LABORATORY SESSSION 2 (LOOPING)


8. WAP to find factorial of a Number.
Code:-
#include<stdio.h>

int main()

int num, i, fact=1;

printf("Enter a number : ");

scanf("%d",&num) ;
for (i=1;i<=num;i++)

fact=fact*i;

printf("Factorial of %d is : %d", num, fact);

printf(“made by kavya”);

return 0;

You might also like