Professional Documents
Culture Documents
Aakashs
Aakashs
Aakashs
ON
FUNDAMENTALS OF
COMPUTER
PROGRAMMING
Submitted to:
Ms. Luxmi Sapra
(AP in IT Dept)
Submitted by:
Aakash Narang
110913085
ECE-2
INDEX
S.No
1
2
Experiment
Write a program to swap number using a third variable.
Write a program to find the largest of three numbers (ifthen-else).
Date
14/08/201
3
14/08/201
3
21/08/201
3
11/09/201
3
18/09/201
3
09/10/201
3
09/10/201
3
23/10/201
3
Sign
S.no.
Experiment
Date
11
30/10/2013
12
06/11/2013
13
13/11/2013
14
30/11/2013
Sign
Experiment No.1
Aim :Write a program to swap two number using third variable.
Source Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{int a,b,c;
clrscr();
printf("enter value of a");
scanf("%d",&a);
printf("enter value of b");
scanf("%d",&b);
c=a;
a=b;
b=c;
printf("value of a %d",a);
printf("value of b %d",b);
getch();}
OUTPUT:
Experiment No.2
Aim
Source Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
int a,b,c;
printf("enter the numbers");
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if(a>b)
{if(a>c)
printf("greatest number is%d",a);
else
printf("greatest number is%d",c);
}
else
if(b>c)
OUTPUT:
Experiment No.3
Aim: Write a program to find the largest of ten numbers
Source code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
int i,a[10],large=0;
printf("enter the numbers");
for(i=0;i<10;i++)
{printf("enter number%d ",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<10;i++)
{if(a[i]>large)
large=a[i];
}
printf("greatest number is%d",large);
getch();
OUTPUT:
Experiment No.4
Aim: Write a program to find the largest and second largest of ten
numbers using array.
Source code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
int i,a[10],max,max2,temp;
for(i=0;i<10;i++)
{printf("enter number%d ",i+1);
scanf("%d",&a[i]);
}
a[0]=max;
a[1]=max2;
if(max<max2)
{temp=max;
max=max2;
max2=temp;}
for(i=2;i<10;i++)
{if(a[i]>=max)
{max2=max;
max=a[i];
}
else if(a[i]>max2)
{max2=a[i];}}
printf("greatest number is%d,max);
printf("second largest number is%d",max2);
getch();
Output:
Experiment No.5
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{clrscr();
char ch[20];
int i,l=0;
printf("enter the string");
scanf("%s",&ch);
for(i=0;c[i]!='/0';i++)
l++;
printf("length of string=%d",l);
prinf("/n reverse of the string is");
for(i=a;i>=0;i--)
printf("%c",ch[i]);
getch();}
OUTPUT:
Experiment 6
Aim :Write a program to concatenate of two strings.
Source code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{char a[20],b[20],c[20];
int i,j;
clrscr();
printf("\n enter first string");
scanf("%s",&a);
printf("\n enter second string"
scanf("%s",&b);
for(i=0;a[i]!='\0';i++)
c[i]=a[i];
for(j=0;b[j]!='\0';j++)
c[i+j]=b[j];
}
c[i+j]='\0';
printf("s%",c)'
getch();}
Experiment No.7
Experiment 8
}}
if(flag==1)
printf("palindrome");
else
printf
("not palindrome");
getch();}
OUTPUT
Experiment 9
Aim: Write a program to find the average male and female height in class
Source code:
#include<stdio.h>
#include<conio.h>
void main()
{
float m[16],f[16],a,v,sum=0,sum1=0;
int i;
clrscr();
printf("enter no of male :");
scanf("%f",&a);
printf("\nenter no of female :");
scanf("%f",&v);
for(i=1;i<=a;i++)
{
printf("enter male height of %d :",i);
scanf("%f",&m[i]);
sum=sum+m[i];
}
printf("\n\n");
for(i=1;i<=v;i++)
{
printf("enter female height of %d :",i);
scanf("%f",&f[i]);
sum1=sum1+f[i];
}
printf("\nTheavg of male height is : %f",sum/a);
printf("\nTheavg of female height is : %f",sum1/v);
getch();
}
Output:
Experiment 10
Aim: Write a program to multiply two matrices.
Source code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
clrscr();
printf("\nEnter the row and column of first matrix");
scanf("%d %d",&m,&n);
printf("\nEnter the row and column of second matrix");
scanf("%d %d",&o,&p);
if(n!=o)
{
printf("Matrix mutiplication is not possible");
printf("\nColumn of first matrix must be same as row of second matrix");
}
else
{
printf("\nEnter the First matrix->");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the Second matrix->");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
clrscr();
printf("\nThe First matrix is\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++){
printf("%d\t",a[i][j]);
}
}
printf("\nThe Second matrix is\n");
for(i=0;i<o;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",b[i][j]);
}
}
for(i=0;i<m;i++)
for(j=0;j<p;j++)
c[i][j]=0;
for(i=0;i<m;i++)
{ //row of first matrix
for(j=0;j<p;j++)
{ //column of second matrix
sum=0;
for(k=0;k<n;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
}
}
}
printf("\nThe multiplication of two matrix is\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",c[i][j]);
}
}
getch();
}
Output:
Experiment 11
Aim: write a
Source code:
#include<conio.h>
#include<stdio.h>
struct student
{
char name[50];
int roll;
int marks;
}f[10];
void main()
{
int a,i;
clrscr();
printf("enter no of student :") ;
scanf("%d",&a);
printf("\n");
for(i=1;i<=a;i++)
{
printf("enter name :");
scanf("%s",&f[i].name);
printf("enter roll :");
scanf("%d",&f[i].roll);
printf("enter marks :");
scanf("%d",&f[i].marks);
}
printf("\n\n");
clrscr();
for(i=1;i<=a;i++)
{
printf("\n name of %d student is : %s",i,f[i].name);
printf("\n roll of %d student is: %d",i,f[i].roll);
printf("\nenter marks %d student is: %d",i,f[i].marks);
printf("\n=========================================");
}
getch();
}
Output:
Experiment 12
Aim: write a program of nested structure
Source code:
#include<conio.h>
#include<stdio.h>
struct dob
{
int date;
int month;
int year;
};
struct employee
{
char name[50];
char des[10];
int salary;
struct dob a;
};
void main()
{
int i;
struct employee f;
clrscr();
printf("\nenter name :");
gets(f.name);
printf("\nenter des :");
scanf("\n%s",&f.des);
printf("\nenter salary :");
scanf("\n%d",&f.salary);
printf("\nenter date/ month/year in integer :");
scanf("\n%d%d%d",&f.a.date,&f.a.month,&f.a.year);
printf("\n name :%s",f.name);
printf("\n des : %s",f.des);
printf("\n salary : %d",f.salary);
printf("\n age : %d/%d/%d",f.a.date,f.a.month,f.a.year);
getch();
}
Output:
Experiment 13
Aim: Programs on file handling.
Source code:
#include<conio.h>
#include<stdio.h>
void main()
{
FILE *r,*c,*v;
int a=0;
char ch ;
r=fopen("rahul","w");
clrscr();
printf("enter ur para\n");
while(1)
{ ch=getchar();
if(ch=='0')
break;
else
putc(ch,r);
}
fclose(r);
r=fopen("rahul","r")
c=fopen("cons","w");
v=fopen("vow","w");
while((ch=getc(r))!=EOF)
{if(ch==' ')
a++;
else
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
putc(ch,v);
else
putc(ch,c);
}
fclose(r);
fclose(c);
fclose(v);
r=fopen("rahul","r");
c=fopen("cons","r");
v=fopen("vow","r");
printf("\n\n cont..of file \n");
while((ch=getc(r))!=EOF)
{putchar(ch);
}
printf("\n\n vowel containing file \n");
while((ch=getc(v))!=EOF)
{putchar(ch);
}
printf("\n\n consonant containing file \n");
while((ch=getc(c))!=EOF)
{putchar(ch);
}
printf("\n\nno of spaces is : %d",a);
fclose(r);
fclose(c);
fclose(v);
getch();
Output: