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

c_practicale

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

c_practicale

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

PROGRAMMING WITH C

PRACTICAL MANUAL

Submitted By

[MEEL PRAMILA]

ENROLLMENT NO. – [24GMCA22 ]

1ST SEMESTER

SUBJECT CODE – MC01094011


Of

MASTER OF COMPUTER APPLICATIONS

GOVERNMENT MCA COLLEGE MANINAGAR (EAST),


AHMEDABAD GUJARAT

[Academic Year: 2024-25]


CERTIFICATE

This is to certify that __________________________________________ (ENROLLMENT NO. –


_________________), Student of MCA 1ST Semester, Government MCA College has successfully
completed his/her practical work of subject Programming with C (MC01094011) for academic
year 2024-25.

DATE OF SUBMISSION:

Prof Nisha K. Chavda Prof Bhavesh B. Prajapati Dr. Chetan B. Bhatt


Lecturer, HOD, Principal,
Government MCA College, Government MCA College, Government MCA College,
Maninagar, Ahmedabad Maninagar, Ahmedabad Maninagar, Ahmedabad
VISION OF THE INSTITUTE
➢ Provide value-based quality education for computer science applications which enable
students to solve real-life problems of society.

MISSION OF THE INSTITUTE


➢ To equip our students with good knowledge, skills and attitude to solve real – life problems
in the domain of computer applications.
➢ To establish industry-academia interaction to facilitate the students to work proficiently in
the industrial environment.
➢ To imbibe high moral values and professional ethics.
➢ To provide conducive environment so as to achieve excellence in teaching-learning, and
research and development activities.

PROGRAM EDUCATIONAL OBJECTIVES


➢ Identify and analyze real life problems and design computing systems appropriate to its
solutions that are technically sound, economically feasible and socially acceptable
➢ Exhibit professionalism, ethical attitude, good communication skills, team work in their
profession
➢ Adapt to current trends by engaging in life-long learning
PROGRAM OUTCOMES (POs)
 PO1 (Foundation Knowledge): Apply knowledge of mathematics, programming logic and
coding fundamentals for solution architecture and problem solving.
 PO2 (Problem Analysis): Identify, review, formulate and analyze problems for primarily
focusing on customer requirements using critical thinking frameworks.
 PO3 (Development of Solutions): Design, develop and investigate problems with as an
innovative approach for solutions incorporating ESG/SDG goals.
 PO4 (Modern Tool Usage): Select, adapt and apply modern computational tools such as
development of algorithms with an understanding of the limitations including human biases.
 PO5 (Individual and Teamwork): Function and communicate effectively as an individual or
a team leader in diverse and multidisciplinary groups. Use methodologies such as agile.
 PO6 (Project Management and Finance): Use the principles of project management
such as scheduling, work breakdown structure and be conversant with the principles of Finance
for profitable project management.
 PO7 (Ethics): Commit to professional ethics in managing software projects with financial
aspects. Learn to use new technologies for cyber security and insulate customers from malware
 PO8 (Life-long learning): Change management skills and the ability to learn, keep up
with contemporary technologies and ways of working.
PROGRAM SPECIFIC OUTCOMES (PSOs)
After completing the program students will be able to

➢ Meet the needs of users within an organizational and societal context through the
selection, creation, application, integration, and administration of computing
technologies.
➢ Apply concepts, probability, statistics, mathematics, through calculus (differential and
integral), numerical methods and sciences including applications appropriate in the field
of computing problems.
➢ Use algorithms, data structures, database management, software design, concepts of
programming languages and computer organization and architecture in the field of
computer applications.
COURSE OUTCOMES (COs)

1. Formulate algorithm/ flowchart for given arithmetic and logical problem.


2. Translate algorithm/flowchart into C program using correct syntax of Operator, conditional & branching statem
3. Write C programs using the concepts of array and functions.
4. Write C programs using the concepts of pointers, structure and union.
5. Develop an application using the concepts file management to solve problems.
INDEX
Sr Page
Title Date Sign
No No
1. Write a program to that performs as calculator
(addition, multiplication, division, subtraction).
2. Write a program to find area of triangle(a=h*b*.5)
a = area h = height b = base.
3. Write a program to calculate simple interest (i =
(p*r*n)/100 )
1
i = Simple interest p = Principal amount r = Rate
of interest n = Number of years.
4. Write a C program to interchange two numbers.
5. Write a C program to enter a distance in to kilometre
and convert it in to meter, feet, inches and centimetre.

10

11

12
1.write a program to that perform as calculator (addition,
multiplication,divison,subtraction)

Code:
//write a program to that perform as calculator(addition,multiplication

,divison,subtraction)

#include <stdio.h>

int main()

int n1,n2,addition,sub,multy,divison;

printf("enter two number\n");

scanf("%d%d", &n1 , &n2);

addition=n1 + n2;

sub = n1 - n2;

multy = n1*n2;

divison = n1 / n2;

printf("addtion= %d\n",addition);

printf("subtraction= %d\n",sub);

printf("multiplication= %d\n",multy);

printf("divison= %d\n",divison);

return 0;

}
Output:

Flowchart:
2. write a program to find area of triangle (a=h*b*.5)
Code:
//write a program to find area of triangle (a=h*b*.5)

#include <stdio.h>

int main ()

float b1, h1 , a1 ;

printf("enter the base of triangle:");

scanf("%f", &b1);

printf("enter the height of the triangle:");

scanf("%f" , &h1);

a1 =0.5*b1*h1;

printf("the area of the triangle is: %.2f\n", a1);

return 0;

}
output:

Flowchart:
3. write a program to calculate simple intrest(i=(p*r*n)/100)
Code:
//write a program to calculate simple intrest(i=(p*r*n)/100)

#include <stdio.h>

int main()

float p1, rate, time, i;

printf("Enter the principal amount: ");

scanf("%f", &p1);

printf("Enter the rate of interest: ");

scanf("%f", &rate);

printf("Enter the time (in years): ");

scanf("%f", &time);

i = (p1 * rate * time) / 100;

printf("The Simple Interest is: %.2f\n", i);

return 0;

}
Output:

Flowchat:
4. write a program to interchange two numbers
Code:
//write a program to interchange two numbers

#include <stdio.h>

int main();

int n1,n2,temp;

printf("enter the frist number:");

scanf("%d", &n1);

printf("enter the second number:");

scanf("%d", &n2);

temp=n1;

n1=n2;

n2=temp;

printf("after swapping:\n");

printf("frist number:%d\n", n1);

printf("second number:%d\n", n2);

return 0;

}
Output:

flowchart:
5. write a c program to enter a distance in ti kilometer and
convert in to meter ,feet,inches and centimeter
Code:
//write a c program to enter a distance in ti kilometer and convert in to meter
,feet,inches and centimeter

#include <stdio.h>

int main()

float km, meters, feet, inches, cm;

printf("Enter the distance in km: ");

scanf("%f", &km);

meters = km * 1000;

cm = meters * 100;

inches = meters * 399.3;

feet = meters * 3.2;

printf("Distance in meters: %.2f m\n", meters);

printf("Distance in centimeters: %.2f cm\n", cm);

printf("Distance in feet: %.2f ft\n", feet);

printf("Distance in inches: %.2f in\n", inches);

return 0;

}
Output:

Flowchart:
6. //write a program to compute fahrenheit from
centigrade (f=1.8*c+32)
Code:
//write a program to compute fahrenheit from centigrade (f=1.8*c+32)

#include <stdio.h>

int main()

float n1, f1;

printf("Enter the temperature in Celsius: ");

scanf("%f", &n1);

f1 = 1.8 * n1 + 32;

printf("Temperature in Fahrenheit: %.2f\n", f1);

return 0;

Output:
Flowchart:
7.Write a C program to find that the accepted number is
Negative, Positive or Zero
Code:
//Write a C program to find that the accepted number is Negative, Positive or Zero

#include <stdio.h>

int main()

int n1;

printf("Enter a number: ");

scanf("%d", &n1);

if (n1 > 0)

printf("The number is Positive.\n");

} else if (n1 < 0)

printf("The number is Negative.\n");

} else

printf("The number is Zero.\n");

return 0;

}
Output:
Flowchart:
8. Write a program to read marks of a student from
keyboard whether the student is pass or fail(using if else)
Code:
/*Write a program to read marks of a student from keyboard whether the student is
pass or fail(using if else)*/

#include <stdio.h>

int main()

int marks;

printf("Enter the marks of student: ");

scanf("%d", &marks);

if (marks >= 50)

printf("The student has Passed\n");

else

printf("The student has Failed0\n");

return 0;

}
Output:

Flowchart:
9. Write a program to read three numbers from keyboard
and find out maximum out of these three.(nested if else)
Code:
/*Write a program to read three numbers from keyboard and find out maximum out of
these three.(nested if else)*/

#include <stdio.h>

int main()

int n1, n2, n3;

printf("Enter first number: ");

scanf("%d", &n1);

printf("Enter second number: ");

scanf("%d", &n2);

printf("Enter third number: ");

scanf("%d", &n3);

if (n1 >= n2)

if (n1 >= n3)

printf("maximum number is: %d\n", n1);

}
else

printf("maximum number is: %d\n", n3);

else

if (n2 >= n3)

