0% found this document useful (0 votes)
7 views

C - Program

C-- PROGRAM

Uploaded by

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

C - Program

C-- PROGRAM

Uploaded by

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

C++ PROGRAM

1 Write a program print your Name?


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"anu”;
}
2 .Write a program print your Name and Addrees?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"anu\n";
cout<<"karikunnu puthan veedu anappara\n";
cout<<"anappara";
getch();
}
3.Sum of Two given Number (20,5)
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
a=20;
b=5;
c=a+b ;
cout<<”sum= “<<c;
getch();
}
4. Sum of Any Two Numbers?
#iclude<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"enter the firt number\n";
cin>>a;
cout<<"enter the second number\n";
cin>>b;
c=a+b;
cout<<"sum= " <<c;
getch();
}
5. Difference of Two Numbers?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"enter the two numbers";
cin>>a>>b;
c=a-b;
cout<<"difference= " <<c;
getch();
}
6.Remainder of two Numbers?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,y,z;
cout<<"enter the two numbers";
cin>>x>>y;
z=x%y;
cout<<"remainder= "<<z;
getch();
}
7. Products of Two Number?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int p,q,r;
cout<<"enter the two numbers";
cin>>p>>q;
r=p*q;
cout<<"product= "<<r;
getch();
}
8. Division of Two Number?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"enter the two numbers";
cin>>a>>b;
c=a/b;
cout<<"quotient= "<<c;
getch();
}
9. Sum of Three Number?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<"enter the number";
cin>>a>>b>>c;
d=a+b+c;
cout<<"sum= "<<d;
getch();
}
10. Area and perimeter of circle?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int r,a,p;
cout<<"enter the radius";
cin>>r;
a=3.14*r*r;
p=2*3.14*r;
cout<<"area= "<<a;
cout<<"perimeter= " <<p;
getch();
}
11. Area and perimeter of a rectangle?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int l,w,a,p;
cout<<"enter the length and width";
cin>>l>>w;
a=l*w;
p=2*(l+w);
cout<<"area= "<<a;
cout<<"perimeter= "<<p;
getch();
}
12.Find the number is Odd or Even?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"enter a number\n";
cin>>a;
if(a%2==0)
cout<<a<<"is odd";
else
cout<<a<<"is even";
getch();
}
13.Find a number is Positive or Negative?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"enter a number\n";
cin>>a;
if(a>0)
cout<<a<<"is positive";
else
cout<<a<<"is negative";
getch();
}
14.Find the greatest number?
#include<iostream.h>
#include<conio.h>
Void main()
{
clrscr();
int a,b,c;
cout<<"enter three numbers\n";
cin>>a>>b>>c;
if(a>b&&a>c)
cout<<a<<"is greater";
else if(b>a&&b>c)
cout<<b<<"is greater";
else
cout<<c<<"is greater";
getch();
}
15.Find the year is leap year to not?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int y;
cout<<"enter a year\n";
cin>>y;
if(y%4==0) && (y%100!=0) ::(y%400==0)
cout<<y<<”is leap year”;
else
cout<<y<<”is not a leap year”;
getch();
}
16.Write a program, enter a character and display its type where
A-Z upper case,a-z lower case,0-9 digit?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ch;
cout<<"enter a character”;
cin>>c;
if(ch>=A && ch<=Z)
cout<<"upper case”;
else if(ch>=a && ch<=z)
cout<<"lower case”;
else if(ch>=0 && ch<=9)
cout<<”digit”;
else
cout<<”special character”;
getch();
}
17.Enter a day number and display its corresponding days?
#include<iostream.h >
#include<conio.h >
Void main ()
{
clrscr();
cout<<"enter a day number";
cin>>d;
if(d==1)
cout<<"Monday";
else if(d==2)
cout<<"Tuesday";
else if(d==3)
cout<<"Wednesday";
else if(d==4)
cout<<"Thursday";
else if(d==5)
cout<<"Friday";
else if(d==6)
cout<<"Saturday";
else if(d==7)
cout<<"Sunday";
else
cout<<"not valid";
getch();
}
19.Enter a month number and display its corresponding month?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int m;
cout<<"enter a month number";
cin>>m;
if(m==1)
cout<<"january";
else if(m==2)
cout<<"february";
else if(m==3)
cout<<"march";
else if(m==4)
cout<<"april";
else if(m==5)
cout<<"may";
else ifdm==6)
cout<<"june";
else if(m==7)
cout<<"july";
else if(m==8
cout<<"august";
else if(m==9)
cout<<"september";
else ifdm==10)
cout<<"october";
else if(m==11)
cout<<"november";
else if(m==12)
cout<<"december";
else
cout<<”not valied”;
getch();
}
19.Ener a number and display its corresponding word?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<"enter a number";
cin>>n;
if(n==1)
cout<<”one";
else if(n==2)
cout<<”two";
else if(n==3)
cout<<”three";
else if(n==4)
cout<<”four";
else if(n==5)
cout<<”five";
else if(n==6)
cout<<"six";
else if(n==7)
cout<<”seven";
else if(n==8)
cout<<"eight";
else if(n==9)
cout<<”nine";
else
cout<<”not valied”;
getch();
}
20.Enter a character and display its corresponding status?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int c,a,m,o,g;
cout<<"enter the character”;
cin>>c;
if(c=='a')
cout<<"apple";
else if(c=='m’)
cout<<"mango";
else if(c==’o')
cout<<"orange";
else if(c=='g')
cout<<"grapes";
else
cout<<"not valid";
getch();
}
21.Prepare a Mark list with percentage?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int m1,m2,m3,m4,p,s,t;
cout<<"enter the marks\n";
cin>>m1>>m2>>m3>>m4;
s=m1+m2+m3+m4;
t=400;
p=s*100/t;
cout<<"Total = "<<s;
cout<<"\nPercentage =\t"<<p;
if(p>=80)
cout<<"distinction";
else if(p>=60)
cout<<”First class”;
else if(p>=50)
cout<<”Second class";
else if(p>=35)
cout<<”Third class”;
else
cout<<”Failed”;
getch();
}
22.Enter a character and display its status?
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr();
int a,c,r,e,d;
cout<<”enter the character “;
cin>>a;
switch (a)
{
case’c’:
cout<<”compiler”;
break;
case 'r':
cout<<"run";
break;
case 'e':
cout<<"error";
break;
case 'd':
cout<<"debug";
break;
default:
cout<<"not valid";
}
getch();
}
23.Print 1st 10 natural numbers?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=0;i<=10;i++)
cout<<i<<"\n";
getch();
}
24.Print even numbers up to 10?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=2;i<=10;i+=2)
cout<<i<<"\n";
getch();
}
25.Print odd numbers upto 10?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=1;i<=10;i+=2)
cout<<i<<"\t";
getch();
}
26.Print 10 to 1 in decreasing order?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=100;i>=1;i--)
cout<<i<<"\n";
getch();
}
27.Find the sum of natural number upto 10 using four loop?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,sum=0;

for(i=1;i<=10;i++)
{cout<<i<<"\n";
sum=sum+i;
}
cout<<"sum ="<<sum<<” “;
getch();
}
28.Find the factorial of a number?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,fact=1,n;
cout<<"enter a number\n";
cin>>n;
for(i=1;i<=100;i++)
{
fact=fact*i;
}
cout<<”factorial=”<<fact;
getch();
}
THE END

You might also like