#include(stdio.h)
#include(conio.h)
int main( )
{
int a, b, c, d;
clrscr( );
printf("Enter the four different numbers:")l
scanf(" %d %d %d %d", &a, &b, &c, &d);
if(a>b && a>c && a>d)
printf("\n%d is greatest", a);
else if(b>a && b>c && b>d)
printf("\n%d is greatest", b);
else if(c>a && c>b && c>d)
printf("\n%d is greatest", c);
else
printf("\n %d is greatest", d);
getch( );
}
Note:- if u have any doubts regarding this program, feel free to contact my email id
Friday, June 19, 2009
Tuesday, June 16, 2009
Write a 'C' program to perform the selected arithmetic operation by taking two integer values using Switch Statement
#include(stdio.h)
#include(conio.h)
int main( )
{
int x,y;
char ch;
clrscr( );
printf("Enter the two integer values:);
scanf("%d%d",&x,&y);
printf("\nEnter the required arithmetic operator(+,-,*,/):");
fflush(stdin);
scanf("%c",&ch);
switch(ch)
{
case '+' : printf("\nAddition: %d", x+y); break;
case '-' : printf("\nSubstraction : %d", x-y); break;
case '*' : printf("\nMultiplication ; %d', x*y); break;
case '/': printf("\nDivision: %d", x/y); break;
default: printf("\nInvalid Arithmetic operator.");
}
getch( );
return 0;
}
Output:- Enter the two integer values: 30
20
Enter the required arithmetic operator(+,-,*,/): +
Addition: 50
#include(conio.h)
int main( )
{
int x,y;
char ch;
clrscr( );
printf("Enter the two integer values:);
scanf("%d%d",&x,&y);
printf("\nEnter the required arithmetic operator(+,-,*,/):");
fflush(stdin);
scanf("%c",&ch);
switch(ch)
{
case '+' : printf("\nAddition: %d", x+y); break;
case '-' : printf("\nSubstraction : %d", x-y); break;
case '*' : printf("\nMultiplication ; %d', x*y); break;
case '/': printf("\nDivision: %d", x/y); break;
default: printf("\nInvalid Arithmetic operator.");
}
getch( );
return 0;
}
Output:- Enter the two integer values: 30
20
Enter the required arithmetic operator(+,-,*,/): +
Addition: 50
Thursday, June 11, 2009
Write a Program to print a Histogram showing the frequencies of different word length
"stdio.h"
"ctype.h"
"string.h" // used header files
int display(int );
void main( )
{
char st[200];
int i, count;
clrscr( );
printf("Enter the required sentence( Press Ctrl + Z to stop the sentence:");
for(i=0; (st[i]=getchar())!=EOF; i++);
printf("\n\n<---------------------Histogram fequencies--------------->");
printf("\n\n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ..................");
for(i=0, count=0; ; i++)
{
if(st[i]==EOF)
break;
if(isspace(st[i])
count=display(count);
else
count++;
}
count= display(count);
printf("\n<----------------------------End---------------------->");
getch( );
}
int display(int ct)
{
int i;
printf("\n");
for(i=0; i<(ct*2); i++) // (ct*2) is applied becoz 1 alpha= 2 ascii syb
{
putchar(177);
}
printf("(%d)",ct);
return 0;
}
"ctype.h"
"string.h" // used header files
int display(int );
void main( )
{
char st[200];
int i, count;
clrscr( );
printf("Enter the required sentence( Press Ctrl + Z to stop the sentence:");
for(i=0; (st[i]=getchar())!=EOF; i++);
printf("\n\n<---------------------Histogram fequencies--------------->");
printf("\n\n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ..................");
for(i=0, count=0; ; i++)
{
if(st[i]==EOF)
break;
if(isspace(st[i])
count=display(count);
else
count++;
}
count= display(count);
printf("\n<----------------------------End---------------------->");
getch( );
}
int display(int ct)
{
int i;
printf("\n");
for(i=0; i<(ct*2); i++) // (ct*2) is applied becoz 1 alpha= 2 ascii syb
{
putchar(177);
}
printf("(%d)",ct);
return 0;
}
Subscribe to:
Posts (Atom)