CS I Practical

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Aim : Write C++ program to find Area of Circle.

#include<iostream.h>
#include<conio.h>
void main()
{
int r;
float area;
clrscr();

cout<<"Enter value of radius to find area of Circle: ";


cin>>r;
area=3.142*r*r;
cout<<"Area of circle is:"<<area;
getch();
}
Aim : To write C++ program to study control structures. display Odd numbers between 1- 100 using for
loop.

#include<iostream.h>
#include<conio.h>
void main()
{
int i;
for(i=1;i<=100;i=i+2)
cout<<i<<"\t";
getch();
}
Aim : To write C++ program to display output of * using for loop.

#include<iostream.h>
#include<conio.h>
void main()
{
int i,r;
for(i=1;i<=4;i++)
{
for(r=1;r<=i;r++)
{
cout<<"*";
}
cout<<endl;
getch();
}
Aim : Write C++ program To Find sum of first 10 numbers using while loop.
#include<iostream.h>
#include<conio.h>
void main()
{
int i,sum=0;
clrscr();
i=1;
while(i<10)
{
sum=sum+i;
i=i+1;
}
cout<<"Sum of first 10 number is: "<<sum;
getch();
}
Aim : To write C++ program to calculate average and percentage marks of student.

#include<iostream.h>
#include<conio.h>
void main()
{
int rollno,marks1,marks2,marks3,total;
float perc;
cout<<"Enter student's roll number:";
cin>>rollno;
cout<<"Enter Marks in Subject 1:";
cin>>marks1;
cout<<"Enter Marks in Subject 2:";
cin>>marks2;
cout<<"Enter Marks in Subject 3:";
cin>>marks3;
total=marks1+marks2+marks3;
cout<<"Total of the subjects:"<<total<<"\n";
perc=(float)((total*100)/300);
cout<<"Percentage marks obtained:"<<perc<<"%\n";
if(perc>=85)
{
cout<<"Class Obtained:Distinction";
}
else if(perc>=60&&perc<85)
{
cout<<"Class Obtained:First Class";
}
else if(50&&perc<60)
{
cout<<"Class Obtained:Second Class";
}
else if(perc>=35&&perc<50)
{
cout<<"Class Obtained:Pass";
}
else
cout<<"OOPS!!!! FAILED";
}
Aim : To write c++ program to study functions.

#include<iostream.h>
#include<conio.h>
void swap(int *, int *);
void main()
{
int a,b,temp;
clrscr();
cout<<"Enter Value of Variable1: ";
cin>>a;
cout<<"Enter Value of Variable2: ";
cin>>b;
cout<<"\nValues of Variables before function call: ";
cout<<a<<"\t"<<b;
swap(&a,&b);
cout<<"\nValues of Variables after function call: ";
cout<<a<<"\t"<<b;
getch();
}
void swap(int *p,int *q)
{
int temp;
temp=*p;
*p=*q;
*q=temp;

}
Aim : To write C++ program to study Arrays.

#include<iostream.h>
#include<conio.h>
void main()
{
int i,a[10];
clrscr();

for(i=0;i<10;i++)
{
cin>>a[i];
}
cout<<"Array Elements are:"<<endl;
for(i=0;i<10;i++)
{
cout<<a[i]<<"\t";
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,d,e;
char oper;
float f;
clrscr();
cout<<"Enter the First Number: ";
cin>>a;
cout<<"Enter the Operator: ";
cin>>oper;
cout<<"Enter the Second Number: ";
cin>>b;
if(oper=='+')
{
c=a+b;
cout<<"The result is: "<<c;
}
else if(oper=='-')
{
d=a-b;
cout<<"The result is: "<<d;
}
else if(oper=='*')
{
e=a*b;
cout<<"The result is: "<<e;
}
else if(oper=='/')
{
if(b==0)
cout<<"Denominator should not be 0";
else
{
f=(float)a/b;
cout<<"The result is: "<<f;
}
}
else
cout<<"Invalid operator";
getch();
}
VB Programs

Aim : Write VB Program for Addition of two numbers.


Private Sub Command1_Click()
Dim a, b, c As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c=a+b
result.Caption = c

End Sub
Aim : Designing VB Project with formula based coding . write VB program to display Square and Cube of
Number.
Private Sub cmdsaqare_Click()
Dim a, sq As Integer
a = Val(Text1.Text)
sq = a * a
lblresult.Caption = sq
End Sub

Private Sub cmdcube_Click()


Dim a, cube As Integer
a = Val(Text1.Text)
cube = a * a * a
lblresult.Caption = cube
End Sub

You might also like