Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts
Sunday, February 15, 2015
C program to swap two numbers using macros

#include<iostream.h>
#include<conio.h>
#define SWAP(a,b) {int temp; temp=a; a=b; b=temp;}
void main()
{
clrscr();
int x,y;
cout<<"Enter two numbers:";
cin>>x>>y;
cout<<"x="<<x<<" y="<<y;
SWAP(x,y);
cout<<"
x="<<x<<" y="<<y;
getch();
}
Thursday, February 12, 2015
C program to find greatest number among three numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z,max;
clrscr();
printf("Enter The Three Numbers:");
scanf("%d%d%d",&x,&y,&z);
max=x;
if(y>max&&y>z)
max=y;
else
if(z>max)
max=z;
printf("
The Greatest Number among %d %d %d is %d",x,y,z,max);
getch();
}
C program to add two numbers using structure

#include<stdio.h>
#include<conio.h>
struct sum
{
int a;
int b;
};
void main()
{
int sum1;
struct sum s;
clrscr();
printf("Enter two numbers:");
scanf("%d%d",&s.a,&s.b);
sum1=s.a+s.b;
printf("
Sum=%d",sum1);
getch();
}
C program to swap two numbers using pointers

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int *a,*b,*temp;
cout<<"Enter value of a and b:";
cin>>*a>>*b;
temp=a;
a=b;
b=temp;
cout<<"
After swaping
a="<<*a<<"
b="<<*b;
getch();
}
Tuesday, February 10, 2015
C program to find largest number of a list of numbers entered through keyboard
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr(); //to clear the screen
int i,n,x,large=0;
cout<<"How many numbers?";
cin>>n;
for(i=0;i<n;++i)
{
cout<<"
Enter number "<<i+1<<":";
cin>>x;
if(x>large)
large=x;
}
cout<<"
The largest number is "<<large;
getch();
}
Subscribe to:
Posts (Atom)