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

final c manual

The document outlines several C programming exercises, including I/O statements, arithmetic operations, prime number generation, array manipulation, matrix multiplication, average height calculation, and BMI computation. Each exercise includes an aim, algorithm, program code, sample output, and a result statement confirming successful execution. The programs cover fundamental programming concepts and demonstrate practical applications of C language.
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)
20 views

final c manual

The document outlines several C programming exercises, including I/O statements, arithmetic operations, prime number generation, array manipulation, matrix multiplication, average height calculation, and BMI computation. Each exercise includes an aim, algorithm, program code, sample output, and a result statement confirming successful execution. The programs cover fundamental programming concepts and demonstrate practical applications of C language.
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/ 31

Ex.

No: 1
PROGRAM USING I/O STATEMENTS AND EXPRESSIONS
Date:

AIM:

To write a C Program to perform I/O statements and expressions.

ALGORITHM:
Step-1: Start the program.
Step-2: Declare variables and initializations.

Step-3: Read the Input variable.


Step-4: Using I/O statements and expressions for computational processing.
Step-5: Display the output of the calculations.
Step-6: Stop.
PROGRAM:
#include <stdio.h>
int main()
{
int sumOdd = 0, sumEven = 0, number=1, limit, Diff;
printf("Enter the limit:");
scanf("%d", & limit);
while (number <= limit)
{
if (number % 2 == 0)
{
sumEven = sumEven +number;
}
else
{
sumOdd =sumOdd +number;
}
++number;
}
if(sumOdd > sumEven)
{
Diff = sumOdd - sumEven;
}
else
{
Diff = sumEven - sumOdd;
}
printf("The sum of odd numbers is %d.\n", sumOdd);
printf("The sum of even numbers is %d.\n",
sumEven);printf("The absolute difference is %d.\n",
Diff);
return 0;
}

1
SAMPLE OUTPUT:
Enter the limit: 10
The sum of odd numbers is 25
The sum of even numbers is 30
The absolute difference is 5

RESULT:

Thus the C Program using I/O statements and expressions successfully.

2
Ex. No: 2
DESIGN A CALCULATOR TO PERFORM BASIC OPERATIONS
Date:

AIM:
To write C Design a calculator to perform the operations, namely, addition, subtraction,
Multiplication, division and square of a number.

ALGORITHM:
Step-1: Start
Step-2: Read the inputs from user.
Step-3: Initialize i as 0 and list.
Step-4: Perform the operations, namely, addition, subtraction, multiplication, division and square of a
given number.
Step-5: Print the value stored in sum, difference, product, quotient, square.
Step-6: Stop.

PROGRAM:

#include<stdio.h>
#include <conio.h>
int main()
{
int firstNumber, secondNumber, sum, difference, product, quotient;
long square;
printf("Enter First Number: ");
scanf("%d", &firstNumber);
printf("Enter Second Number: ");
scanf("%d", &secondNumber);
sum = firstNumber + secondNumber;
printf("\nSum = %d", sum);
difference = firstNumber - secondNumber;printf("\nDifference = %d", difference);
product = firstNumber * secondNumber;printf("\nMultiplication = %d", product);
quotient = firstNumber / secondNumber;printf("\nDivision = %.3f", quotient);
square = firstNumber *firstNumber;printf("\n Square= %ld", square);
getch();
}
return 0;

3
SAMPLE OUTPUT:
Enter First Number: 25
Enter Second Number: 4
Sum = 29
Difference = 21
Multiplication = 100
Division = 6.250
Square = 625

RESULT:

Thus the C Program for Arithmetic operations has been executed and the output was obtained.

4
Ex. No: 3
Date: GENERATION OF PRIMENUMBERS AND CHECK ARMSTRING OR NOT

AIM:
To write C Program to generate prime numbers and check the given numbers are Armstrong or not

ALGORITHM:

STEP 1:Start the program.

STEP 2: Declare all required variables and initialize the result variable “sum” to 0.

STEP 3: Get an input from the user and store it in “n” and “n_copy” variables.

