Вы находитесь на странице: 1из 12

C PROGRAMS #include<conio.

h>
void main()
1. Program to find sum of two numbers. {
#include<stdio.h> floatc,f;
#include<conio.h> clrscr();
void main() printf(“Enter temp in centigrade: ”);
{ scanf(“%f”,&c);
inta,b,s; f=(1.8*c)+32;
clrscr(); printf(“\nTemp in Fahrenheit=%f ”,f);
printf(“Enter two no:”); getch();
scanf(“%d%d",&a,&b); }
s=a+b; Output:
printf(“\nSum=%d”,s); Enter temp in centigrade: 32
getch(); Temp in Fahrenheit=89.59998
}
Output: 5. Program to calculate sum of 5 subjects and find
Enter two no: 5 6 percentage.
Sum=11 #include<stdio.h>
#include<conio.h>
2. Program to find area and circumference of void main()
circle. {
#include<stdio.h> ints1,s2,s3,s4,s5,sum,total=500;
#include<conio.h> float per;
void main() clrscr();
{ printf(“Enter marks of 5 subjects: ”);
int r; scanf(“%d%d%d%d%d”,&s1,&s2,&s3,
float pi=3.14,area,ci; &s4,&s5);
clrscr(); sum=s1+s2+s3+s4+s5;
printf(“Enter radius of circle: ”); printf(“\nSum=%d”,sum);
scanf(“%d”,&r); per=(sum*100)/total;
area=pi*r*r; printf(“\nPercentage=%f”,per);
printf(“\nArea of circle=%f ”,area); getch();
ci=2*pi*r; }
printf(“\nCircumference=%f ”,ci); Output: Enter marks of 5 subjects:
getch(); 6065506060
} Sum=300
Output: Percentage=60.000
Enter radius of a circle: 5
6. Program to show swap of two no’s without using
Area of circle=78.000
third variable.
Circumference=31.4
#include<stdio.h>
3. Program to find the simple interest. #include<conio.h>
#include<stdio.h> void main()
#include<conio.h> {
void main() inta,b;
{ clrscr();
intp,r,t,si; printf(“\nEnter value for a &b”);
clrscr(); scanf(“%d%d”,&a,&b);
printf(“Enter principle, Rate of interest a=a+b;
& time to find simple interest:”); b=a-b;
scanf(“%d%d%d”,&p,&r,&t); a=a-b;
si=(p*r*t)/100; printf(“\nAfter swapping the value of a
printf(“\nSimpleintrest= d”,si); & b: %d &%d”,a,b);
getch(); getch();
} }
Output: Enterprinciple, Output:
rateofinterest&timetofindsimpleinterest: 500 52 Enter value for a & b: 4 5
Simple interest=50 After swapping the value of a & b: 5 4

4. Program to convert temperature from degree 7. Program to reverse a given number.


centigrade to Fahrenheit. #include<stdio.h>
#include<stdio.h> #include<conio.h>
void main() void main()
{ {
intn,a,r=0; clrscr();
clrscr(); printf(“Enter value for a & b: \n”);
printf(“\nEnter any no to get its reverse: scanf(“%d%d”,&a,&b);
”); (a>b)?printf(“a is greater”):printf(“b is
scanf(“%d”,&n); greater”);
while(n>=1) getch();
{ }
a=n%10; Output:
r=r*10+a; Enter value for a & b: 5 7
n=n/10; b is greater
}
printf(“\nReverse=%d”,r); 11. Program to find that entered year is leap year or
getch(); not.
} #include<stdio.h>
Output: #include<conio.h>
Enter any no to get its reverse: 456 void main()
Reverse=654 {
int n;
8. Program to find gross salary. clrscr();
#include<stdio.h> printf(“Enter any year:”);
#include<conio.h> scanf(“%d”,&n);
void main() if(n%4==0)
{ printf(“\nYear is a leap
intgs,bs,da,ta; year”);
clrscr(); else
printf(“\nEnter basic salary: ”); printf(“\nYear is not a
scanf(“%d”,&bs); da=(10*bs)/100; leap year”);
ta=(12*bs)/100; getch();
gs=bs+da+ta; }
printf(“\nGross salary=%d”,gs); Output:
getch(); Enter any year: 1947
} Year is not a leap year
Output:
Enter basic salary: 100 12. Program to find whether given no. is even or odd.
Gross salary=122 #include<stdio.h>
#include<conio.h>
9. Program to find greatest in 3 numbers. void main()
#include<stdio.h> {
#include<conio.h> int n;
void main() clrscr();
{ printf(“Enter any no: ”);
inta,b,c; scanf(“%d”,&n);
clrscr(); if(n%2==0)
printf(“\nEnter value of a, b & c:); printf(“\nNo is even”);
scanf(“%d%d%d”,&a,&b,&c); else
if((a>b)&&(a>c)) printf(“\nNo is odd”);
printf(“a is greatest”); getch();
if((b>c)&&(b>a)) }
printf(“b is greatest”); Output:
if((c>a)&&(c>b)) Enter any no: 5
printf(“c is greatest”); No is odd
getch();
}
Output:
Enter value for a, b& c: 5 74 13. Program to shift inputed data by two bits
b is greatest to the left.
#include<stdio.h>
10. Program to show the use of conditional operator. #include<conio.h>
#include<stdio.h> void main()
#include<conio.h> {
intx,y; }
clrscr(); getch();
printf(“Read the integer from keyboard }
:- ”); Output:
scanf(“%d”,&x); Enter m for Monday t for Tuesdaywfor
x<<=3; Wednesday h for Thursdayf for Fridays for
y=x; Saturday u for Sunday: f Friday
printf(“\nThe left shifted data is = %d
”,y); 15. Program to display arithmetic operator using
getch(); switch case.
} #include<stdio.h>
Output: #include<conio.h>
Read the integer from keyboard: - 2 void main()
The left shifted data is = 16 {
inta,b,n,s,m,su,d; clrscr();
14. Program to use switch statement. Display printf(“Enter two no’s : ”);
Monday to Sunday. scanf(“%d%d”,&a,&b);
#include<stdio.h> printf(“\nEnter 1 for sum\n2 for
#include<conio.h> multiply\n3for subtraction\n4 for
void main() division: ”);
{
charch; scanf(“%d”,&n);
clrscr();
printf(“enter m for Monday\nt for switch(n)
Tuesday\nw for Wednesday\nh for {
Thursday\nf for Friday\ns for case 1: s=a+b;
Saturday\nu for Sunday); printf(“\nSum=%d”,s);
scanf(“%c”,&ch); break;
switch(ch) case 2: m=a*b;
{ printf(“\nMultiply=%d”,m);
case ‘m’: break;
case ‘M’: case 3: su=a-b;
printf(“Monday”); printf(“\nSubtraction=%d”,su);
break; break;
case ‘t’: case 4: d=a/b;
case ‘T’: printf(“\nDivission=%d”,d);
printf(“Tuesday”); break;
break; default:
case ‘w’: printf(“\nWrong input”);
case ‘W’: break;
printf(“Wednesday”); }
break; getch();
case ‘h’: }
case ‘H’: Output:
printf(“Thursday”); Enter two no’s: 8 4
break; Enter 1 for sum 2 for multiply 3 forsubtraction 4
case ‘f ’: for division:
case ‘F’: 1
printf(“Friday”); Sum=12
break;
case ‘s’:
case ‘S’:
printf(“Saturday”);
break;
case ‘u’: 16. Program to display first 10 natural no. &
case ‘U’: their sum.
printf(“Sunday”); #include<stdio.h>
break; #include<conio.h>
default : void main()
printf(“Wrong input”); {
break; inti,sum=0;
clrscr(); }
for(i=1;i<=10;i++) }
{ Output:
printf(“%d no is=%d\n”,i,I); *
sum=sum+i; **
} ***
printf(“Sum =%d”,sum); ****
getch();
} 19. Program to print starsSequence3.
Output: #include<stdio.h>
1 nois=1 #include<conio.h>
2 nois=2 void main()
3 nois=3 {
4 nois=4 inti, j, k;
5 nois=5 for(i=1;i<=5;i++)
6 nois=6 {
7 nois=7 for(j=i;j<5;j++)
8 nois=8 {
9 nois=9 printf(" ");
10 nois=10 }
Sum=55 for(k=1;k<(i*2);k++)
{
17. Program to print stars Sequence1: printf("*");
#include<stdio.h> }
#include<conio.h> printf("\n");
void main() }
{ }
inti, j; Output:
for(i=1;i<=5;i++) *
{ ***
for(j=1;j<=i;j++) *****
{ *******
printf("*"); *********
} 20. Program to print Fibonacci series up to 100.
printf("\n"); #include<stdio.h>
} #include<conio.h>
void main()
} {
Output: int a=1,b=1,c=0,i;
* clrscr();
** printf("%d\t%d\t",a,b);
*** for(i=0;i<=10;i++)
**** {
***** c=a+b;
18. Program to print stars Sequence2. if(c<100)
#include<stdio.h> {
#include<conio.h> printf("%d\t",c);
void main() }
{ a=b;
inti, j, k; b=c;
for(i=5;i>=1;i--) }
{ getch();
for(j=1;j<i;j++) }
{ Output: 1 1 2 3 5 8 13 21 34 55 89
printf(" ");
} 21. Program to find factorial of a number.
for(k=5;k>=i;k--) #include<stdio.h>
{ #include<conio.h>
printf("*"); void main()
} {
printf("\n"); intn,i,fact=1; clrscr();
printf(“Enter any no: ”); The sum of the given series is 2.08
scanf(“%d”,&n);
for(i=n;i>=1;i--) 24. Program to display series and find sum of
{ 1+3+5+……..+n.
fact=fact*i; #include<stdio.h>
} #include<conio.h>
printf(“\nFactorial=%d”,fact); getch(); void main()
} {
Output: intn,i,sum=0; clrscr();
Enter a no: 5 printf(“Enter any no: ”);
Factorial=120 scanf(“%d”,&n); for(i=1;i<n;i=i+2)
{
22. Program to find whether given no. is a printf(“%d+”,i); sum=sum+i;
prime no. or not. }
#include<stdio.h> printf("%d",n);
#include<conio.h> printf("\nSum=%d",sum+n);
void main() }
{ Output:
inti,n,r=0; clrscr(); Enter any no: 7
printf(“Enter any no: ”); 1+3+5+7
scanf(“%d”,&n); for(i=2;i<=n-1;i++) Sum=16
{
if(n%i==0) 25. Program to use bitwise AND operator between
r=1; the two integers.
#include<stdio.h>
break; #include<conio.h>
} void main()
if(r==0) {
printf(“\nPrime no”); inta,b,c;
else clrscr();
printf(“\nNot prime”); printf(“Read the integers from
getch(); keyboard:- ”);
} scanf(“%d %d”,&a,&b);
Output: c=a&b;
Enter any no: 16 printf(“\nThe Answer after ANDing is:
Not prime %d ”,c);
getch();
23. Program to display sum of series }
1+1/2+1/3+……….+1/n. Output:
#include<stdio.h> Read the integers from keyboard:- 8 4
#include<conio.h> The Answer after ANDing is: 0
void main()
{ 26. Program to add two number using pointers.
double number, sum = 0, i; #include<stdio.h>
printf("\n Enter the number "); #include<conio.h>
scanf("%lf", &number); void main()
for (i = 1; i <= number; i++) {
{ int *p1,*p2,sum; clrscr();
sum = sum + (1 / i); printf(“\nEnter two no’s: ”);
if (i == 1) scanf(“%d%d”,&*p1,&*p2);
printf("\n 1 +"); sum=*p1+*p2;
else if (i == number) printf(“\nSum=%d”,sum);
printf(" (1 / %lf)", i); getch();
else }
printf(" (1 / %lf) + ", i); Output:
} Enter two no’s: 10 20
printf("\n The sum of Sum=30
the given series is %.2lf", sum);
} 27. Program to show sum of 10 elements of
Output: array & show the average.
Enter the number 4 #include<stdio.h>
1 + (1/2.000000) + (1/3.000000) + (1/4.000000) #include<conio.h>
void main() scanf(“%d”,&a[i][j]);
{ }
int a[10],i,sum=0; printf(“\nEnter value for
floatav; b matrix: ”);
clrscr(); for(i=0;i<3;i++)
printf(“Enter elements of an aaray: ”); {
for(i=0;i<10;i++) for(j=0;j<2;j++)
scanf(“%d”,&a[i]); scanf(“%d”,&b[i][j]);
for(i=0;i<10;i++) }
sum=sum+a[i]; printf(“\na matrix
printf(“\nSum=%d”,su is\n\n”);
m); for(i=0;i<3;i++)
av=sum/10; {
for(j=0;j<2;j++)
printf(“\nAverage=%.2f”,av); {
getch(); printf(“ %d ”,a[i][j]);
} }
Output: printf(“\n”);
Enter elements of an array: }
1234567891 printf(“\nb matrix is\n\n”);
Sum=46 for(i=0;i<3;i++)
Average=4.66 {
for(j=0;j<2;j++)
28. Program to find the maximum no. in an {
array. printf(“ %d ”,b[i][j]);
#include<stdio.h> }
#include<conio.h> printf(“\n”);
void main() }
{ getch();
int a[5],max,i; }
clrscr(); 7 8 Output:
9 4 enter value for a matrix: 7 89456
5 6 enter value for b matrix: 3 2145 6
a matrix is
b matrix is 3 2
printf(“Enter element for the array: ”); 1 4
for(i=0;i<5;i++) 5 6
scanf(“%d”,&a[i]); 30. Program to find sum of two matrices.
max=a[0]; #include<stdio.h>
for(i=1;i<5;i++) #include<conio.h>
{ void main()
if(max<a[i]) {
max=a[i]; int a[3][2],b[3][2],c[3][2],i,j;
} clrscr();
printf(“\nMaximum no= %d”,max); printf(“Enter value for 1 matrix: ”);
getch(); for(i=0;i<3;i++)
} {
Output: for(j=0;j<2;j++)
Enter elements for array: 5 4712 scanf(“%d”,&a[i][j]);
Maximum no= 7 }
29. Program to display a matrix. printf(“Enter value for 2
#include<stdio.h> matrix: ”);
#include<conio.h> for(i=0;i<3;i++)
void main() {
{ for(j=0;j<2;j++)
inta[3][2],b[3][2],i,j; scanf(“%d”,&b[i][j]);
clrscr(); }
printf(“Enter value for a matrix: ”); for(i=0;i<3;i++)
for(i=0;i<3;i++) {
{ for(j=0;j<2;j++)
for(j=0;j<2;j++) c[i][j]=a[i][j]+b[i][j];
} {
printf(“Sum of matrix for(j=0;j<2;j++)
is\n”); scanf(“%d”,&b[i][j]);
for(i=0;i<3;i++) }
{ for(i=0;i<3;i++)
for(j=0;j<2;j++) {
{ for(j=0;j<2;j++)
printf(“%d\t”,c[i][j]); c[i][j]=a[i][j]*b[i][j];
} }
printf(“\n”); printf(“matrix is\n”);
} for(i=0;i<3;i++)
getch(); {
} for(j=0;j<2;j++)
Output: {
Enter value for 1 matrix: 123456 printf(“ %d ”,c[i][j]);
Enter value for 2 matrix: 456132 }
Sum of matrix is 57 printf(“\n”);
95 }
88 getch();
}
31. Program to find subtraction of two Output:
matrices. enter value for 1 matrix: 789456
#include<stdio.h> enter value for 2 matrix: 321256
#include<conio.h> matrix is 21 16
void main() 98
{ 25
int a[5],b[5],c[5],i; clrscr();
printf(“enter value for array a ”); 33.Program to find transpose of a matrix.
for(i=0;i<5;i++) #include<stdio.h>
scanf(“%d”,&a[i]); #include<conio.h>
printf(“enter value for array b void main()
”); {
for(i=0;i<5;i++) inta[3][2],b[2][3],i,j; clrscr();
scanf(“%d”,&b[i]); printf(“Enter value for matrix: ”);
for(i=0;i<5;i++) for(i=0;i<3;i++)
c[i]=a[i]-b[i]; {
printf(“subtraction”); for(j=0;j<2;j++)
for(i=0;i<5;i++) scanf(‘%d”,&a[i][j]);
printf(“ %d ”,c[i]); }
getch(); printf(“Matrix:\n”);
} for(i=0;i<3;i++)
Output: {
enter value for array a: 7 8945 for(j=0;j<2;j++)
enter value for array b: 4 5612 printf(“ %d ”,a[i][j]);
subtraction 3 3 3 3 3 printf(“\n”);
}
32. Program to find multiplication of two for(i=0;i<3;i++)
matrices. {
#include<stdio.h> for(j=0;j<2;j++)
#include<conio.h> b[j][i]=a[i][j];
void main() }
{ printf(“Transpose matrix:\n”);
int a[3][2],b[3][2],c[3][2],i,j; for(i=0;i<2;i++)
clrscr(); {
printf(“enter value for 1 matrix: ”); for(j=0;j<3;j++)
for(i=0;i<3;i++) printf(“ %d ”,b[i][j]);
{ printf(“\n”);
for(j=0;j<2;j++) }
scanf(“%d”,&a[i][j]); getch();
} }
printf(“enter value for 2 matrix: ”); Output:
for(i=0;i<3;i++)
Enter value for matrix: 4 56123 Output:
Matrix: 4 5 enter any no: 5 square is : 25
61
23 37. Program to swap two numbers using
Transpose matrix: 462 functions.
513 #include<stdio.h>
#include<conio.h>
34. Program to find the maximum number in void main()
array using pointer. {
#include<stdio.h> void swap(int,int);
#include<conio.h> inta,b,r;
void main() clrscr();
{ printf(“enter value for a&b: ”);
intmax,i,*a[5]; scanf(“%d%d”,&a,&b); swap(a,b);
clrscr(); getch();
printf(“enter element for the array: ”); }
for(i=0;i<5;i++) void swap(inta,int b)
scanf(“%d”,&*a[i]); max=*a[0]; {
for(i=1;i<5;i++) int temp;
{ temp=a;
if(max<*a[i]) max=*a[i]; a=b;
} b=temp;
printf(“maximum no= printf(“after swapping the value for a &
%d”,max); b is : %d %d”,a,b);
getch(); }
} Output:
Output: enter value for a&b: 4 5
enter elements for array: 5 4712 after swapping the value for a & b : 5 4
maximum no= 7
38. Program to find factorial of a number
35. Program to show input and output of a using functions.
string. #include<stdio.h>
#include<stdio.h> #include<conio.h>
#include<conio.h> void main() void main()
{ {
char a[50]; inta,f;
clrscr(); int fact(int);
printf(“enter any string: ”); clrscr();
gets(a); printf(“enter a no: ”);
puts(a); scanf(“%d”,&a); f=fact(a);
getch(); printf(“factorial= %d”,f);
} getch();
Output: }
enter any string: hi everyone hi everyone int fact(int x)
{
36. Program to find square of a number using intfac=1,i;
functions. for(i=x;i>=1;i--)
#include<stdio.h> fac=fac*i; return(fac);
#include<conio.h> }
void main() Output:
{ enter a no: 5 factorial=120
int rev(int); intr,a;
clrscr(); 39. Program to show table of a number using
printf(“enter any no: ”); functions.
scanf(“%d”,&a); r=rev(a); #include<stdio.h>
printf(“square is : %d”,r); #include<conio.h>
getch(); void main()
} {
int rev(int x) void table();
{ clrscr();
return(x*x); table();
} getch();
} printf(“value of a= %d & value of b=%d
void table() before swap”,a,b);
{ swap(aa,bb);
intn,i,r; printf(“\nvalue of a=%d & b=%d after
printf(“enter a no to know swap”,a,b);
table:”); getch();
scanf(“%d”,&n); }
for(i=1;i<=10;i++) int swap(int *x,int *y)
{ {
r=n*i; int temp;
printf(“%d*%d=%d\n”,n,i,r); temp=*x;
} *x=*y;
} *y=temp;
Output: }
enter a no to know table: 2 2*1=2 Output:
2*2=4 value of a= 5 & value of b=10 before swap value
2*3=6 of a=10 & b=5 after swap
2*4=8 42. Program to find largest of two numbers
2*5=10 using functions.
2*6=12 #include<stdio.h>
2*7=14 #include<conio.h>
2*8=16 void main()
2*9=18 {
2*10=20 void max();
40. Program to show call by value. clrscr();
#include<stdio.h> max();
#include<conio.h> getch();
void main() }
{ void max()
inta,b,swap(); {
clrscr(); int a[5],max,n,i;
a=5; b=10; printf(“How many no’s you
printf(”value of a=%d & value of b=%d want to enter: ”);
before swap ”,a,b); scanf(“%d”,&n);
swap(a,b); printf(“Enter element for the
printf(“\nvalue of a =%d & b=%d after array: ”);
swap”,a,b); for(i=0;i<n;i++)
getch(); scanf(“%d”,&a[i]);
} max=a[0];
int swap(intx,int y) for(i=1;i<5;i++)
{ {
int temp; if(max<a[i])
temp=x; max=a[i];
x=y; }
y=temp; printf(“maximum no=
} %d”,max);
Output: }
value of a=5 & value of b=10 before swap value Output:
of a=5 & b=10 after swap How many no’s you want to enter: 4 Enter element for
array: 4561
41. Program to show call by reference. maximum no: 6
#include<stdio.h>
#include<conio.h> 43. Program to find factorial of a number
void main() using recursion.
{ #include<stdio.h>
inta,b,*aa,*bb,swap(); #include<conio.h>
clrscr(); void main()
a=5; {
b=10; int n;
aa=&a; clrscr();
bb=&b; printf(“enter number:”);
scanf(“%d”,&n); fputc(c,fp);
if(n<0) c=fgetc(fp);
printf(“invalid number”); }
else fclose(fp);
printf(“%d!=%d”,n,fact(n)); fclose(fp1);
getch(); fp1=fopen(“tes.c”,”r”);
} c=fgetc(fp1);
int fact(int x) printf(“\nthe contents in file
{ 2\n”);
if(x==0) return1; while(c!=eof)
else {
return(x*fact(x-1)); putchar(c);
} c=fgetc(fp1);
Output: }
enter number: 5 fclose(fp1);
5!=120 getch();
}
44. Program to find whether a string is Output:
palindrome or not. enter the contents of file1(#-end) good morning#
#include<stdio.h> the contents of file2 good morning
#include<conio.h>
void main() 46. MergingOneDimensionalArray–
{ ExcludingtheRepeatingElement
char s1[20],s2[20]; #include<stdio.h>
clrscr(); #include<conio.h>
printf(“enter a string:”); void main()
scanf(“%s”,s1); strcpy(s2,s1); strrev(s2); {
if(strcmp(s1,s2)==0) inta[50],b[50],n1,n2,i,x;
printf(“string is a palindrome”); clrscr();
else printf(“enter the number of elements in
printf(“not a palindrome the first array”);
string”); scanf(“%d”,&n1);
getch(); printf(“enter the elements\n”);
} for(i=0;i<n1;i++)
Output: {
enter a string: abc printf(“enter a[%d]”,i+1);
not a palindrome string scanf(“%d”,&a[i]);
}
45. File Operations: printf(“enter the number of elements in
#include<stdio.h> the second array”);
#include<conio.h> scanf(“%d”,&n2);
void main() printf(“enter the elements\n”);
{ for(i=0;i<n2;i++)
file *fp,*fp1; {
char c; printf(“enter b[%d]”,i+1);
clrscr(); scanf(“%d”,&b[i]);
fp=fopen(“test.c”,”w”); }
printf(“\nenter the contents for for(x=0;x<n1;x++)
file1(#.end)\n”); {
c=getchar(); for(i=0;i<n2;i++)
while(c!=’#’) {
{ if(b[i]==a[x])
fputc(c,fp); {
c=getchar(); b[i]=’ ‘;
} }
rewind(fp); }
fp=fopen(“test.c”,”r”); }
for(i=o;i<n1;i++)
fp1=fopen(“tes.c”,”w”); {
c=fgetc(fp); printf(“%d”,a[i]);
while(c!=eof) }
{
for(i=0;i<n2;i++) }
{ Output:
if(b[i]==’ ‘;) continue; else Enter the statement
printf(“%d”,b[i]); *Nothing is impossible in the world. No.of
} words=6
getch(); No.of vowels=10 No.of consonants=19 No.of
} space=5
Output: No.of special characters=1
Enter the number of elements in the first array 3
Enter the elements 357 48. Write a program to create enumerated data type
Enter the number of elements in the first array 3 for 12 months. Display their values in
Enter the elements 259 integerconstants.
3 5 7 2 9 #include<stdio.h>
#include<conio.h>
47. Number of Occurrences of Vowels, void main()
Consonants, Words, Spaces and Special {
Characters inthe Given Statement. Enum month(Jan, Feb, Mar, Apr, May,
#include<stdio.h> June, July, Aug,Sep, Oct, Nov, Dec)
#include<conio.h> clrscr();
#include<stdlib.h> printf(“Jan=%d”, Jan);
#include<string.h> printf(“Feb=%d”, Feb);
#include<ctype.h> printf(“June=%d”, June);
void main() printf(“Dec=%d”, Dec);
{ }
char s[100]; Output:
intvow=0,cons=0,spc=0,punc=0,l,i; Jan =0 Feb=1 June=5 Dec=11
clrscr();
49. program to print the multiplication table from
printf(“enter the statement\n”);
gets(s); 1*1to12*10.
#include<stdio.h>
l=strlen(s);
#include<conio.h.>
for(i=0;i<l;i++)
#define COLMAX 10
{
#define ROWMAX 12
if(isalpha(s[i]))
void main()
{
{
if(s[i]==’a’||s[i]==’e’||s[i]==’i’||s
int row, column, y;
[i]==’o’||s[i]==’u’)
row=1;
{
printf(“MULTIPLICATION TABLE ”);
printf(“----------------------------------------
vow++;
”);
}
do
else
{
{
column=1;
cons++;
do
}
{
}
y=row*column;
if(isspace(s[i])
printf(“%d”, y);
{
column=column +1;
spc++;
}
}
while(column<=COLMAX);
if(ispunct(s[i]))
printf(“\n”);
{
row=row+1;
punc++;
}
}
while(row<=ROWMAX);
}
printf(“------------------------------
printf(“\nno.of words=%d”,spc+1);
---------------”)
printf(“\nno.of vowels=%d”,vow);
}
printf(“\nno.of consonants=%d”,cons);
printf(“\nno.of space=%d”,spc);
printf(“\nno.on special
characters=%d”,punc);
getch();
Output:
MULTIPLICATION TABLE
----------------------------------------------------------
---------------------------------

1 2 3 4 5 6 7 8 9 1 50. Program using error handling function.


0 #include <stdio.h>
#include <errno.h>
#include <string.h>
2 4 6 8 1 1 1 1 1 2 externinterrno ;
0 2 4 6 8 0 int main ()
{
3 6 9 1 1 1 2 2 2 3
2 5 8 1 4 7 0 FILE * pf;
interrnum;
pf = fopen ("unexist.txt", "rb");
4 8 1 1 2 2 2 3 3 4 if (pf == NULL)
2 6 0 4 8 2 6 0 {
errnum = errno;
5 1 1 2 2 3 3 4 4 5 fprintf(stderr, "Value of errno: %d\n",
0 5 0 5 0 5 0 5 0 errno);
perror("Error printed by perror");
fprintf(stderr, "Error opening file:
6 1 1 2 3 3 4 4 5 6 %s\n", strerror( errnum ));
2 8 4 0 6 2 8 4 0 }
else
7 1 2 2 3 4 4 5 6 7 {
4 1 8 5 2 9 6 3 0 fclose (pf);
}
return 0;
8 1 2 3 4 4 5 6 7 8 }
6 4 2 0 8 6 4 2 0 Output:
Value of errno: 2
Error printed by perror: No such file or directory
9 1 2 3 4 5 6 7 8 9 Error opening file: No such file or directory
8 7 6 5 4 3 2 1 0

1 2 3 4 5 6 7 8 9 1
0 0 0 0 0 0 0 0 0 0
0
1 2 3 4 5 6 7 8 9 1
1 2 3 4 5 6 7 8 9 1
0
1 2 3 4 6 7 8 9 1 1
2 4 6 8 0 2 4 6 0 2
8 0