0% found this document useful (0 votes)
9 views15 pages

Pwc Journal [Fcs2324011]

Uploaded by

goyer67899
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views15 pages

Pwc Journal [Fcs2324011]

Uploaded by

goyer67899
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

S.I.E.

S College of Arts, Science and Commerce(Autonomous)


Sion(W), Mumbai – 400 022.

CERTIFICATE

This is to certify that Miss./Mr Ashutosh vinodkumar Maurya


Roll No.FCS2324011 has successfully completed the necessary course of
experiments in the subject of Programming with C during the academic year
2023 – 2024 complying with the requirements of University of Mumbai, for the
course of FYBSc Computer Science [Semester-II].

Prof. In-Charge
Dr ManojKumar Singh
(PROGRAMMING WITH C)

Examination date:

Examiner’s Signature & Date:

Head of the Department College Seal


Prof. Manoj Singh
INDEX
Practica Description Page Date Signature
l no: no
1 Basic Programs 3 21-12-2023
2 Programs to Demonstrate input , 6 04-01-2024
output functions
3 Conditional Statements 7 11-01-2024
4 Programs on Functions 9 01-02-2024
5 Recursive Functions 9 29-02-2024
6 Arrays 11 07-03-2024
7 Pointers 12 14-03-2024
8 Programs on File Handling 13 23-03-2024
 Practical 1: - Basic Programs
A. Write a program to find addition, subrtraction, multiplication, division of
two numbers
 Code:-

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,add=0,sub=0,mul;
float div;
clrscr();
printf("Enter the numbers for operation:-");
scanf("%d %d",&a,&b);
add=a+b;
sub=a-b;
mul=a*b;
div=a/b;
printf("The additiion of two numbers is :- %d\n",add);
printf("the subtraction of two number is :- %d\n",sub);
printf("The multiplication of two numbers is :-%d\n",mul);
printf("The division of two numbers is :- %f",div);
getch();
}
 Output:-

B. Write a program to find area of rectangle, square and circle


 Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
float l,b,s,r,area;
clrscr();
printf("Enter the digits for which you have to perform task\n");
printf("1.Area of rectangle .\n2.Area of square.\n3. Area of circle.\n");
scanf("%d",&x);
switch(x){
case 1:
printf("Enter the length and breadth of the rectangle:-");
scanf("%f%f",&l,&b);
area=l*b;
printf("The area of the rectnagle is:- %funit sqr\n",area);
break;
case 2:
printf("Enter the side of a square:-\n");
scanf("%f",&s);
area=s*s;
printf("The area of the square is :- %f unit sqr\n",area);
break;
case 3:
printf("Enter the radius of the circle :-\n");
scanf("%f",&r);
area=3.14*r*r;
printf("The area of the circle is :- %f unit sqr\n",area);
break;
default:printf("Invalid input");
break;
}getch();
}

 Output:-

C. Write a program to find the volume of a cube, sphere and cylinder.


 Code:-

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
float a,r,h,vol;
clrscr();
printf("Enter the digit for the operation you have to do\n");
printf("1. Volume of cube. \n2. Colume of sphere.\n3. Volume of cylinder.\n");
scanf("%d",&x);
switch(x)
{
case 1:
printf("Enter the side of a cube:-\n");
scanf("%f",&a);
vol=a*a*a;
printf("The volume of the cuibe is :- %f unit cube",vol);
break;
case 2:
printf("Enter the radius pf sphere:-\n");
scanf("%f",&r);
vol= 1.67*3.14*r*r*r;
printf("The volume of sphere is :- %f unit cube\n",vol);\
break;
case 3:
printf("Enter the radius and height of the cylinder :-\n");
scanf("%f%f",&r,&h);
vol=3.14*r*r*h;
printf("The volume of the cylinder is:- %f unit cube\n",vol);
break;
default :
printf("Invalid input\n");
break;
}
getch();
}

 Output:-
 Practical 2: - Demonstrate input and output function
A. Programs to input and output functions
 Code:-

#include<stdio.h>
#include<conio.h>
void main()
{
int n1=0,n2=0;
clrscr();
printf("Enter the 2 numbers :-");
scanf("%d %d",&n1,&n2);
printf("The addition of the number %d and %d is :-%d",n1,n2,n1+n2);
getch();
}
 Output:-
 Practical 3: - Conditional statements and loops
 Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
clrscr();
printf("Enter the number to check:-");
scanf("%d",&x);
if (x%2==0){
printf("The given numvber is even ");}
else{
printf("The given number is odd");}
getch();
}
 Output:

B. Write a program to check whether a number is positive, negative or zero


 Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
clrscr();
printf("Enter the number to check:-");
scanf("%d",&x);
if (x>0){
printf("The given number is positive"); }
else if (x<0){
printf("The given number is negative");}
else{
printf("The number is zero");}
getch();
}
 Output:
C. Write a program to find a sum of squares of a digits of a number
 Code:-