STEP 4: Using the user input, perform the following operation until it becomes
ZEROr = n %10;
Sum = sum + (r*r*r);
n = n/10;
STEP 5: compare the value of “sum” and n_copy”. If they are equal then go to step no 6
Otherwise go to step no 7.
STEP 6: print the result as “It is an Armstrong Number” and go to step 8.

STEP 7: print the result as “It is not an Armstrong Number”.

STEP 8: Stop the program.

PROGRAM:

#include <stdio.h>
#include <math.h>
// Function to check if a number is prime
int is Prime(int num)
{
if (num <= 1) return 0; // 0 and 1 are not prime
for (int i = 2; i <= sqrt(num); i++) {
if (num % i == 0) return 0; // Found a divisor, not prime
}
return 1; // It's a prime number
}
// Function to check if a number is an Armstrong number
int is Armstrong(int num) {
int originalNum = num, sum = 0, digits = 0;

// Count the number of digits


while (originalNum != 0) {
originalNum /= 10;
digits++;
}
originalNum = num; // Reset originalNum to calculate sum
// Calculate the sum of digits raised to the power of digits
while (originalNum != 0) {
int digit = originalNum % 10;

5
sum += pow(digit, digits);
originalNum /= 10;
}
return sum == num; // Check if it's an Armstrong number
}
int main() {
int lower, upper;

// Get the range for generating prime numbers


printf("Enter the lower and upper range to generate prime numbers: ");
scanf("%d %d", &lower, &upper);

printf("Prime numbers between %d and %d are:\n", lower, upper);


for (int num = lower; num <= upper; num++) {
if (isPrime(num)) {
printf("%d ", num);
}
}
printf("\n");

// Check if a given number is Armstrong


int checkNum;
printf("Enter a number to check if it is an Armstrong number: ");
scanf("%d", &checkNum);

if (isArmstrong(checkNum))
{
printf("%d is an Armstrong number.\n", checkNum);
} else {
printf("%d is not an Armstrong number.\n", checkNum);
}

return 0;
}
SAMPLE OUTPUT:

Enter the lower and upper range to generate prime numbers: 10 50


Prime numbers between 10 and 50 are:
11 13 17 19 23 29 31 37 41 43 47
Enter a number to check if it is an Armstrong number: 153
153 is an Armstrong number.

RESULT:

Thus the C Program to generate prime numbers and check the given numbers are Armstrong or not.

6
Ex. No: 4
Date: Greatest number using Array(one- dimensional)

AIM:
To write C Program to generate greatest number using one-dimensional Array.

ALGORITHM:

STEP 1: Start the program.


STEP 2: Initialize a variable to hold the maximum value, starting with the first element of the array.
STEP 3: Loop through each element of the array.
STEP 4: For each element, check if it is greater than the current maximum value.
STEP 5: If it is, update the maximum value.
STEP 6: After the loop, the maximum value variable will hold the greatest number in the array.
STEP 7: Stop the program.

PROGRAM:

#include <stdio.h>
int find_greatest(int arr[], int size)
{
if (size == 0)
{
return -1; // Indicate an empty array (or handle as needed)
}
int max_value = arr[0]; // Start with the first element
for (int i = 1; i < size; i++)
{
if (arr[i] > max_value)
{
max_value = arr[i];
}
}
return max_value;
}
int main()
{
int array[] = {3, 1, 4, 1, 5, 9, 2, 6};
int size = sizeof(array) / sizeof(array[0]);
int greatest_number = find_greatest(array, size);
if (greatest_number != -1)
{
printf("The greatest number is: %d\n", greatest_number);
}
else
{
printf("The array is empty.\n");
7
}

return 0;
}

SAMPLE OUTPUT:

The greatest number is: 9

RESULT:

Thus the C Program to generate greatest numbers using one-dimensional array was successfully executed.

8
Ex. No: 5
Matrix Multiplication using array (Two-Dimensional)
Date:

AIM:
To write a C Program to calculate matrix multiplication using two dimensional array.
ALGORITHM:

Step 1: Read the dimensions of the first matrix


