C Practical Arjav
C Practical Arjav
C Practical Arjav
Object No 1:-Write a program in which you declare variable of all data type
supported by ‘c’ language. Get input from user and print the value of each
various with alignment left. Right and column width 10. For real number print
their values with two digit right to the decimal.
Source Code:
iii)1 iv) 1
12 11
123 121
1234 1331
14641
SOURCE CODE
(i)
/*Name of programmer : Arjav jain Date:- 11/10/22
Path:- C:\TurboC++\Disk\TurboC3\BIN\Que2.c Unit no :- */
//A program of pattern
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=4;i++)
{
k = i;
for(j=1;j<=i;j++,k++)
{
printf("%c",(char)(k+64));
}
printf("\n");
}
getch();
}
(ii)
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,k;
clrscr();
for (i=1; i<=3;i++)
{
for (j=1;j<=3-i;j++)
{
printf (" ");
}
for (k=1;k<=(2*i-1);k++)
{
printf ("* ");
}
printf ("\n");
}
getch();
}
Input and Output:
(iii)
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c;
clrscr();
for(r=1;r<=4;r++)
{
for(c=1;c<=r;c++)
{
printf("%d ",c);
}
//for(c=1;c<=3-r;c++)
printf("\n");
}
getch();
}
Input and Output:
(iv)
#include<stdio.h>
#include<conio.h>
void main()
{
int i, res=1;
clrscr();
for(i=1; i<=5; i++)
{
if(i == 1)
res = i;
else
res = res * 11;
printf("%d", res);
printf("\n");
}
getch();
}
Input and Output:
Source Code:
Source Code:
scanf("%d",&n);
a=1;
b=1;
printf("%d %d ",a,b);
for(i=3;i<=n;i++)
{
c=a+b;
sum=sum+2;
printf("%d",c);
a=b;
b=c;
}
printf("\nTotal is %d",sum);
break;
case 3: i=1;
printf("Enter Any Number:");
scanf("%d",&num);
while(i<=2)
{
if(num%i==0)
{
count++;
}
i++;
}
if(count==2)
{
printf("It is a prime number");
}
else
{
printf("It is not a prime number");
}
break;
case 4: printf("Enter Any Year:");
scanf("%d",&year);
leap=year%4;
if(leap==0)
{
printf("It is leap year");
}
else
{
printf("It is not a leap year");
}
break;
default:printf("\nYou Have To Enter Valid choice");
}
getch();
}
Input and Output
Source Code:
getch();
}
Input and Output:
Object No 7:-Write a program to copy the one string to other string without
using library function
Source Code:
Source Code:
getch();
}
Input and Output:
Object No 9:-Write a program that read the afternoon day temperature for
each day of the month and then report the month average temperature.
Source Code:
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“Enter number in pocket for second matrix[%d][%d]”,i,j);
scanf(“%d”,&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,b[i][j]);
}
printf(“\n”);
}
printf(“Enter your choice:”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:
{
printf(“Addition of two matrix:”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf(“%d\t”,c[i][j]);
}
printf(“\n”);
}
}
break;
case 2:
{
printf(“Multiplication of two matrix:”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][j]*b[i][j];
}
printf(“%d\t”,c[i][j]);
}
printf(“\n”);
}
}
break;
case 3:
{
printf(“Transpose of matrix is:”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,a[j][i]);
}
printf(“\n”);
}
}
getch();
}
Source Code:
Source Code:
}
}
printf("List of elements are:-\n");
for(i=0;i<size;i++)
{
printf("Elements %d:%d \n",i,list[i]);
}
printf("Max Element in the list is: %d\n",max);
printf("Min Element in the list is: %d",min);
getch();
}
Input and Output:
Source Code:
}
getch();
}
Input and Output:
Source Code:
Source Code:
Source Code:
Source Code:
Object No 18:- Write a program to print Fibonacci series up to n terms and its
sum
Source Code:
Source Code:
{
n3 = n1 + n2;
printf("%d ", n3);
n1 = n2;
n2 = n3;
}
break;
default:
printf("invalid option please choose valid option.");
}
printf("\nyou want to do again (Enter: y/n):");
scanf("%d", &dummy);
scanf("%c", &ch);
} while (ch == 'Y' || ch == 'y');
getch();
}
int factorial(int n)
{
if (n >= 1)
return n * factorial(n - 1);
else
return 1;
}
Input and Output:
Source Code:
}
}
Input and Output:
Source Code:
{
printf(" %d",a[i][j]);
}
printf("\n");
}
printf("\n Second Matrix...\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf(" %d",b[i][j]);
}
printf("\n");
}
printf("Enter your choice : ");
scanf(" %d",&choice);
if(choice==1)
{
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n Addition of two Matrix...\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf(" %d ",c[i][j]);
}
printf("\n");
}
}
else if(choice==2)
{
getch();
}
Source Code:
Object No 23:- Create a structure student having data members to store roll
no.,name max mark,min mark, obtained marks.Declare a structure variable of
student provided facility to input in data members and display result of
student.
Source Code:
Object No24 :-Create a structure date with data member’s dd, mm, yy (to
store date).Create another structure employee with data members to hold
name of employee, employee id and date of joining (date of joining will be
hold by variable of structure date which appears as data members in Employee
Structure).Store data of an employee and print the same.
Source Code:
printf("Enter Year:");
scanf("%d",&e.d.Year);
printf("\nEmployee Details\n");
printf("Name of Employee:%s\n",e.ename);
printf("Employee Id:%d\n",e.eid);
printf("Date of joining:%d/%d/%d",e.d.dd,e.d.Month,e.d.Year);
getch();
}
Input and Output
Object No 25:-Create a Structure student having data member to store roll no,
number of student ,name of the three subject ,max marks,min marks, obtained
marks. Declare array of structure to hold data of 3 student . Provide Facilities
to display result of all student .
Source code:-
n",s[0].name,s[0].roll,s[0].max,s[0].min,s[0].math,s[0].max,s[0].min,s[0].scie
nce,s[0].max,s[0].min,s[0].hindi);
strcpy(s[1].name,"KUNDAN");
s[1].roll=13;
s[1].max=100;
s[1].min=33;
s[1].math=100;
s[1].science=92;
s[1].hindi=85;
printf("NAME :- %s\nROLL NO:- %d\nSUBJECT\t MAX\t MIN\t OBT\nMATH\t
%d\t %d\t %d\nSCIENCE\t %d\t %d\t %d\nHINDI\t %d\t %d\t %d\n\
n",s[1].name,s[1].roll,s[1].max,s[1].min,s[1].math,s[1].max,s[1].min,s[1].scie
nce,s[1].max,s[1].min,s[1].hindi);
strcpy(s[2].name,"RAVI");
s[2].roll=14;
s[2].max=100;
s[2].min=33;
s[2].math=70;
s[2].science=70;
s[2].hindi=55;
printf("NAME :- %s\nROLL NO:- %d\nSUBJECT\t MAX\t MIN\t OBT\nMATH\t
%d\t %d\t %d\nSCIENCE\t %d\t %d\t %d\nHINDI\t %d\t %d\t %d\n\
n",s[2].name,s[2].roll,s[2].max,s[2].min,s[2].math,s[2].max,s[2].min,s[2].scie
nce,s[2].max,s[2].min,s[2].hindi);
getch();
}
Input and Output
Source code:-
c=a;
a=b;
b=c;
printf("After swapping the values in function a=%d,b=%d",a,b);
}
Input and output
Object No 27:- Write a program to find biggest number among three numbers
using pointer and function.
Source Code:
Source code:-
/*
Name of Programmer :- Arjav jain Date :-8/11/22
Path:-C:\TURBOC3\BIN\KUNDAN Unit:- */
//A program to create structure employee with salary
#include<stdio.h>
#include<conio.h>
struct employee
{
char name[30];
int id;
float salary;
};
void main()
{
struct employee emp={"Kundan",45,35000};
struct employee *ptr;
ptr=&emp;
clrscr();
printf("Employee Information :\n");
printf("Name : %s\n",ptr->name);
printf("ID : %d\n",ptr->id);
printf("Salary : %f\n",ptr->salary);
getch();
}
Input & Output:-
Source Code:
Source Code:
int sum,multi,divi,sub;
sum=*a1+*b1;
printf("Addition is:%d",sum);
multi=*a1**b1;
printf("\nMultilication is:%d",multi);
divi=(*a1)/(*b1);
printf("\nDivision is:%d",divi);
sub=*b1-*a1;
printf("\nSubtraction is:%d",sub);
}
Source Code:
Source Code:
//fp2=fopen("Data.txt","w");
if(fp2==NULL)
{
printf("The data does not exist");
exit(1);
}
while((c=fgetc(fp1))!=EOF)
{
fputc(c,fp2);
}
printf("AB.txt->Data.txt\n");
printf("Successfully copied the content\n");
printf("Ab.txt contents are:-\n");
fp1=fopen("AB.txt","r");
c=fgetc(fp1);
while(c!=EOF)
{
printf("%c",c);
c=fgetc(fp1);
}
printf("\nData.txt contents are:-\n");
fp2=fopen("Data.txt","r");
c=fgetc(fp2);
while(c!=EOF)
{
printf("%c",c);
c=fgetc(fp2);
}
fclose(fp1);
fclose(fp2);
getch();
}
Input and Output
Source Code:
o=fopen("odd.txt","w");
printf("Press -1 to break : \n");
while(1)
{
scanf("%d",&num);
if(num==-1)
break;
else
{
putw(num,fp);
if(num%2==0)
{
putw(num,e);
}
else
{
putw(num,o);
}
}
}
fclose(fp);
fclose(e);
fclose(o);
//opening file for reading
printf("\n\nInput1 File Data is \n");
fp=fopen("input1.txt","r");
while((num=getw(fp))!=EOF)
{
// putw(num,stdout);
printf(" %d",num);
}
fclose(fp);
fclose(e);
Source Code:
while((ch=getc(stdin))!=EOF)
{
putc(ch,fp);
}
fclose(fp);
printf("File content is \n\n");
fp=fopen("input.txt","r");
while((ch=getc(fp))!=EOF)
{
putc(ch,stdout);
if(ch=='a'||ch=='i'||ch=='o'||ch=='e'||ch=='u'||ch=='A'||ch== 'I'||
ch=='O'||ch=='E'||ch=='U')
v++;
else if(ch==' ')
s++;
else
c++;
}
printf("\n\nNo. of vowel : %d\n",v);
printf("No. of consonent : %d\n",c);
printf("No. of space : %d",s);
fclose(fp);
getch();
}
Input and Output
Source Code:
{
putc(ch,fp);
}
fclose(fp);
fp=fopen("input.txt","r");
printf("\n\nFile Content Moveing file pointer forword by 5th byte using
fseek() from beginning \n");
fseek(fp,5,0);
while((ch=getc(fp))!=EOF)
{
printf("\nCharacter at position %d : ",ftell(fp));
putc(ch,stdout);
}
rewind(fp);
printf("\n\nFile content After rewind function\n");
while((ch=getc(fp))!=EOF)
{
printf("\nCharacter at position d%d : ",ftell(fp));
putc(ch,stdout);
}
fclose(fp);
getch();
}
Input and Output