#include<stdio.h>
#include<conio.h>
void main()
{
int x,sum=0,r;
clrscr();
printf("Enter the number:-");
scanf("%d",&x);
while (x!=0){
r=x%10;
sum+=r*r;
x=x/10;}
printf("The sum of square of the digits is :- %d",sum);
getch();
}

 Output:

D. Write a program to reverse a digits of an integer.


 Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int x,r,rev=0;
clrscr();
printf("Enter the number:-");
scanf("%d",&x);
while (x!=0){
r=x%10;
rev=rev*10+r;
x=x/10;}
printf("The reverse of the number is :- %d",rev);
getch();
}
 Output:

 Practical 4: - Programs on Functions


 Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int f(int);
int x,result=0;
clrscr();
printf("Enter the number to find the square");
scanf("%d",&x);
result=f(x);
printf("The square of the given number is :- %d",result);
getch();
}
int f(int x){
int z;
z=x*x;
return z;}

 Output:

 Practical 5: - Recursive Functions


A. Write a program to find a factorial of a number using recursive function
 Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int fact(int);
int x,result=0;
clrscr();
printf("Enter the number:-");
scanf("%d",&x);
result=fact(x);
printf("The factoral of the given number %d is %d ", x, result );
getch();
}
int fact(int x){
if (x==1){
return 1;}
else{
return x*fact(x-1);}}

 Output:

B. Write a program to find a sum of natural numbers using recursive functions


 Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int sum(int);
int x,result=0;
clrscr();
printf("Enter the number:-");
scanf("%d",&x);
result= sum(x);
printf("The sum of the given %d natural numbers is %d",x,result);
getch();
}
int sum(int x){
if (x==1){
return 1;}
else{
return x+sum(x-1);}}

 Output:

 Practical 6 : - Arrays
A. Write a program to find a largest value stored in array.
 Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int x[5],max=0,i=0;
clrscr();
for (i=1;i<=5;i++){
printf("Enter the %dst number :- ",i);
scanf("%d",&x[i]);}
max=x[1];
for (i=2;i<=5;i++){
if (max<x[i]){
max=x[i];}}
printf("The largest number is :- %d",max);
getch();
}
 Output:

B. Write a program to arrange ‘n’ elements stored in array in ascending to


descending order.
 Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],n,i,temp,j;
clrscr();
printf("Enter the size of the array:-");
scanf("%d",&n);
for (i=1;i<=n;i++){
printf("Enter the %dst digit:-",i);
scanf("%d",&a[i]);}
for (j=1;j<=n;j++){
for (i=1;i<=n;i++){
if (a[i]>a[i+1]){
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;}}}
printf("The sorted array is:-\n");
for (i=1;i<=n;i++){
printf("%d\n",a[i]);}
getch();
}

 Output:

 Practical 7: - Pointers
A. Write a programs to demonstrate the use of pointers.
 Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int num=10;
int*ptr;
clrscr();

ptr=&num;

printf("Value of num:- %d\n",num);


printf("Address of num:- %p\n",&num);
printf("Value of num using pointer :- %d\n",*ptr);
printf("Address of num using pointer:- %p",ptr);
getch();
}

 Output:

B. Write a program to perform addition and subtraction of two pointers.


 Code:
#include<stdio.h>
#include<conio.h>
void main(){
int num1,num2,*a,*b;
clrscr();
a=&num1;
b=&num2;
printf("Enter the 1st number:-");
scanf("%d",&num1);
printf("Enter the 2nd number:-");
scanf("%d",&num2);
printf("The addition of numbers is :- %d\n",*a+*b);
printf("The subtraction of numbers is :- %d",*a-*b);
getch();
}

 Output:

 Practical 8: - Programs on File Hndling


A. Write a program to create a file , write in it and close a file.
 Code:

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
int n;
clrscr();
fp=fopen("Number.dat","w");
if (fp==NULL){
printf("Can't open file");
exit(0);}
printf("Enter an Integer");
scanf("%d",&n);
fprintf(fp,"%d",n);
fclose(fp);
getch();}
 Output:
B. Write a program to open a file , read from it, and close a file .
 Code:

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
int n;
clrscr();
fp=fopen("Number.dat","r");
if (fp==NULL){
printf("n't open file");
exit(0);}
fscanf(fp,"%d",&n);
printf("Entered number is : %d",n);
getch();}

 Output:

C. Write a program to read the name and marks pf ‘n’ number of students and
store them in a file.
 Code:

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
int n,i,marks;
char name[50];
clrscr();
fp=fopen("students_record.txt","w");
if (fp==NULL){
printf("Can't open the file ");
exit(0);}
printf("Enter the number of students :-");
scanf("%d",&n);
for (i=1;i<=n;i++){
printf("Enter the name of the %dst student:-",i);
scanf("%s",&name);
printf("Enter the mark of the %dst student:-",i);
scanf("%d",&marks);
fprintf(fp,"%s\t%d\n",name,marks);}
printf("Data is successfully written to the file \n");
fclose(fp);
getch();
}
 Output:

You might also like