printf("maximum number is: %d\n", n2);

else

printf("maximum number is: %d\n", n3);

return 0;

}
Output:

Flowchart:
10. Write a C program to check whether the entered
character is capital, small letter, digit or any special
character
Code:
/*Write a C program to check whether the entered character is capital, small letter,
digit or any special character*/

#include <stdio.h>

int main()

char ch;

printf("Enter a character: ");

scanf("%d", &ch);

if (ch >= 'A' && ch <= 'Z')

printf("The character is a Capital Letter.\n");

else if (ch >= 'a' && ch <= 'z')

printf("The character is a Small Letter.\n");

else if (ch >= '0' && ch <= '9')

printf("The character is a Digit.\n");


}

else

printf("The character is a Special Character.\n");

return 0;

Output:
Flowchart:
11. Write a program to read marks from keyboard and your
program should display equivalent grade according to
following table(if else ladder).

Code:
/*Write a program to read marks from keyboard and your program should display
equivalent grade according to following table(if else ladder)*/

#include <stdio.h>

int main()

int marks;

printf("Enter your marks: ");

scanf("%d", &marks);

if (marks >= 80 && marks <= 100)

printf("Grade: Distinction\n");

else if (marks >= 60 && marks <= 79)

printf("Grade: First Class\n");

else if (marks >= 40 && marks <= 59)

{
printf("Grade: Second Class\n");

else if (marks < 40 && marks >= 0)

printf("Grade: Fail\n");

else

printf("Invalid marks entered.\n");

return 0;

}
12. Write a c program to prepare pay slip using following
data.Da = 10% of basic, Hra = 7.50% of basic, Ma = 300, Pf =
12.50% of basic, Gross = basic + Da + Hra + Ma, Nt = Gross –
Pf.*/
Code:
/*Write a c program to prepare pay slip using following data.Da = 10% of basic, Hra =
7.50% of basic, Ma = 300, Pf = 12.50% of basic, Gross = basic + Da + Hra + Ma, Nt = Gross
– Pf.*/

#include <stdio.h>

int main()

float basic, da, hra, ma = 300, pf, gross, net;

printf("Enter the basic salary: ");

scanf("%f", &basic);

da = 0.10* basic;

hra = 0.075 * basic;

pf = 0.125 * basic;

gross = basic + da + hra + ma;

net = gross - pf;

printf("\n---- Pay Slip ----\n");

printf("Basic Salary: %.2f\n", basic);

printf("DA (10%%) : %.2f\n", da);


printf("HRA (7.5%%) : %.2f\n", hra);

printf("MA : %.2f\n", ma);

printf("PF (12.5%%) : %.2f\n", pf);

printf("Gross Salary: %.2f\n", gross);

printf("Net Salary : %.2f\n", net);

return 0;

Output:
13. Write a C program to read no 1 to 7 and print relatively
day Sunday to Saturday.
Code:
//Write a C program to read no 1 to 7 and print relatively day Sunday to Saturday.

#include <stdio.h>

int main()

int day;

printf("Enter a number: ");

scanf("%d", &day);

switch (day)

case 1:

printf("Sunday");

break;

case 2:

printf("Monday");

break;

case 3:

printf("Tuesday");

break;

case 4:

printf("Wednesday");
break;

case 5:

printf("Thursday");

break;

case 6:

printf("Friday");

break;

case 7:

printf("Saturday");

break;

default:

printf("Invalid input! Please enter a number between 1 and 7.");

return 0;

Output:
14. Write a C program to find out the Maximum and
Minimum number from given 10 numbers
Code:
//Write a C program to find out the Maximum and Minimum number from given 10
numbers

#include <stdio.h>

int main()

int n1[10], i, max, min;

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

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

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

max = min = n1[0];

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

if (n1[i] > max)

max = n1[i];

if (n1[i] < min)

{
min = n1[i];

printf("Maximum number: %d\n", max);

printf("Minimum number: %d\n", min);

return 0;

Output:
15. Write a C program to find factorial of a given number.
Code:
//Write a C program to find factorial of a given number.

#include <stdio.h>

int main()

int n, i;

long fact = 1;

printf("Enter a positive integer: ");

scanf("%d", &n);

if (n < 0)

printf("Factorial is not defined for negative numbers.\n");

else

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

fact *= i;

printf("Factorial of %d = %llu\n", n, fact);

}
return 0;

Output:
16. Write a program to reverse a number.
code:
//Write a program to reverse a number.

#include <stdio.h>

int main()

int n1, n2, n3;

printf("Enter a number: ");

scanf("%d", &n1);

while (n1 != 0)

n3 = n1 % 10;

n2 = n2 * 10 + n3;

n1 /= 10;

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

