0% found this document useful (0 votes)
12 views48 pages

Practical File For PPS

Uploaded by

simmi81990
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)
12 views48 pages

Practical File For PPS

Uploaded by

simmi81990
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/ 48

PROGRAM-1

Aim-To print hello world

Source Code
#include<stdio.h>
#include<conio.h>
void main ()
{
clrscr();
printf("hello");
getch();
}

Output
PROGRAM-2
Aim-To print your own name

Source Code
#include <stdio.h>
int main(void)
{
char name[25] ;
printf("what's your name ?") ;
scanf("%s", name) ;
printf ("your name is %s", name) ;
return 0 ;
}

Output
PROGRAM-3
Aim-To print the sum of two number

Source Code
#include <stdio.h>
int main()
{
int num1,num2,sum;
printf("Enter two integers: ");
scanf("%d %d", &num1, &num2);
sum = num1 + num2;
printf("%d + %d = %d", num1, num2, sum);
return 0;
}

Output
Program-4
Aim- To find area of circle

Source Code
#include <stdio.h>

#define PI 3.14159

int main()

float radius, area;

printf("Enter the radius of the circle: ");

scanf("%f", &radius);

area = PI * radius * radius;

printf("The area of the circle is: %f", area);

return 0;

Output
Program-5
Aim- To find simple interest
Source Code

#include <stdio.h>

int main()

float principle, time, rate, SI;

/* Input principle, rate and time */

printf("Enter principle (amount): ");

scanf("%f", &principle);

printf("Enter time: ");

scanf("%f", &time);

printf("Enter rate: ");

scanf("%f", &rate);

/* Calculate simple interest */

SI = (principle * time * rate) / 100;

/* Print the resultant value of SI */

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

return 0;

}
Output
Program-6
Aim- To convert fahrenheit to celsius

#include<stdio.h>
#include<conio.h>
void main()
{
float fahren, celsius;
printf("enter temprature in fahrenheit=");
scanf("%f",&fahren);
celsius=(fahren-32)*5.0/9.0;
printf("%.2f fahrenheit is equal %.2f in celsius", fahren, celsius);
getch();
}

Output
PROGRAM-7
Aim-To find even and odd number

Source Code

#include <stdio.h>
int main()
{
int a;
printf("Enter a: ");
scanf("%d", &a);

//logic
if (a % 2 == 0) {
printf("The given number is EVEN");
}
else {
printf("The given number is ODD");
}
return 0;
}

Output
Program-8
Aim-To find greatest of three numbers using if only
Source Code

#include <stdio.h>

int main()

int a, b, c;

printf("Enter three numbers: \n a: ");

scanf("%d", &a);

printf("b: ");

scanf("%d", &b);

printf("c: ");

scanf("%d", &c);

if (a > b && a > c)

printf("Biggest number is %d", a);

if (b > a && b > c)

printf("Biggest number is %d", b);

if (c > a && c > b)

printf("Biggest number is %d", c);

return 0;

}
Output
Program-9
Aim- To find greatest of three numbers using if else
Source Code
#include <stdio.h>

int main()

double n1, n2, n3;

printf("Enter three different numbers: ");

scanf("%lf %lf %lf", &n1, &n2, &n3);

// if n1 is greater than both n2 and n3, n1 is the largest

if (n1 >= n2 && n1 >= n3)

printf("%.2f is the largest number.", n1);

// if n2 is greater than both n1 and n3, n2 is the largest

if (n2 >= n1 && n2 >= n3)

printf("%.2f is the largest number.", n2);

// if n3 is greater than both n1 and n2, n3 is the largest

if (n3 >= n1 && n3 >= n2)

printf("%.2f is the largest number.", n3);

return 0;

}}
Output
Program-10

AIM-To takes input at runtime for attendance and marks criteria and then
checks whether a student meets the attendance and marks criteria using nested if
statements.

Source Code

#include <stdio.h>

int main() {

float attendance_criteria, marks_criteria;

float student_attendance, student_marks;

printf("Enter attendance criteria (in percentage): ");

scanf("%f", &attendance_criteria);

printf("Enter marks criteria (out of 100): ");

scanf("%f", &marks_criteria);

printf("Enter student's attendance (in percentage): ");

scanf("%f", &student_attendance);

printf("Enter student's marks (out of 100): ");

scanf("%f", &student_marks);

if (student_attendance >= attendance_criteria && student_marks >= marks_criteria) {

printf("Congratulations! The student meets both attendance and marks criteria.\n");

} if (student_attendance < attendance_criteria && student_marks < marks_criteria) {

if (student_attendance < attendance_criteria) {

printf("The student does not meet the attendance criteria.\n");

if (student_marks < marks_criteria) {


printf("The student does not meet the marks criteria.\n");

return 0;

Output
Program- 11

AIM- To print the number from 1 to 10 using loop

Source Code using for loop

#include<stdio.h>

void main()

int i;

printf("The first 10 natural numbers are:\n ");

for (i = 1; i <= 10; i++)

printf("%d \t", i );

Output
Source Code using while loop

#include <stdio.h>

int main() {

int i = 1;

while (i <= 10) {

printf("%d\n", i);

i++;

return 0;

Output
Source Code using Do while loop

#include <stdio.h>

int main() {

int i = 1;

do {

printf("%d\n", i);

i++;

} while (i <= 10);

return 0;

Output
Program-12
AIM – To Print the Star pattern (right half pyramid and inverted right half pyramid)

For right half pyramid

Source Code using for loop


#include <stdio.h>

int main()

int i, j, rows;

printf("Enter the number of rows: ");

scanf("%d", &rows);

for(i = 1; i <= rows; ++i) {

for(j = 1; j <= i; ++j) {

printf("* ");

printf("\n");

return 0;

Output
Source Code using while loop
#include <stdio.h>

int main() {

int i, j, rows;

printf("Enter the number of rows: ");

scanf("%d", &rows);

i = 1;

while(i <= rows) {

j = 1;

while(j <= i) {

printf("* ");

j++;

printf("\n");

i++;

return 0;

Output
For inverted right half pyramid

Source Code using for loop


#include <stdio.h>

int main() {

int i, j, rows;

printf("Enter the number of rows: ");

scanf("%d", &rows);

for(i = rows; i >= 1; --i) {

for(j = 1; j <= i; ++j) {

printf("* ");

printf("\n");

return 0;

Output
Source Code using while loop
#include <stdio.h>

int main() {

int i, j, rows;

printf("Enter the number of rows: ");

scanf("%d", &rows);

i = rows;

while(i >= 1) {

j = 1;

while(j <= i) {

printf("* ");

j++;

printf("\\n");

i--;

return 0;

Output
Program-13
AIM- To print input elements using 1D array
Source Code

#include <stdio.h>
int main()
{
int size;
printf("Enter the size of the array: ");
scanf("%d", &size);
int array[size];
printf("Enter %d values for the array:\n", size);
for (int i = 0; i < size; i++) {
scanf("%d", &array[i]);
}
printf("\nArray elements are:\n");
for (int i = 0; i < size; i++) {
printf("%d ", array[i]);
}
printf("\n");
return 0;
}

Output
Program-14
AIM- To print input elements using 2D array

Source Code
#include <stdio.h>

int main()

int rows, cols;

printf("Enter the number of rows: ");

scanf("%d", &rows);

printf("Enter the number of columns: ");

scanf("%d", &cols);

int array[rows][cols];

printf("Enter %d values for the array:\n", rows * cols);

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

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

}}

printf("\nArray elements are:\n");

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

printf("%d ", array[i][j]);

printf("\n");
}

return 0;

Output
Program-15
AIM- To print the sum of all array elements

Source Code
#include <stdio.h>

int main()

int size;

int sum = 0;

printf("Enter the size of the array: ");

scanf("%d", &size);

int array[size];

printf("Enter %d values for the array:\n", size);

for (int i = 0; i < size; i++) {

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

sum += array[i];

printf("\nThe sum of array elements is: %d\n", sum);

return 0;

}
Output
Program-16
AIM- To add two matrix

Source Code
#include <stdio.h>

int main()

int rows, cols;

printf("Enter the number of rows and columns of the matrices: ");

scanf("%d %d", &rows, &cols);

int matrix1[10][10], matrix2[10][10], sum[10][10];

printf("Enter the elements of the first matrix:\n");

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

printf("Enter element (%d, %d): ", i + 1, j + 1);

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

printf("Enter the elements of the second matrix:\n");

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

printf("Enter element (%d, %d): ", i + 1, j + 1);

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

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

sum[i][j] = matrix1[i][j] + matrix2[i][j];


}

printf("\nSum of the matrices:\n");

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

printf("%d ", sum[i][j]);

printf("\n");

return 0;

Output
Program-17
AIM- To read and print a string

Source Code
#include <stdio.h>

int main()

char str[100];

printf("Enter a string: ");

fgets(str, sizeof(str), stdin);

printf("You entered: %s", str);

return 0;

Output
Program-18
AIM- To find length of a string

Source Code
#include <stdio.h>

#include <string.h>

int main()

char Str[1000];

int i;

printf("Enter the String: ");

scanf("%s", Str);

for (i = 0; Str[i] != '\0'; ++i);

printf("Length of Str is %d", i);

return 0;

Output
Program-19
AIM- To concatenate two strings

Source Code
#include <stdio.h>

int main()

char s1[100] = "Kold ", s2[] = "World";

int length, j;

length = 0;

while (s1[length] != '\0') {

++length;

for (j = 0; s2[j] != '\0'; ++j, ++length) {

s1[length] = s2[j];

s1[length] = '\0';

printf("After concatenation: ");

puts(s1);

return 0;

Output
Program-20
AIM- To compare two strings

Source Code
#include <stdio.h>
#include<string.h>
int main()
{
char str1[20];
char str2[20];
int value;
printf("Enter the first string : ");
scanf("%s",str1);
printf("Enter the second string : ");
scanf("%s",str2);
value=strcmp(str1,str2);
if(value==0)
printf("strings are same");
else
printf("strings are not same");
return 0;
}

Output
Program-21
AIM- To find square root of a given number

Source Code
#include <math.h>

#include <stdio.h>

int main()

double number, squareRoot;

printf("Enter a number: ");

scanf("%lf", &number);

squareRoot = sqrt(number);

printf("Square root of %.2lf = %.2lf", number, squareRoot);

return 0;

Output
Program-22
AIM- To calculate the sum of two numbers using functions

Source Code
#include <stdio.h>

int main()

int number1, number2, sum;

printf("Enter two integers: ");

scanf("%d %d", &number1, &number2);

sum = number1 + number2;

printf("%d + %d = %d", number1, number2, sum);

return 0;

Output
Program-23

AIM- To swap two numbers using call by value

Source Code
#include <stdio.h>

int main()

int x, y;

printf("Enter Value of x ");

scanf("%d", &x);

printf("\nEnter Value of y ");

scanf("%d", &y);

int temp = x;

x = y;

y = temp;

printf("\nAfter Swapping: x = %d, y = %d", x, y);

return 0;

Output
Program-24
AIM- To swap two numbers using call by reference

Source Code
#include <stdio.h>

void swap(int * num1, int * num2);

int main()

int num1, num2;

printf("Enter two numbers: ");

scanf("%d%d", &num1, &num2);

printf("Before swapping ");

printf("Value of num1 = %d \n", num1);

printf("Value of num2 = %d \n\n", num2);

swap(&num1, &num2);

printf("After swapping ");

printf("Value of num1 = %d \n", num1);

printf("Value of num2 = %d \n\n", num2);

return 0;

void swap(int * num1, int * num2)

int temp;

temp = *num1;
*num1= *num2;

*num2= temp;

Output
Program-25
AIM- To find the factorial of a number using functions

Source Code
#include <stdio.h>
int fact(int);
void main()
{
int no,factorial;
printf("Enter a number: \n");
scanf("%d",&no);
factorial=fact(no);
printf("The Factorial of %d is %d\n",no,factorial);
}
int fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
return f;
}

Output
Program-26
AIM- To reverse a number using functions

Source Code
#include <stdio.h>

// Function to reverse a number

int reverseNumber(int num)

int reversedNum = 0;

reversedNum = num % 10 * 10 + num / 10;

return reversedNum;

int main() {

int number, reversedNumber;

// Input number from user

printf("Enter an integer: ");

scanf("%d", &number);

// Call function to reverse the number

reversedNumber = reverseNumber(number);

// Display the reversed number

printf("Reversed number: %d\n", reversedNumber);

return 0;

}
Output
Program-27
AIM- To check a number is palindrome or not using functions

Source Code
#include <stdio.h>

// Function to check if a number is palindrome

int isPalindrome(int num) {

int reversedNum = 0, originalNum = num;

while (num > 0) {

reversedNum = reversedNum * 10 + num % 10;

num /= 10;

return originalNum == reversedNum;

int main() {

int number;

// Input number from user

printf("Enter an integer: ");

scanf("%d", &number);

// Check if the number is palindrome or not

printf("%d is %s a palindrome.\n", number, isPalindrome(number) ? "" : "not");

return 0;

}
Output
Program-28
AIM- To find maximum value in an array using pointer

Source Code
#include <stdio.h>
int main()
{
long array[100], *maximum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%ld", &size);
printf("Enter %ld integers\n", size);
for ( c = 0 ; c < size ; c++ )
scanf("%ld", &array[c]);
maximum = array;
*maximum = *array;
for (c = 1; c < size; c++)
{
if (*(array+c) > *maximum)
{
*maximum = *(array+c);
location = c+1;
}
}
printf("Maximum element is present at location number %ld and it's value is %ld.\n",
location, *maximum);
return 0;
}
Output
Program-29
AIM- To generate the Fibonacci series

Source Code
#include <stdio.h>

void generateFibonacci(int n)

int a = 0;

int b = 1;

int i;

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

printf("%d ", a);

int temp = a;

a = b;

b = temp + b;

printf("\n");

int main() {

int n;

printf("Enter the number of terms for Fibonacci series: ");

scanf("%d", &n);
generateFibonacci(n);

return 0;

Output
Program-30
AIM- To find Ackermann function

Source Code
#include <stdio.h>

int ackermann(int m, int n) {

if (m == 0) {

return n + 1;

} else if (n == 0) {

return ackermann(m - 1, 1);

} else {

return ackermann(m - 1, ackermann(m, n - 1));

int main() {

int m, n;

printf("Enter the values of m and n for Ackermann function (m n): ");

scanf("%d %d", &m, &n);

int result = ackermann(m, n);

printf("A(%d, %d) = %d\n", m, n, result);

return 0;

}
Output

You might also like