Step 2: Create a result matrix C with dimensions and Initialize all elements C to zero.
Step 3: Loop through each row of matrix A and matrix B
Step4: Calculate the sum of the products of the corresponding elements from row i of A and column j of B
Step-6: Print the result.

PROGRAM:
#include <stdio.h>
#define MAX 10
void multiplyMatrices(int first[MAX][MAX], int second[MAX][MAX], int result[MAX][MAX], int row1,
int col1, int row2, int col2)
{
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col2; j++)
{
result[i][j] = 0;
}
}
for (int i = 0; i < row1; i++) {
for (int j = 0; j < col2; j++) {
for (int k = 0; k < col1; k++) {
result[i][j] += first[i][k] * second[k][j];
}
}
}
}

int main() {
int first[MAX][MAX], second[MAX][MAX], result[MAX][MAX];
int row1, col1, row2, col2;
printf("Enter rows and columns for first matrix: ");
scanf("%d %d", &row1, &col1);
printf("Enter elements of first matrix:\n");
for (int i = 0; i < row1; i++) {
for (int j = 0; j < col1; j++) {
scanf("%d", &first[i][j]);
}
}

9
printf("Enter rows and columns for second matrix: ");
scanf("%d %d", &row2, &col2);
if (col1 != row2) {
printf("Matrix multiplication not possible. Columns of first matrix must equal rows of second matrix.\n");
return 1;
}
// Input second matrix elements
printf("Enter elements of second matrix:\n");
for (int i = 0; i < row2; i++) {
for (int j = 0; j < col2; j++) {
scanf("%d", &second[i][j]);
}
}
// Multiply the matrices
multiplyMatrices(first, second, result, row1, col1, row2, col2);
// Display the result
printf("Resultant matrix:\n");
for (int i = 0; i < row1; i++) {
for (int j = 0; j < col2; j++) {
printf("%d ", result[i][j]);
}
printf("\n");
}
return 0;
}
SAMPLE OUTPUT:
Enter rows and columns for first matrix: 2 3
Enter elements of first matrix:
123
456
Enter rows and columns for second matrix: 3 2
Enter elements of second matrix:
7 8
9 10
11 12

Resultant matrix:
1863 36
4650 99

RESULT:

Thus the C Program for calculating matrix multiplication was successfully executed.

10
Ex. No: 6
AVERAGE HEIGHT OF PERSONS
Date:

AIM:
To write a C Program to populate an array with height of persons and find how many persons are
above the average height.
ALGORITHM:
Step-1: Start
Step-2: Declare variables
Step-3: Read the total number of persons and their height.
Step-4: Calculate avg=sum/n and find number of persons their h>avg.
Step-5: Display the output of the calculations.
Step-6: Stop.

PROGRAM:

/* Get a Height of Different Persons and find how many of them are are above average */

#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,sum=0,count=0,height[100];float avg;
clrscr();
//Read Number of persons
printf("Enter the Number of Persons : ");
scanf("%d",&n);
//Read the height of n persons
printf("\nEnter the Height of each person in centimeter\n");
for(i=0;i<n;i++)
{
scanf("%d",&height[i]);
sum = sum + height[i];
}
avg = (float)sum/n;
//Counting
for(i=0;i<n;i++)
if(height[i]>avg)
{
count++;
}
printf("\nAverage Height of %d persons is : %.2f\n",n,avg);
printf("\nThe number of persons above average : %d ",count);
getch();
}

11
SAMPLE OUTPUT:
Enter the Number of Persons: 5
Enter the Height of each person in centimeter
150
155
162
158
154
Average Height of 5 persons is: 155.8
The number of persons above average: 2

RESULT:

Thus the C Program average height of persons has been executed and the output was obtained.

12
Ex. No: 7
BODY MASS INDEX OF THE INDIVIDUALS
Date:

AIM:
To write a C Program to Populate a two dimensional array with height and weight of persons
and compute the Body Mass Index of the individuals
ALGORITHM:
Step-1: Start
Step-2: Declare variables
Step-3: Read the number of persons and their height and weight.
Step-4: Calculate BMI=W/H2 for each person
Step-5: Display the output of the BMI for each person
Step-6: Stop.

