0% found this document useful (0 votes)
6 views

Practical Assignment 1 (A)

Uploaded by

Karan Ajudiya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Practical Assignment 1 (A)

Uploaded by

Karan Ajudiya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Defination 1

//Write a program to make addition of two numbers and display the summation.

#include<stdio.h>

void summation(int a,int b)

printf("summation: %d",a+b);

int main ()

int a,b;

printf("enter a value for a and b");

scanf("%d",&a);

scanf("%d",&b);

summation(a,b);

}
––

Defination 2
//Write a program to input Student Name, Branch, Semester, CGPA, and Age and display it.

#include<stdio.h>

void main ()

float cgpa;

int sem,age;

char student_name,branch;

printf("enter the student_name : ");

scanf("%s",&student_name);

printf("enter the branch : ");

scanf("%s",&branch);

printf("enter the sem : ");

scanf("%d",&sem);

printf("enter the age : ");

scanf("%d",&age);

printf("enter the cgpa : ");

scanf("%lf",&cgpa);

}
Defination 3

// Write a program to display addition, subtraction, multiplication and division of two integers on
screen.

#include<stdio.h>

void main ()

int summ,subt,multi,divi,a,b;

printf("enter any two intergers number");

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

printf("summ :%d\n",a+b);

printf("subt :%d\n",a-b);

printf("multi :%d\n",a*b);

printf("divi :%d\n",a/b);

}
Defination 4

//Write a program to find area of circle. (Area of Circle = PI * r * r )

#include<stdio.h>

void main ()

float pi=3.14,r,area;

printf("enter the values");

scanf("%f",&r);

area=pi*r*r;

printf("%f",area);

}
Defination 5
//Write a program to check whether the entered number is even or odd. (User Define Function)

#include<stdio.h>

void main ()

int a;

printf("enter the value is odd or even");

scanf("%d",&a);

if(a%2==0)

printf("number is even",a);

else

printf("number is odd",a);

}
Defination 6
//. Write a program to find maximum between two numbers.

#include <stdio.h>

int find_maximum(int num1, int num2) {

if (num1 > num2) {

return num1;

} else {

return num2;

int main() {

int number1, number2;

printf("Enter the first number: ");

scanf("%d", &number1);

printf("Enter the second number: ");

scanf("%d", &number2);

int maximum_number = find_maximum(number1, number2);

printf("The maximum between %d and %d is: %d\n", number1, number2, maximum_number);

return 0;

}
Defination 7
// Write a program to Find Maximum from Three numbers.(User Define Function)

#include <stdio.h>

int find_maximum(int num1, int num2, int num3)

int max = num1;

if (num2 > max)

max = num2;

if (num3 > max)

max = num3;

return max;

int main()

int number1, number2, number3;

printf("Enter the first number: ");

scanf("%d", &number1);

printf("Enter the second number: ");

scanf("%d", &number2);
printf("Enter the third number: ");

scanf("%d", &number3);

int maximum_number = find_maximum(number1, number2, number3);

printf("The maximum among %d, %d, and %d is: %d\n", number1, number2, number3,
maximum_number);

return 0;

}
Defination 8
//Write a program to input 5 numbers in an array and display it.

#include <stdio.h>

int main()

// Declare an array to store 5 numbers

int numbers[5],i;

// Input phase: Read 5 numbers from the user

printf("Enter 5 numbers:\n");

for(i=0;i<5; ++i)

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

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

// Output phase: Display the entered numbers

printf("\nEntered numbers are:\n");

for (i = 0; i < 5; ++i)

printf("%d ", numbers[i]);

return 0;

}
Defination 9
//Write a program to input 5 subject marks using array and display total marks and average marks.

#include <stdio.h>

int main()

// Declare an array to store marks for 5 subjects

int marks[5],i;

// Input phase: Read marks for 5 subjects

printf("Enter marks for 5 subjects:\n");

for ( i = 0; i < 5; ++i)

printf("Enter marks for subject %d: ", i + 1);

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

// Calculate total and average marks

int total = 0;

for ( i = 0; i < 5; ++i)

total += marks[i];

float average = (float)total / 5;

// Output phase: Display total and average marks

printf("\nTotal Marks: %d\n", total);

printf("Average Marks: %.2f\n", average);

return 0;
}
Defination 10

//. Write a program to find maximum number from an array.

#include <stdio.h>

int find_maximum(int arr[], int size)

int max = arr[0],i; // Assume the first element as the maximum

// Iterate through the array to find the maximum

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

if (arr[i] > max)

max = arr[i];

return max;

int main()

// Declare an array

int numbers[] = {12, 45, 67, 23, 89, 34, 56};

// Calculate the size of the array

int size = sizeof(numbers) / sizeof(numbers[0]);

// Find the maximum number in the array


int maximum_number = find_maximum(numbers, size);

// Display the result

printf("The maximum number in the array is: %d\n", maximum_number);

return 0;

}
Defination 11
//Write a program to input two umbers from user and perform all the basic arithmetic operations.
Here

use switch case to make menu driven programming.

#include <stdio.h>

int main()

float num1, num2, result;

int choice;

// Input phase: Get two numbers from the user

printf("Enter the first number: ");

scanf("%f", &num1);

printf("Enter the second number: ");

scanf("%f", &num2);

// Menu for arithmetic operations

printf("\nChoose an operation:\n");

printf("1. Addition\n");

printf("2. Subtraction\n");

printf("3. Multiplication\n");

printf("4. Division\n");

// Get the user's choice

printf("Enter your choice (1-4): ");

scanf("%d", &choice);

// Perform the selected arithmetic operation

switch (choice)
{

case 1:

result = num1 + num2;

printf("Result: %.2f\n", result);

break;

case 2:

result = num1 - num2;

printf("Result: %.2f\n", result);

break;

case 3:

result = num1 * num2;

printf("Result: %.2f\n", result);

break;

case 4:

if (num2 != 0)

result = num1 / num2;

printf("Result: %.2f\n", result);

} else

printf("Error: Division by zero is undefined.\n");

break;

default:

printf("Invalid choice. Please choose a number between 1 and 4.\n");

return 0;

You might also like