This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Showing posts with label Semester I and II. Show all posts
Showing posts with label Semester I and II. Show all posts

Sunday, June 10, 2012

CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs



//Bubble Sort.

#include<stdio.h>
#include<conio.h>

void main()
{
int ar[50],i,j,num,temp;
clrscr();
printf("Enter the number of elements of the Array:\t");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\nEnter element %d :",i+1);
scanf("%d",&ar[i]);
}
for(i=0;i<num;i++)
for (j=0;j<num-i-1;j++)
if(ar[j]>ar[j+1])
{
temp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=temp;
}
printf("\nThe Sorted array is:\n");
for(i=0;i<=num-1;i++)
printf("%d\t",ar[i]);
getch();
}

CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs




//Program To Execute Binary Search.

#include<stdio.h>
#include<conio.h>

void main()
{
int ar[50],i,j,beg=0,mid,end,num,temp,item;
clrscr();
printf("\nEnter the number of elements of the Array:\t");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\nEnter element %d :",i+1);
scanf("%d",&ar[i]);
}
for(i=0;i<num;i++)
for (j=0;j<num-i-1;j++)
if(ar[j]>ar[j+1])
{
temp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=temp;
}
printf("\nEnter the element to be searched:");
scanf("%d",&item);
end=num-1;
mid=(beg+end)/2;
while(beg<=end && item!=ar[mid])
{
if(item>ar[mid])
{
beg=mid+1;
}
else
{
end=mid-1;
}
mid=(beg+end)/2;
}
if(item==ar[mid])
printf("\nThe Item is found");
else
printf("\nThe item is not found");
getch();
}





CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs


//Program to Implement a Bank Account Class.

#include<iostream.h>
#include<process.h>
#include<stdio.h>
#include<conio.h>

void menu();

class bank
{
private:

unsigned long int accno;
char name[20];
char type[15];
float balance;

public:
void insert();
void deposit();
void withdraw();
void view();
void exit1();

};

void bank::insert()
{
cout<<"\n Enter Account no:\t";
cin>>accno;
cout<<"\n Enter User Name:\t";
gets(name);
cout<<"\n Enter Account Type:\t";
gets(type);
cout<<"\n Enter Net Balance:\t";
cin>>balance;
menu();
}

void bank::view()
{
cout<<"\n Account no:\t"<<accno;
cout<<"\n User Name:\t";
puts(name);
cout<<"\n Account Type:\t";
puts(type);
cout<<"\n Net Amount:\t"<<balance;
menu();
}

void bank::deposit()
{
int deposit;
cout<<"\n Enter deposit amount";
cin>>deposit;
balance+= deposit;
menu;
}

void bank::withdraw()
{
int draw;
cout<<"\n Enter the amount to withdraw:\t";
cin>>draw;
if(draw>balance)
{
cout<<"\n Sorry! Your Balance is less than the draw amount.";
cout<<"\n Please change your draw amount.";
}
else
balance-=draw;
menu();
}

void bank::exit1()
{
char ch;
cout<<"\n Do you really want to exit (Y/N)?";
if(ch=='y'||ch=='Y')
{
cout<<"\nThank You For Using Bank Master";
getch();
exit(0);
}
else
menu();
}


void main()
{
clrscr();
menu();
getch();
}

void menu()
{
clrscr();
int n;
bank ac1;
cout<<"\n\t\t WELCOME TO BANK MASTER 2.0";
cout<<"\n 1.Insert Amount \t 2.Withdraw Amount \t 3.View Status \t 4.Exit ";
cout<<"\n\n Enter Your Choice:\t";
cin>>n;
switch(n)
{
case 1:ac1.insert();break;
case 2:ac1.withdraw();break;
case 3:ac1.view();break;
case 4:ac1.exit1();

default:{
cout<<"\n Invalid case...Please retry..";
menu();
}
}
}


CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs


//To Eliminate Duplicate Elements Of An Array.

#include<stdio.h>
#include<conio.h>

void main()
{
int ar[50];
int i,j,k,lim;
clrscr();
printf("\nEnter the limit of the array :");
scanf("%d",&lim);
printf("\nEnter the elements of Array :");
for(i=0;i<lim;i++)
scanf("%d",&ar[i]);
printf("\nThe Array before deletion is :\n");
for(i=0;i<lim;i++)
{
printf("%d",ar[i]);
printf("\t");
}

for(i=0;i<lim;i++)
{
for(j=i+1;j<lim;j++)
{
if(ar[i]==ar[j])
{
for(k=j;k<lim-1;k++)
{
ar[k]= ar[k+1];
}
lim=lim-1;
j--;
}
}
}
printf("\nThe array after deletion is:\n\n");

for(i=0;i<lim;i++)
{
printf("%d",ar[i]);
printf("\t");
}


getch();
}

CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs


//Armstrong Number

#include<stdio.h>
#include<conio.h>

void main()
{
int num,temp,rem,sum=0;
clrscr();
printf("\nEnter a Number:\t");
scanf("%d",&num);
temp=num;
while(num>0)
{
rem=num%10;
sum=sum+(rem*rem*rem);
num=num/10;
}
if(sum==temp)
printf("\nThe Number is Armstrong.");
else
printf("\nThe number is not Armstrong.");
getch();
}

CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs


//Program to calculate Area and Perimeter of Rectangle.


#include<stdio.h>
#include<conio.h>
void main()
{
float l,b,area,per;
clrscr();
printf("\n Enter the length and breadth of the rectangle \n");
scanf("%f%f",&l,&b);
area=l*b;
per=2*(l+b);
printf("\n The area and perimeter of rectangle with l=%.2f and b=%.2f is \n %.2f and %.2f",l,b,area,per);
getch();
}

CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs


//Program to find area and circumference of a circle.


#include<stdio.h>
#include<conio.h>
void main()
{
float r,area,cir;
clrscr();
printf("\nEnter the radius of the circle\n");
scanf("%f",&r);
area=3.14*r*r;
cir=2*3.14*r;
printf("\n The area and circumference of the circle with radius %.2f is %.2f and %.2f \n",r,area,cir);
getch();
}

CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs


//Program to Allot Students.

#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>

class student
{
private:
char name[20];
int rollno;
float marks[5];

public:
void getdata();
void allot();
void putdata();
};

void student::getdata()
{
cout<<"\n Enter Student's Name:\t";
gets(name);
cout<<"\n\n Enter Rollno:\t";
cin>>rollno;
cout<<"\n Enter Student's Marks (in 100):\t";
for(int i=0;i<5;i++)
{
cout<<"\n\n Enter the Mark of Subject"<<i+1<<":\t";
cin>>marks[i];
}
}
void student::putdata()
{
cout<<" \n\n The Allotment Profile is:";
cout<<"\n Name:\t";
puts(name);
cout<<"\n\n Rollno:\t"<<rollno;

for(int i=0;i<5;i++)
{
cout<<"\n\n Mark of Subject"<<i+1<<":";
cout<<marks[i];
}
}

void student::allot()
{
int sum=0;
int percent;
for(int i=0;i<5;i++)
sum+=marks[i];
percent=(sum/5);

if(percent>=96)
cout<<"\n\n Alloted to Computer Stream.";
if((percent>=91)&&(percent<=95))
cout<<"\n\n Alloted to Electronics Stream.";

if((percent>=86)&&(percent<=90))
cout<<"\n\n Alloted to Mechanical Stream.";

if((percent>=81)&&(percent<=85))
cout<<"\n\n Alloted to Electrical Stream.";

if((percent>=76)&&(percent<=80))
cout<<"\n\n Alloted to Chemical Stream.";

if((percent>=71)&&(percent<=75))
cout<<"\n\n Alloted to Civil Stream.";

if(percent<=71)
cout<<"\n\n You are Disqualified.";
}

void main()
{
clrscr();
student std;
std.getdata();
std.putdata();
std.allot();
getch();
}

CS 110 COMPUTER PROGRAMMING LAB - Basic C Programs


//Program to find aggregate marks and percentage


#include<stdio.h>
#include<conio.h>
void main ()
{
float m1,m2,m3,m4,m5,sum,per;
clrscr();
printf("\n Enter the marks of 5 subjects (Max:mark is 100)\n");
scanf("%f%f%f%f%f",&m1,&m2,&m3,&m4,&m5);
sum=m1+m2+m3+m4+m5;
per=(sum/500)*100;
printf("\n The aggregate marks of 5 subjects is %.2f and percentage is %.2f",sum,per);
getch();
}

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More