return 0;

}
Output:
17. Write a program to generate first n number of Fibonacci
series
Code:
//Write a program to generate first n number of Fibonacci series

#include <stdio.h>

int main()

int n, i;

int first, second, next;

printf("Enter number");

scanf("%d", &n);

if (n <= 0)

printf("enter positive number.\n");

else if (n == 1)

printf("Fibonacci series: %d\n", first);

else

printf("Fibonacci series: %d, %d", first, second);

for (i = 3; i <= n; i++)


{

next = first + second;

printf(", %d", next);

first = second;

second = next;

printf("\n");

return 0;

Output:
18. Write a program to calculate average and total of 5
students for 3 subjects (use nested for loops)*/
Code:
/*Write a program to calculate average and total of 5 students for 3 subjects (use nested
for loops)*/

#include <stdio.h>

int main()

int i, j;

float marks, total, avg;

int s1 = 5;

int sub = 3;

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

total = 0;

for (j = 1; j <= sub; j++)

printf("Enter marks of Student %d in Subject %d: ", i, j);

scanf("%f", &marks);

total += marks;

avg = total / sub;


printf("Total marks of Student %d: %.2f\n", i, total);

printf("Average marks of Student %d: %.2f\n\n", i, avg);

return 0;

Output:
19. Read five persons height and weight and count the
number of person having height greater than 170 and weight
less than 50
Code:
/*Read five persons height and weight and count the number of person having height
greater than 170 and weight less than 50*/

#include <stdio.h>

int main()

int i, count;

float h1, w1;

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

printf("Enter height %d: ", i);

scanf("%f", &h1);

printf("Enter weight %d: ", i);

scanf("%f", &w1);

if (h1 > 170 && w1 < 50)

count++;

}
printf("Number of persons with height greater than 170 cm and weight less than 50
kg: %d\n", count);

return 0;

Output:
20. Write a program to check whether the given number is
prime or not.
Code:
//Write a program to check whether the given number is prime or not.

#include <stdio.h>

int main()

int num, i;

printf("Enter a number: ");

scanf("%d", &num);

if (num < 2)

printf("%d is not a prime number.\n", num);

return 0;

for (i = 2; i * i <= num; i++)

if (num % i == 0)

printf("%d is not a prime number.\n", num);

return 0;

}
printf("%d is a prime number.\n", num);

return 0;

Output:
21. Write a program to evaluate the series 1^2+2^2+3
^2+……+n^2
Code:
//Write a program to evaluate the series 1^2+2^2+3^2+……+n^2

#include <stdio.h>

int main()

int n, i;

int sum;

printf("Enter a number: ");

scanf("%d", &n);

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

sum += i * i;

printf("The sum of the series 1^2 + 2^2 + ... + %d^2 is: %d\n", n, sum);

return 0;

}
Output:
22. Write a C program to find 1+1/2! +1/3! +1/4! +. ..... +1/n!
Code:
//Write a C program to find 1+1/2! +1/3! +1/4! +. ..... +1/n!

#include <stdio.h>

int main() {

int n;

double sum = 1;

double factorial = 1;

printf("Enter a number: ");

scanf("%d", &n);

int i;

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

factorial *= i;

sum += 1.0 / factorial;

printf("The sum of the series is: %.6f\n", sum);

return 0;

}
Output:
23. Write a program to print following patterns :
Code:
//Write a program to print following patterns :

#include <stdio.h>

int main()

int i, j, space;

printf("Pattern 1\n");

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

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

printf("*");

printf("\n");

printf("Pattern 2\n");

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

for (space = 1; space <= 5 - i; space++)

printf(" ");

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


{

printf("* ");

printf("\n");

printf("Pattern 3\n");

for (i = 5; i >= 1; i--)

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

printf("*");

printf("\n");

return 0;

}
Output:
24. Write a program to print following patterns
Code:
//Write a program to print following patterns

#include <stdio.h>

int main()

int i, j;

printf("pattern 1:\n");

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

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

printf("%d", j);

printf("\n");

printf("\npattern 2:\n");

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

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

printf("%d", j);

printf("\n");

}
printf("\npattern 3:\n");

for (i = 5; i >= 1; i--)

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

printf("%d", i);

printf("\n");

printf("\npattern 4:\n");

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

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

printf("%d", i);

printf("\n");

return 0;

}
Output:
25. Write a program to print following patterns
Code:
//Write a program to print following patterns

#include <stdio.h>

int main()

int i, j;

printf("pattern 1:\n");

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

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

printf("%c", 'A' + i);

printf("\n");

printf("\npattern 2:\n");

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

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

printf("%c", 'A' + j);

}
printf("\n");

return 0;

Output:

You might also like