Beruflich Dokumente
Kultur Dokumente
[Q002] W.A.P. in C to find the Fifth root of the sum of the squares of the first 100
ODDnumbers only.
/* To find the Fifth root of the sum of the squares of the first 100 ODD numbers
ONLY */
#include< stdio.h >
#include< conio.h >
#include< math.h >
int main(void)
{
long i,oddnum=1,sqrnum,sum=0;
for (i=1; i<=100; i++)
{
sqrnum=oddnum * oddnum; // Square the ODD number
sum+=sqrnum; // Add Square value to the sum
oddnum+=2; // Get the next ODD number
}
printf("\nThe result is : %ld,%.2f",sum,pow((double)sum,(1.0/5.0)));
return(0);
} /* End of Main */
[Q003] W.A.P. in C to multiply any two numbers without using * (asterisk)
[Hint : Use BITWISE OPERATORS]
/* Multiplication of two numbers using BITWISE OPERATORS ONLY */
#include< stdio.h >
int main()
{
long int i,n,mul,mul2,count,temp,a,b,sum,carry,res,tot;
printf("\nEnter any 2 numbers : ");
scanf("%ld %ld",&mul,&n);
mul2=temp=mul;
for (i=2; i<=n; i++)
{
temp=mul;
count=32;
res=1;
tot=sum=carry=0;
while (count--)
{
a=temp & 0x1;
b=mul2 & 0x1;
if ((a^b==1) && (carry==1))
{
sum=(a^b)^carry;
carry=(a^b)&carry;
}
else
{
sum=a^b|carry;
carry=a&b;
}
temp=temp>>1;
mul2=mul2>>1;
tot+=res*sum;
res=res*2;
}
mul2=tot;
}
printf("\n%3ld * %3ld = %3ld",mul,i-1,tot);
getch();
return(0);
} /* End of Main */
[Q004] W.A.P. in C to check whether given number x is equal to the value 2 POWER i
or something, where i>=0 using BITWISE operators ONLY. [Hint : Check whether the
given number x is equal to the value 2 POWER i or something using BITWISE operators
ONLY]
/* Check whether the given number x is equal to the value 2 power i or not using
BITWISE operators ONLY */
#include< stdio.h >
#include< conio.h >
int main(void)
{
long x;
printf("Enter a number : ");
scanf("%ld",&x);
if ((x & 0x1) == 0x0) // Checking the Least significant bit
printf("The given number %ld is EQUAL to the value 2 POWER
something",x);
else
printf("The given number %ld is NOT EQUAL to the value 2 POWER
something",x);
getch();
return(0);
} /* End of Main */
[Q005] W.A.P. in C to maintain 2 STACKS within a SINGLE ARRAY and the values of
onestack should not overwrite the values of another stack.
case 5 : Display();
break;
case 6 : exit(0);
}
}
return(0);
} /* End of Main */
[Q006] W.A.P. in C that act as a guessing game in which the user has eight tries to
guess a
randomly generated number. The program will tell the user each time whether he
guessed high or
low. The user WINS the game when the number guessed is same as randomlygenerated
number.
/* Guessing Game Solution */
#include< stdlib.h >
#include< stdio.h >
#include< time.h >
int main(void)
{
int i=8,rval,val,flag=1;
randomize(); // Initialize the random number generatorrval=random (100); // Generates a
random number in the range 0 to99
printf("Welcome to Guessing Game.\n");
printf("RULES:\n1. Only 8 chances to guess the randomly generatednumber.");
printf("\n2. You can WIN the game when the number guessed is sameas the");
printf("randomly generated number.\n3. Follow the hints.");
printf("\n\n$$$ Good Luck. Start Guessing $$$");
for (i=1; i<=8; i++)
{
printf("\n\nGUESS %d ? ",i);
scanf("%d",&val);
if (val > rval)
printf("Your value is GREATER THAN the randomly generatednumber");
else if (val < rval)
printf("Your value is LESSER THAN the randomly generatednumber");
else
{
flag=1;
break;
}
}
if (flag)
printf("\n\n*** You are the WINNER. No. of tries = %d***",i);
else
printf("\n\n*** You are the LOSER. ***");
return(0);
} /* End of Main */
[Q007] W.A.P. to determine how much money is in a piggy bank that contains several50
paise coins, 25 paise coins, 20 paise coins, 10 paise coins and 5 paise coins. Usethe
following values to test your program : Five 50 paise coins, Three 25 paise coins,
Two 20 paise coins, One 10 paise coin and Fifteen 5 paise coins. (Answer : Rs. 4.50)
/* To determine how much money in a piggy bank */
#include< stdio.h >
#include< string.h >
#include< conio.h >
int main(void)
{
float
coin1=0.50,coin2=0.25,coin3=0.20,coin4=0.10,coin5=0.05,total=0.0;
int ncoins;
clrscr();
printf("How many 50 paise coins : ");
scanf("%d",&ncoins);
total += (ncoins * coin1);
printf("** %.2f **",total);
} /* End of Main */
[Q008] Modify the program given in [Q007] to accept total amount (in rupees)
andconvert them into paise.(Vice-versa of [Q007])
/* Denominations */
#include< stdio.h >
#include< string.h >
#include< conio.h >
int main(void)
{
int nc1,nc2,nc3,nc4,nc5,temp;
float total;
clrscr();
printf("Enter the amount : ");
scanf("%f",&total);
temp = total * 100;
nc1 = temp / 50;
temp = temp % 50;
nc2 = temp / 25;
temp = temp % 25;
nc3 = temp / 20;
temp = temp % 20;
nc4 = temp / 10;
temp = temp % 10;
nc5=temp;
printf("\n\nNo. of 50 paise coins = %d",nc1);
printf("\nNo. of 25 paise coins = %d",nc2);
printf("\nNo. of 20 paise coins = %d",nc3);
printf("\nNo. of 10 paise coins = %d",nc4);
printf("\nNo. of 5 paise coins = %d",nc5);
getch();
return(0);
} /* End of Main */
[Q09] W.A.P. in C to determine how many of the characters are vowels and how
manyare consonants in a given line of text. Also terminate the string when the
inputcharacter encountered is other than the alphabets(a-z or A Z) and Blank spaces.
[Hint:(a) When the input string is 'C FOR SWIMMERS, TEST YOUR C
PROGRAMMINGSTRENGTHS'. Consider the string 'C FOR SWIMMERS' only
Because ',' is encountered.
(b) When the input string is 'Y2K PROBLEM'. Consider the character 'Y' only
Becausethe '2' is encountered.]
int main(void)
char *str;
int i,vow=0,cons=0;
clrscr();
printf("Enter a string : ");
scanf("%[
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",str);
for (i = 0; i < strlen(str); i++)
if (str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' ||
str[i]=='U' ||
str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' ||
str[i]=='u')
vow++;
else if (str[i] != ' ') // Ignore BLANK characters
cons++;
} /* End of Main */
l = sum - (i + j + k);
printf("\n%c%c%c%c",str[i],str[j],str[k],str[l]);
}
}
} /* End of Main */
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{clrscr();
char str1[20],str2[20];
int m,x,i,j;
printf("\n Enter any string - ");
scanf("%s",&str1);
m=strlen(str1);
for(i=m-1,j=0;i>=0;i--,j++)
{
str2[j]=str1[i];
}
str2[j]='\0';
x=strcmp(str1,str2);
if(x!=0)
printf("\n The entered string is not palindrome");
if(x==0)
printf("\n The entered string is palindrome");
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{clrscr();
char a[20],b[20];
printf("Enter the first string = ");
scanf("%s",&a);
printf("Enter the second string = ");
scanf("%s",&b);
strcat(a,b);
printf("The concatenated string is = ");
printf("%s",a);
getch();
}
To find the reverse of a string
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{clrscr();
char a[20];
printf("Enter the first string = ");
scanf("%s",&a);
strrev(a);
printf("The reverse string is = ");
printf("%s",a);
getch();
}
To multiply two given Matrices of orders (2*3) &
(3*3) respectively
#include<stdio.h>
#include<conio.h>
void main ()
{clrscr();
int m1[2][3],m2[3][3],r[2][3];
int i,j;
puts("Values for 1st Matrix of 2*3");
for(i=0;i<2;i++)
{
printf("\n%d row",i+1);
for(j=0;j<3;j++)
{
printf("\nEnter the value of column : ");
scanf("%d",&m1[i][j]);
}
}
puts("\n\n\nEnter values for 2nd Matrix of 3*3 ");
for(i=0;i<3;i++)
{
printf("\n%d row",i+1);
for(j=0;j<3;j++)
{
printf("\nEnter the value of column : ");
scanf("%d",&m2[i][j]);
}
}
for(i=0;i<2;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
r[i][j]=0;
r[i][j]=m1[i][j]+m2[i][j];
}
}
puts("\nResultant Matrix : ");
for(i=0;i<2;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf("%d",r[i][j]);
}
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{clrscr();
int a[10],i,j,x;
for(i=0;i<10;i++)
{
printf("\nEnter the no., %d = ",i+1 );
scanf("%d",&a[i]);
}
for(i=0;i<10;i++)
{
for(j=i+1;j<=10;j++)
{
if(a[i]<a[j])
{
x=a[j];
a[j]=a[i];
a[i]=x;
}
}
}
printf("\nThe largest no. :%d",a[0]);
printf("\nThe 2nd largest no.is :%d",a[1]);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
int num,i;
int num1=0;
printf("Enter a number = ");
scanf("%d",&num);
while(num!=0)
{
i=num%10;
num=num/10;
num1=num1*10+i;
}
printf("Reversed No. is = %d",num1);
getch();
}
To find the average height of 5 Males & 5
Females
#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
float mavg,mtot,favg,ftot,mh[5],fh[5];
int i;
puts("Enter the Male heights");
for(i=0;i<5;i++)
{
printf("\nHeight, %d = ",i+1);
scanf("%f",&mh[i]);
mtot=mh[i]+mtot;
}
mavg=mtot/5;
printf("\nThe average Male height is = %f",mavg);
puts("\n\n\n\nEnter the Female heights");
for(i=0;i<5;i++)
{
printf("\nHeight, %d = ",i+1);
scanf("%f",&fh[i]);
ftot=fh[i]+ftot;
}
favg=ftot/5;
printf("\nThe average Female height is = %f",favg);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
int a,b,c;
printf("Enter any integer,a");
scanf("%d",&a);
printf("Enter any integer,b");
scanf("%d",&b);
printf("Enter any integer,c");
scanf("%d",&c);
if(a>b)
{
if(a>c)
{printf("a is greatest");
printf("%d",a);}
else
{
printf("c is greatest");
printf("%d",c);
}
}
(Greatest out of three numbers continued…………)
else
{
if(b>c)
{printf("b is greatest");
printf("%d",b);}
else
{
printf("c is greatest");
printf("%d",c);
}
}
getch();
}
To find the roots of a Quadratic Equations
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
float a,b,c,p,q,r,x,conjug_X;
printf("Enter coefficient, a = ");
scanf("%f",&a);
printf("Enter coefficient, b = ");
scanf("%f",&b);
printf("Enter coefficient, c = ");
scanf("%f",&c);
r=2*a;
p=-b/r;
q=(sqrt((b*b)-(4*a*c)))/r;
x=p+q;
conjug_X=p-q;
printf("x = ");
printf("%f",x);
printf("\nConjugate x = ");
printf("%f",conjug_X);
getch();
}
for(i=0;(a[i]=getchar())!='$';i++)
;
a[i]='\0';
for(i=0,j=0;a[i];j++,i++)
b[j]=a[i];
b[j]='\0';
Sample Run:
Program:
int i,j;
char a[100],b[100];
clrscr();
getch();
Sample Run:
enter the string
BIOINformatics$
the entered string is BIOINformatics
the letters in small letler is bioinformatics
Program:
char a[100];
int i,j,k,flag=1;
clrscr();
getch();
Sample run:
Program:
for(i=0;(a[i]=getchar())!='$';i++)
;
a[i]='\0';
for(i=0,j=0;i<n;j++,i++)
b[j]=a[i];
b[j]='\0';
Sample Run:
Aim:
Program:
for(i=0;(a[i]=getchar())!='$';i++);
a[i]='\0';
printf("Enter the number of characters to copy from the right:");
scanf("%d",&n);
for(i=i-n,j=0;a[i];j++,i++)
b[j]=a[i];
b[j]='\0';
Sample run:
Aim:
Program:
scanf("%d%d",&m,&n);
for(i=m-1,j=0;i<n;j++,i++)
b[j]=a[i];
b[j]='\0';
getch();
Sample run:
Aim:
Program:
#include<stdio.h>
main()
char a[100],b[100],c[100];
int i,j,k;
clrscr();
Sample run:
Program:
for(i=0;(a[i]=getchar())!='$';i++);
a[i]='\0';
for(i=0;a[i];i++)
{
if((a[i]==' '&&a[i+1]!=' ')||(a[i]=='\n'&&a[i+1]!='\n')||
(a[i]=='\t'&&a[i+1]!='\t'))
w++;
if(a[i]=='\n'&&a[i+1]!='\n')
l++;
if(a[i]!=' '&&a[i]!='\n'&&a[i]!='\t')
c++;
}
Sample run:
Aim:
Program:
/*Counting number of lower & upper case alphabets,digits & spl characters*/
#include<stdio.h>
main()
{
char a[100];
int i,alp=0,dig=0,spc=0;
clrscr();
printf("Enter the string:");
for(i=0;(a[i]=getchar())!='$';i++);
a[i]='\0';
for(i=0;a[i];i++)
{
if(a[i]==' '||a[i]=='\t'||a[i]=='\n')
continue;
if((a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z'))
alp++;
else
if(a[i]>='0'&&a[i]<='9')
dig++;
else
spc++;
}
Sample run:
Program:
*check the number of occurance of pattern*/
#include<stdio.h>
main()
{
char a[100],b[100];
int i,j,k,count=0;
clrscr();
printf("enter the charecters:\n");
for(i=0;(a[i]=getchar())!='$';i++)
;
a[i]='\0';
fflush(stdin);
Sample run:
Program:
for(i=0;(a[i]=getchar())!='$';i++)
;
a[i]='\0';
fflush(stdin);
Sample run:
Program:
{
int a[100],n,i,sum;
clrscr();
printf("how many values you want to enter\n\n");
scanf("%d",&n);
if(n>100)
{
printf("your n value is exceeding");
return;
}
printf("enter the elements\n\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("this is the array you had entered\n\n");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
printf("\n\nthe array in reverse order\n\n");
for(i=i-1;i>=0;i--)
printf("%d\t",a[i]);
for(i=sum;i+=sum;i++)
scanf("%d",&sum);
sum+=i;
printf("the sum of the digits are %d",sum);
getch();
}
Sample run:
Program:
{
int a[10],i;
clrscr();
printf("enter the elements\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\n this is the array numbers");
for(i=0;i<10;i++)
printf("%d\t",a[i]);
printf("\nthe array in reverse order is shown");
for(i=i-1;i>=0;i--)
printf("%d\t",a[i]);
getch();
}
Sample Run:
Program:
{
int a[100],n,i,sum=0;
clrscr();
printf("enter how many values you want to enter\n");
scanf("%d",&n);
printf("enter the elements of a array\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
printf("sum of %d elements is %d",n,sum);
getch();
}
Sample Run:
Program:
/*ascending order*/
#include<stdio.h>
main()
{
int a[100],n,i,j,temp=0;
clrscr();
printf("enter how many values you want to have\n");
scanf("%d",&n);
printf("enter the elements of array\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("the array elements are\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
printf("the array in ascending order format is\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
getch();
}
Sample Run:
Program:
{
int a[100],n,i,j,temp=0;
clrscr();
printf("enter the values you want to enter\n");
scanf("%d",&n);
printf("\nenter the array elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nthe elements of the array is\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]<a[j])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
printf("\nthe array in decending order is\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
getch();
}
Sample run:
Program:
scanf("%d",&a[i]);
printf("\nthe array elements are\n");
for(i=0;i<10;i++)
printf("%d\t",a[i]);
big=a[0];
for(i=1;i<10;i++)
if(a[i]>big)
big=a[i];
printf("\n the biggest of 10 integer is %d\n",big);
small=a[0];
for(i=1;i<10;i++)
if(a[i]<small)
small=a[i];
printf("\n the smallest of 10 integer is %d\n",small);
getch();
}
Sample run:
Program:
{
int a[10],i,big,small,x,y;
clrscr();
printf("enter the array elements\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\nthe array elements are\n");
for(i=0;i<10;i++)
printf("%d\t",a[i]);
big=a[0];
small=a[0];
for(i=1;i<10;i++)
{
if(a[i]>big)
{
big=a[i];
x=i;
}
}
printf("\nthe biggest of array is %d\n",big);
for(i=1;i<10;i++)
{
if(a[i]<small);
small=a[i];
y=i;
a[x]=small;
a[y]=big;
printf("%d\t",a[i]);
getch();
}
Sample Run:
enter the array elements
3241576980
the array elements are
3241576980
the biggest of array is 9
the smallest number is 0
the inter changed array is
3241576089
Aim:
To write a menu driven program.
Program:
/* menu driven program*/
#include<stdio.h>
main()
int a,b,c,option,i,fac=1;
clrscr();
sleep(3);
do
printf("******menu******\n\n");
printf("1.addition\n ");
printf("3.multiplication\n ");
printf("4.division\n ");
printf("5.modulation\n ");
printf("13.exit\n ");
printf("\n\nenter the option code of program\n ");
scanf("%d",&option);
switch(option)
{
case 1:
clrscr();
printf("enter the value of a,b");
scanf("%d%d",&a,&b);
c=a+b;
printf("the value of %d and %d is %d",a,b,c);
getch();
clrscr();
break;
case 2:
clrscr();
printf("enter the value of a,b");
scanf("%d%d",&a,&b);
c=a-b;
printf("the value of %d and %d is %d",a,b,c);
getch();
clrscr();
break;
case 3:
clrscr();
printf("enter the value of a,b");
scanf("%d%d",&a,&b);
c=a*b;
printf("the value of %d and %d is %d",a,b,c);
getch();
clrscr();
break;
case 4:
clrscr();
printf("enter the value of a,b");
scanf("%d%d",&a,&b);
c=a/b;
printf("the value of %d and %d is %d",a,b,c);
getch();
clrscr();
break;
case 5:
clrscr();
printf("enter the value of a,b");
scanf("%d%d",&a,&b);
c=a%b;
printf("the value of %d and %d is %d",a,b,c);
getch();
clrscr();
break;
case 6:
clrscr();
i=1;
printf("enter the number a to be reversed");
scanf("%d",&a);
while(i<=4)
{
b=a%10;
printf("%d",b);
a=a/10;
i++;
}
getch();
clrscr();
break;
case 7:
clrscr();
printf("enter the a value");
scanf("%d",&a);
while(a!=0)
{
b=a%10;
fac=fac*b;
a-=1;
}
case 8:
clrscr();
printf("enter the number to check");
scanf("%d",&a);
(a%2==0)?printf("the %d is the even number",a):printf("the %d
is the odd number",a);
break;
case 9:
clrscr();
printf("enter the year");
scanf("%d",&a);
(a%4==0)?printf("the %d is the leap year",a):printf("the %d is
a
ordinary year",a);
getch();
clrscr();
break;
case 10:
clrscr();
sum=0;
printf("enter the number");
sum=0;
scanf("%d",&a);
d=a;
while(a!=0)
{
b=a%10;
sum+=b;
a/=10;
}
case 12:
clrscr();
printf("enter the number");
scanf("%ld",&a);
while(fac<a)
{
b=a%fac;
if(b==0)
{
sum=sum+2;
}
fac++;
}
(sum==2||sum==0)?printf("%d is a prime
number",a):printf("%d is
a composite number",a);
getch();
clrscr();
break;
case 13:
clrscr();
exit();
clrscr();
break;
default:
printf("enter the correct case number\n\n");
break;
}
}while(option!=13);
getch();
}
Sample run:
******menu******
1. addition
2. subraction
3. multiplication
4. division
5. modulation
6. reverse the four digits
7. factorial value
8. odd or even
9. leap year
10. sum of the four digits
11. ascii value of coding
12. prime or composite
13. exit
enter the option code of program 6
enter the number a to be reversed 3456
6543
TERNARY OPERATORS
Aim:
To write program using ternary operator, to identify bigger of two numbers
Program:
/* ternary operators*/
#include<stdio.h>
main()
int a,b;
clrscr();
scanf("%d",&a);
scanf("%d",&b);
getch();
Sample run:
9 is bigger
TERNARY OPERATORS
Aim:
To write program using ternary operators to identify biggest among three numbers.
Program:
#include<stdio.h>
main()
int a,b,c;
clrscr();
scanf("%d%d%d",&a,&b,&c);
(a>b&&a>c)?printf("%d is biggest",a):(b>c)?printf("%d is
biggest",b):printf("%d is biggest",c);
getch();
Sample run:
enter the three numbers
5
3
7 is biggest
Aim
To write the program to print the single digit numbers in words
Program:
/*print all single digit numbers*/
#include<stdio.h>
main()
{
int num;
clrscr();
printf("enter the number option that you want in words");
scanf("%d",&num);
fflush(stdin);
switch(num)
Case 0:
Clrscr();
printf("%d -zero",num);
break;
case 1:
clrscr();
printf("%d - one",num);
break;
case 2:
clrscr();
printf("%d - two",num);
break;
case 3:
clrscr();
printf("%d - three",num);
break;
case 4:
clrscr();
printf("%d - four",num);
break;
case 5:
clrscr();
printf("%d - five",num);
break;
case 6:
clrscr();
printf("%d -six",num);
break;
case 7:
clrscr();
printf("%d - seven",num);
break;
case 8:
clrscr();
printf("%d - eight",num);
break;
case 9:
clrscr();
printf("%d - nine",num);
break;
default:
clrscr();
printf("the %d is invalid enter the single digit value",num);
}
getch();
}
Sample run:
7 - seven
Aim:
To write the program to print the tens in words
Program:
/* tens in words*/
#include<stdio.h>
main()
{
int num;
clrscr();
printf("\n\n\enter the tens value in numbers");
scanf("%d",&num);
switch(num)
{
case 10:
clrscr();
printf("%d - ten\n\n",num);
break;
case 20:
clrscr();
printf("%d - twenty\n\n",num);
break;
case 30:
clrscr();
printf(" %d - thirty\n\n",num);
break;
case 40:
clrscr();
printf("%d - fourty\n\n",num);
break;
case 50:
clrscr();
printf("%d - fifty\n\n",num);
break;
case 60:
clrscr();
printf("%d - sixty\n\n",num);
break;
case 70:
clrscr();
printf(" %d - seventy\n\n",num);
break;
case 80:
clrscr();
printf("%d - eighty\n \n",num);
break;
case 90:
clrscr();
printf("%d -ninety\n\n",num);
break;
default:
printf("%d is the invalid number\n\n",num);
break;
while(num);
getch();
}
Sample run:
Aim:
To write the program in C language to print the number in words
Program:
/*for the teen values*/
#include<stdio.h>
main()
{
int num;
clrscr();
printf("enter the num that you want in words");
scanf("%d",&num);
fflush(stdin);
switch(num)
case 11:
clrscr();
printf("%d - eleven",num);
break;
case 12:
clrscr();
printf("%d -twelve",num);
break;
case 13:
clrscr();
printf("%d - thirteen",num);
break;
case 14:
clrscr();
printf("%d - fourteen",num);
break;
case 15:
clrscr();
printf("%d - fifteen",num);
break;
case 16:
clrscr();
printf("%d - sixteen",num);
break;
case 17:
clrscr();
printf("%d - seventeen",num);
break;
case 18:
clrscr();
printf("%d - eighteen",num);
break;
case 19:
clrscr();
printf("%d - nineteen",num);
break;
default:
clrscr();
printf("enter the valid num");
break;
}
getch();
}
Sample run: