This program takes two numbers as inputs and compares them to show which one is greater.
#include // Header file
#include // Header file
void main() // Main function
{
int a,b flag; // Define variables
flag=2; // Initialize variables
clrscr() // Clear screen
printf(" Enter the first number: \n");
scanf("%d",&a); // Input First number
printf(" Enter the second number: \n");
scanf("%d",&b); // Input second number
if ( a>b)
flag=1;
else if (a
flag=0;
if( flag==1)
printf( "%d is greater than %d ", a,b);
else if(flag==0)
printf( "%d is greater than %d ", b,a);
else
printf(" Both are equal ");
getch();
}
*************************************************** OUTPUT ***************************************************
Enter the first number :10
Enter the second number:12
12 is greater than 10
#include<iostream.h>Function Declaration
#include<conio.h>
void fibonacci(long int i,long int j);Instance Variables Declaration
static int totNum;Main Method which uses the recursive function to print fibonacci series
static int count;
void main(){
Local variables declaration
long int i=0,j=1;
clrscr();
Accept the max number of series
cout<<"Enter The Limit:";
cin>>totNum;
Print initial numbers
cout<<endl<<i<<" "<<j<<" ";
Track count, initialize to 2, as the starting two numbers are already printed.
count=2;
Recurse through function to print series
fibonacci(i, j);
getch();
}
Now the actual funtionality to get the fibonacci number reccursively.
void fibonacci(long int i,long int j){
// Print next number
cout<<i+j<<" ";
// Increase the count
count++;
Check if count reaches the max number else recurse.
if(count<=totNum){
fibonacci(j,i+j);
}
}
#include<iostream.h>#include<stdio.h>#include<string.h>#include<conio.h>
void selsort(char *items,int count){
// Local variable declarationint a,b,c;int exchange;
char t;
// Loop over the array of characters
for(a=0;a<count-1;++a){
exchange=0;
c=a;
t=items[a];
for(b=a+1;b<count;++b){if(items[b]<t){c=b;t=items[b];exchange=1;}
}
if(exchange){items[c]=items[a];items[a]=t;}}}
void main(){clrscr();char s[30];cout<<"Enter A String:";gets(s);selsort(s,strlen(s));cout<<"The String After Selection Sort:"<<s;getch();}
Page 21 of 21