PROGRAM:

#include <stdio.h>
#define MAX_PERSONS 100
void computeBMI(float persons[MAX_PERSONS][2], float bmi[], int count)
{
for (int i = 0; i < count; i++) {
float height = persons[i][0]; // height in meters
float weight = persons[i][1]; // weight in kilograms
if (height > 0) {
bmi[i] = weight / (height * height); // BMI calculation
} else
{
bmi[i] = -1; // Invalid height
}
}
}

int main() {
int count;
float persons[MAX_PERSONS][2]; // 2D array for height and weight
float bmi[MAX_PERSONS]; // Array to store BMI values

printf("Enter the number of persons (max %d): ", MAX_PERSONS);


scanf("%d", &count);

if (count > MAX_PERSONS) {


printf("Error: Number of persons exceeds the maximum limit.\n");
return 1;
}

// Input heights and weights


13
for (int i = 0; i < count; i++) {
printf("Enter height (in meters) and weight (in kilograms) for person %d: ", i + 1);
scanf("%f %f", &persons[i][0], &persons[i][1]);
}

// Compute BMI
computeBMI(persons, bmi, count);

// Output results
printf("\nBMI Results:\n");
for (int i = 0; i < count; i++) {
if (bmi[i] >= 0) {
printf("Person %d: Height = %.2f m, Weight = %.2f kg, BMI = %.2f\n", i + 1, persons[i][0],
persons[i][1], bmi[i]);
} else {
printf("Person %d: Invalid height!\n", i + 1);
}
}

return 0;
}

SAMPLE OUTPUT:
Enter the number of persons (max 100): 2
Enter height (in meters) and weight (in kilograms) for person 1: 1.28 88
Enter height (in meters) and weight (in kilograms) for person 2: 2.2 58

BMI Results:
Person 1: Height = 1.28 m, Weight = 88.00 kg, BMI = 53.71
Person 2: Height = 2.20 m, Weight = 58.00 kg, BMI = 11.98

RESULT:
Thus The C program body mass index of the individuals has been executed and the output was obtained

14
Ex. No: 8
REVERSE OF A GIVEN STRING
Date:

AIM:
To write a C Program to perform reverses without changing the position of special characters for
the given string.
ALGORITHM:
Step-1: Start
Step-2: Declare variables.
Step-3: Read a String.
Step-4: Check each character of string for alphabets or a special character by using Alpha().
Step-5: Change the position of a character vice versa if it is alphabet otherwise
remains same.
Step-6: Repeat step 4 until reach to the mid of the position of a string.
Step-7: Display the output of the reverse string without changing the position of
special characters.
Step-8: Stop

PROGRAM:

#include<stdio.h>
#include<string.h>
#include <ctype.h>
void swap(char *a, char *b)
{
char temp = *a;
*a = *b;
*b = temp;
}
void reverse(char *str)
{
char *p1 = str;
char *p2 = str + strlen(str) - 1;
while (p1 < p2) {
while (!isalpha(*p1))
p1++;
while (!isalpha(*p2))
p2--;
if (p1 < p2)
{
swap(p1, p2);
15
p1++;
p2--;
}
}
}
int main(void)
{
char str[6];
strcpy(str,"a,b$c");
reverse(str);
printf("%s\n", str);
return 0;
}
SAMPLE OUTPUT:

c,b$a

RESULT:
Thus the C Program for reverse of a given String has been executed and the output was obtained.

16
Ex. No: 9
STRING OPERATIONS USING BUILT-IN FUNCTIONS
Date:

AIM:

To write a C Program to perform string operations on a given paragraph for the following using
built-in functions:

a. Find the total number of words.

b. Capitalize the first word of each sentence.

c. Replace a given word with another word.

ALGORITHM:
Step 1: Start the program.

Step 2: Declare variables

Step 3: Read the text.


Step 4: Display the menu options
Step 5: Compare each character with tab char „\t‟ or space char „ „ to count no of words

Step 6: Find the first word of each sentence to capitalize by checks to see if a character is punctuation
mark used to denote the end of a sentence. (! . ?)
Step 7: Replace the word in the text by user specific word if match
Step 8: Display the output of the calculations.
Step 9: Repeat the step 4 till choose the option stop.
Step 10: Stop
PROGRAM

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_LENGTH 1000
int countWords(const char *str) {
int count = 0;
int inWord = 0;
while (*str)
{
if (isspace(*str))
{
inWord = 0;
17
}
else if (inWord == 0)
{
inWord = 1;
count++;
}
str++;
}
return count;
}
void capitalizeSentences(char *str)
{
int capitalize = 1;
for (int i = 0; str[i] != '\0'; i++)
{
if (capitalize && isalpha(str[i]))
{
str[i] = toupper(str[i]);
capitalize = 0;
}
if (str[i] == '.' || str[i] == '!' || str[i] == '?')
{
capitalize = 1;
}
}
}
void replaceWord(char *str, const char *oldWord, const char *newWord)
{
char buffer[MAX_LENGTH];
char *pos, *start = str;
int oldLen = strlen(oldWord);
int newLen = strlen(newWord);
int bufferIndex = 0;
while ((pos = strstr(start, oldWord)) != NULL)
{
strncpy(buffer + bufferIndex, start, pos - start);
bufferIndex += pos - start;
strcpy(buffer + bufferIndex, newWord);
bufferIndex += newLen;
start = pos + oldLen;
}
strcpy(buffer + bufferIndex, start);
strcpy(str, buffer);
18
int main()
{
char paragraph[MAX_LENGTH];
char oldWord[50], newWord[50];
printf("Enter a paragraph:\n");
fgets(paragraph, sizeof(paragraph), stdin);
paragraph[strcspn(paragraph, "\n")] = '\0';
int wordCount = countWords(paragraph);
printf("Total number of words: %d\n", wordCount);
capitalizeSentences(paragraph);
printf("Paragraph after capitalizing sentences:\n%s\n", paragraph);
printf("Enter the word to replace: ");
scanf("%s", oldWord);
printf("Enter the new word: ");
scanf("%s", newWord);
replaceWord(paragraph, oldWord, newWord);
printf("Paragraph after replacing words:\n%s\n", paragraph);
return 0;
}
SAMPLE OUTPUT:

Enter a paragraph:
Function to count the number of words in a string.flag to indicate if we are inside a word.we
are outside a word.
Total number of words: 22
Paragraph after capitalizing sentences:
Function to count the number of words in a string. Flag to indicate if we are inside a word.We are
outside a word.
Enter the word to replace: to
Enter the new word: hello
Paragraph after replacing words:
Function hello count the number of words in a string. Flag hello indicate if we are inside a word.We
are outside a word.

RESULT:
Thus a C Program String operation has been executed and the output was obtained

19
Ex. No: 10
SORTING USING PASS BY REFERENCE
Date:

AIM:

To write a C Program to Sort the list of numbers using pass by reference


ALGORITHM:
Step 1: Start the program.
Step 2: Declare variables and create an array
Step 3: Read the Input for number of elements and each element.
Step 4: Develop a function to sort the array by passing reference.
Step 5: Compare the elements in each pass till all the elements are sorted.
Step 6: Display the output of the sorted elements.
Step 7: Stop the program.
PROGRAM:

#include<stdio.h>
int main()
{
int n,a[100],i;
void sortarray(int*,int);
printf("\nEnter the Number of Elements in an array : ");
scanf("%d",&n);
printf("\nEnter theArray elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sortarray(a,n);
printf("\nAfter Sorting ... \n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}
void sortarray(int* arr,int num)
{
int i,j,temp;
for(i=0;i<num;i++)
for(j=i+1;j<num;
j++)

20
if(arr[i] > arr[j])
{
temp=arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}

SAMPLE OUTPUT:
Enter the Number of Elements in an array : 5
Enterthe Array elements
33
67
21
45
11

After Sorting....
11
21
33
45
67

RESULT:
Thus the C Program Sorting using pass by reference has been executed and the output was obtained.

21
Ex. No: 11(a)
Date: PROGRAMS WITH USER DEFINED FUNCTIONS AND RECURSIVE
FUNCTIONS.

AIM:

To write a C Program with User Defined Functions and Recursive Functions.

a. Factorial of a number using recursion

ALGORITHM:

Step 1: Start
Step 2: Read number n
Step 3: Call factorial (n)
Step 4: If n>=1 then
return n*multiply Numbers(n-1);
Step 5: Else
return 1;
Step 6: Print factorial
Step 7: stop

PROGRAM:
#include<stdio.h>
long int multiplyNumbers(int n);
int main() {
int n;
printf("Enter a positive integer: ");

scanf("%d",&n);
printf("Factorial of %d = %ld", n, multiplyNumbers(n));
return 0;
}
long int multiplyNumbers(int n)
{if (n>=1)
return n*multiplyNumbers(n-1);
else
return 1;
}

22
SAMPLE OUTPUT:

Enter a positive integer: 4


Factorial of 4 = 24

RESULT:

Thus the C Program with User Defined Functions and Recursive Functions for the Factorial of a
number using recursion has been executed and the output was obtained.

23
Ex. No:11 (b)
Date: FIBONACCI OF A NUMBER USING RECURSION

AIM:

To write a C Program with User Defined Functions and Recursive Functions.

Fibonacci of a number using recursion

ALGORITHM:

Step 1: Start
Step 2: Take an integer as an input, and will return the element at that position.
Step 3: we will have an if-else-if ladder.
Step 4: If the input will be 0 i.e., the element at the 0th position, we will return 0.
Step 5: If the input will be 1 i.e., the element at 1st position, we will return 1.
Step 6: Else, we will recursively call the fibonacci().
Step 7: stop.

PROGRAM:
#include <stdio.h>
int fibonacci(int num)
{
if (num == 0) {
return 0;
} else if (num == 1) {
return 1;
} else {
return fibonacci(num - 1) + fibonacci(num - 2);
}
}
int main()
{
int num;
printf("Enter the number of elements to be in the series: ");
scanf("%d", &num);
for (int i = 0; i < num; i++)
{
printf("%d", fibonacci(i));
if (i < num - 1)
{
printf(", ");
}
}
printf("\n");
return 0;
}

24
SAMPLE OUTPUT:

Enter the number of elements to be in the series:8


Fibonacci:0, 1, 1, 2, 3, 5, 8, 13

RESULT:

Thus the C Program with User Defined Functions for Fibonacci of a number using recursion has been
executed and the output was obtained

25
Ex. No: 12
Generate salary slip of employees using structures and pointers
Date:

AIM:
To write a C Program to generate salary slip of employees usingstructures and pointers.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Create a structure named Employee that contains id, name, basic salary, allowances, and
deduction.
STEP 3: Compute the total salary using the formula:
Total Salary=Basic Salary+Allowances−Deductions

STEP 4: Return the computed total salary


STEP 5: Read the user the employee's ID, name, basic salary, allowances and deduction.
STEP 6:Call printSalarySlip with a pointer to emp to display the salary slip.
STEP 7: Stop the program.
PROGRAM:
#include <stdio.h>
struct Employee {
int id;
char name[50];
float basicSalary;
float allowances;
float deductions;
};

float calculateSalary(struct Employee *emp) {


return emp->basicSalary + emp->allowances - emp->deductions;
}
void printSalarySlip(struct Employee *emp) {
printf("\nSalary Slip for Employee ID: %d\n", emp->id);
printf("Name: %s\n", emp->name);
printf("Basic Salary: %.2f\n", emp->basicSalary);
printf("Allowances: %.2f\n", emp->allowances);
printf("Deductions: %.2f\n", emp->deductions);
printf("Total Salary: %.2f\n", calculateSalary(emp));
}

int main() {
struct Employee emp;
printf("Enter Employee ID: ");
scanf("%d", &emp.id);
printf("Enter Employee Name: ");
getchar(); // to consume newline left by previous input
fgets(emp.name, sizeof(emp.name), stdin);
printf("Enter Basic Salary: ");
scanf("%f", &emp.basicSalary);
26
printf("Enter Allowances: ");
scanf("%f", &emp.allowances);
printf("Enter Deductions: ");
scanf("%f", &emp.deductions);
printSalarySlip(&emp);
return 0;
}

SAMPLE OUTPUT:
Enter Employee ID: 61
Enter Employee Name: sandhiya
Enter Basic Salary: 60000
Enter Allowances: 5000
Enter Deductions: 3000

Salary Slip for Employee ID: 61


Name: sandhiya

Basic Salary: 60000.00


Allowances: 5000.00
Deductions: 3000.00
Total Salary: 62000.00

RESULT:

Thus the C Program to generate salary slip of employees usingstructures and pointers was
successfully created and the output was obtained.

27
Ex. No: 13
INTERNAL MARKS OF STUDENTS
Date:

AIM:
To write a C Program to compute internal marks of students for five different subjects using
structures and functions.

ALGORITHM:
Step 1: Start
Step 2: Declare variables
Step 3: Read the number of students.
Step 4: Read the student mark details
Step 5: Calculate internal mark by i=total of three test marks / 3 for each subject per student.
Step 6: Display the output of the calculations for all the students.
Step 7: Stop
PROGRAM:

#include<stdio.h>
#include<conio.h>
struct stud
{
char name[20];
long int rollno;
int marks[5,3];
int i[5];
}students[10];

void calcinternal(int);
int main()
{
int a,b,j,n;
clrscr();
printf("How many students : \n");
scanf("%d",&n);
for(a=0;a<n;++a)
{
clrscr();
printf("\n\nEnter the details of %d student : ", a+1);
printf("\n\nEnter student %d Name : ", a);
scanf("%s", students[a].name);
printf("\n\nEnter student %d Roll Number : ", a);
scanf("%ld", &students[a].rollno);
total=0;
for(b=0;b<=4;++b)
{
for(j=0;j<=2;++j)
{
28
printf("\n\nEnter the test %d mark of subject-%d : ",j+1, b+1); scanf("%d", &students[a].marks[b,j]);
}
}
}
calcinternal(n);
for(a=0;a<n;++a)
{
clrscr();
printf("\n\n\t\t\t\tMark Sheet\n");
printf("\nName of Student : %s", students[a].name);
printf("\t\t\t\t Roll No : %ld", students[a].rollno);
printf("\n ");
for(b=0;b<5;b++)
{
printf("\n\n\t Subject %d internal \t\t :\t %d", b+1, students[a].i[b]);
}
printf("\n\n \n");
getch();
}
return(0);
}
void calcinternal(int n)
{
int a,b,j,total;
for(a=1;a<=n;++a)
{
for(b=0;b<5;b++)
{
total=0;
for(j=0;j<=2;++j)
{
total += students[a].marks[b,j];
}
students[a].i[b]=total/3;
}
}
}

29
SAMPLE OUTPUT:

How many students: 1


Enter the details of 1 student:
Enter student 1 Name: H.Xerio
Enter student 1 Roll Number: 536435

Enter the test 1mark of subject-1: 46 Enter the


test 2 mark of subject-1: 56 Enter the test 3 mark
of subject-1: 76

Enter the test 1 mark of subject-2: 85 Enter the


test 2 mark of subject-2: 75 Enter the test 3 mark
of subject-2: 75

Enter the test 1 mark of subject-3: 66 Enter the


test 2 mark of subject-3: 86 Enter the test 3 mark
of subject-3: 70

Enter the test 1 mark of subject-4: 25 Enter the


test 2mark of subject-4: 35 Enter the test 3mark
of subject-4: 61

Enter the test 1 mark of subject-5: 45 Enter the


test 2 mark of subject-5: 75 Enter the test 3 mark
of subject-5: 60

Mark Sheet
Name of Student: H.Xerio Roll No: 536435

Subject 1 internal : 59
Subject 2 internal : 78
Subject 3 internal : 74
Subject 4 internal : 40
ubject 5 internal : 60

RESULT:
Thus the C Program for Internal marks of students has been executed and the output was obtained

30

You might also like