0% found this document useful (0 votes)
2 views

C programs

The document is a comprehensive list of C programming exercises, covering a wide range of topics including arithmetic operations, control structures, string manipulation, and file handling. Each program is briefly described, indicating its purpose, such as calculating sums, checking for prime numbers, and manipulating arrays. The document serves as a resource for learners to practice and enhance their programming skills in C.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C programs

The document is a comprehensive list of C programming exercises, covering a wide range of topics including arithmetic operations, control structures, string manipulation, and file handling. Each program is briefly described, indicating its purpose, such as calculating sums, checking for prime numbers, and manipulating arrays. The document serves as a resource for learners to practice and enhance their programming skills in C.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

C programs of special characters

33. Program to accept any single digit number


and print it in words .
1. Program to print text 34. Program to print prime numbers between 1
2.Program To Read Two Numbers And Print to 100
The Sum Of Given Two Numbers. 35. Program to accept two numbers and print
3.Program To Accept Student Roll No, Marks sum of two numbers by using functions
in 3 Subjects and Calculate Total, Average and 36. Program to accept a number and find
Print it. factorial of given number
4.Program To Read Three Numbers And Print 37. Program to accept a number and check
The Biggest Of Given Three Numbers the given number Armstrong or not
5.Program To Read A Number And Find 38. Program to accept a number and print the
Whether The Given Number Is Even Or Odd. sum of given and Reverse number
6.Program to accept a year and check whether 39. Program to accept 10 numbers and print
the given year IS leap year or not. first five numbers in original order and print
7.Individual Digits last five numbers in reverse order.
8. Program to accept a three digit number and 40. Program to accept a string and print the
print the sum of individual digits. reverse of the given string by using for loop.
9. Program to accept a number and check the 41. Program to accept a string and check the
given number is Armstrong or not. given string is palindrome or not .
10. Program to print ODD numbers from 1 to 42.Program to accept values into 3
10 dimensional array and print .
11. Program to print natural numbers from 1 43. Program to print upper triangle .
to 10 in Reverse 44. Program to accept two 3 dimensional array
12. Program to print sum of the natural and store addition of those into arrays into the
numbers from 1 to 10. third array .
13. Program to accept a number and print 45. Program to accept a string and find the
mathematical table of the given no. length of the given string by using functions
14. Program to print 1 to 10 mathematical 46. Program to count the number of words,
tables . characters, alphabets, vowels, consonants and
15. Program to print fibonacci series . digit in a line of text.
16. Program to print numeric pyramid 47. Program to accept two string and
17. Program to print numerical pyramid. compare the strings are equal or not
18. Program to print numerical diamond. 48. Program to sort the entered numbers
19. Program to print character pyramid. using bubble sort.
20. Program to print character diamond. 49. Program to read date,month, year and print
21. Program to find biggest of two no by using the next day’s date,month,year.
ternary numbers 50. Program to interchange two values using
22. Program to find biggest of four no by using pointers.
ternary numbers 51. Program to print “PASCAL TRIANGLE”.
23. Program to print smallest of four no by 52. Program to check whether a given number
using ternary operators is perfect or not.
24. Program to accept a year and check the 53. Program to check whether a given number
given year is leap or not by using ternary is prime number.
25. Program to accept a character in the 54. Program to read ‘n’ number and print them
uppercase and print in lower case. in matrix terms in all orders.
26. Program to accept a character in any case 55. Program to search an element using binary
and print in another case. search
27. Program to natural number from 1 to 10 by 56. Program to accept two numbers and print
using while loop. the sum of given two numbers by using
28. Program to accept a string and print it by pointers
using the while loop. 57. Programs to multiply two Matrices
29. Program to accept a string in upper case 58. Program to print prime number between 1-
and print it by lower case. 100
30. Program to accept a string in any case and 59. Program to accept a string and find the
print it by another case . length of the string
31. Program to accept a string print each word 60. Program to fibanocci of matrix
in new line. 61. Program a structure which reads ‘n’
32. Program to accept a string and count no students information (name,3 subjects marks)
of capital letters, no. of small letters and no. and calculate total marks, result print them in
a particular format. third array..
62. Program to find whether a square matrix is 87.Program to accept a single dimensional
a) symmetric b) skew symmetric c) none of array and print them by using pointers
two. 88.Program to accept two strings and biggest
63. Program to find area of a triangle when among them
there sides are given. 89.Program to print 4 dimentional matrix with
64. Program to print Armstrong number constant number.
between 1-500. 90.Prongram to accept a string and print each
65. Program to check whether a given number word in reverse
is Armstrong or not. 91. Program to accept elements into single
66. Program to print the floyd’s triangle. dimensional array and print the array in
67. Program to read data in 3 structures and ascending order by using three different arrays.
print 92.Program to accept data and store the given
68. Program to print a diagonal matrix. data into file print the data.
69. Program to copy contents of one file into 93. Program to accept data in lower case and
another. store the given data into file into upper case
70. Program to create a file of number and and print the data.
copy odd number into second file and even 94.Program to copy contents of one file into
number into third file. another.
71. Program a structure which stores 95. Program to create a file of numbers and
information about hotels which stores copy odd number into second file and even
information about name, grade, room change, number into third file
no of rooms. 96.Program to accept a string in lower case
72. Program which does the below process and print first character of each word in upper
after reading on odd no of integer. case.
73. Program to sort the entered elements 97.Program to accept two numbers and
using selection sort technique. interchange two values using functions.
74. Program to find whether a number is 98.Program for example of static variable.
divisible by ‘11’ or not without actual division. 99.Program to accept a string and print by
75. Program to find maximum and minimum trailing spaces.
of entered ’n’ number using arrays. 100. Program to print anti diagonal.
76. Program to print the following series until
there sum exceeds 2.6 term value exceeds 1.5
x+x2/2!+x3/3!+------------.
77. Program to print a frequency distribution 1. Program to print text
table for a class of 20-students in the
following format. # include <stdio.h>
The marks range form 1-25. # include <conio.h>
78. Program to accept values into an array and main()
print array in reverse and original format by {
using three different functions. clrscr();
79. Program to accept values into single printf(“HELLO WELCOME TO
dimensional array and print the array in reverse VIDYARTHI COMPUTERS”);
by using pointers. printf(“Hanamkonda Warangal
80. Program to read a string and print the phone : 0870-2574900, 9849103344”);
number of characters in each word of the getch();
string. }
81. Program to accept two strings and Back
compare those two strings
82. Program to accept a string using pointers 2. Program To Read Two Numbers And Print
and functions. The Sum Of Given Two Numbers.
83.Program to read a string and print the first
two characters of each word in the string. # include <stdio.h>
84.Program to accept two numbers and print # include <conio.h>
the sum of given two numbers by using main()
pointers {
85.Program to accept a string and print int a,b, sum;
reverse of the given string by using functions. clrscr ();
86. Program to accept two 3 dimensional array printf (“ENTER VALUE FOR A ;
and store subtraction of those two arrays into “);
scanf (“%d”,&a); clrscr( );
printf(“ENTER VALUE FOR B printf(“ENTER VALUE FOR A:”);
;”); scanf(“%d”,&a);
scanf(“%d”,&b); printf(“ENTER VALUE FOR B:”);
sum=a+b; scanf(“%d”,&b);
printf(“Sum Of Given Two print(“ENTER VALUE FOR C:”);
Numbers are %d”, sum); scanf(“%d”,&c);
getch(); if (a>big)
} big=a ;
Back if(b>big)
big=b;
3. Program To Accept Student Roll No, Marks if (c>big)
in 3 Subjects and Calculate Total, Average big=c;
and Print it. printf (“BIGGEST OF ABOVE GIVEN
THREE NUMBER IS %d”,big)
# include <stdio.h> getch( );
# include <conio.h> }
main() Back
{
int r,b,c,d, tot, avg; 5. Program To Read A Number And Find
clrscr(); Whether The Given Number Is Even Or Odd.
printf (“ENTER STUDENT RNO
; “); # include <stdio.h>
scanf (“%d”,&r); # include <conio.h>
printf(“ENTER FIRST SUBJECT main()
MARKS ;”); {
scanf(“%d”,&b); int n,r;
printf(“ENTER SECOND clrscr();
SUBJECT MARKS;”); printf(“ENTER A NUMBER ;”);
scanf(“%d”,&c); scanf(“%d”, &n);
printf(“ENTER THIRD r=n%2;
SUBJECT MARKS ;”); if(r= = 0)
scanf(“%d”,&d); printf(“the above given number is even
tot=b+c+d; number”);
avg=tot/3; else
printf(“\n\n\t\t VIDYARTHI printf(“the above given number is odd
COMPUTERS – number”);
HANAMAKONDA \n\n”); getch();
printf(“\t STUDENT RNO ; %d }
“,r); Back
printf(“\t FIRST SUBJECT
MARKS ;%d “,b); 6. Program to accept a year and check
printf(“\t SECOND SUBJECT whether the given year IS leap year or not.
MARKS ;%d “,C);
printf(“\t THIRD SUBJECT # include <stdio.h>
MARKS ;%d “,d); # include <conio.h>
printf(“\t AVERAGE MARKS ; main( )
%d”, avg); {
getch(); int y;
} clrscr( );
Back printf(“enter a year:”);
scanf(“%d”,&y);
4. Program To Read Three Numbers And Print if(y%4==0& &y%100!=0|| y%400==0);
The Biggest Of Given Three Numbers printf(“the above given year IS a leap
year”);
# include <stdio.h> else
# include <conio.h> printf(“the above given year IS not a
main( ) leap year”);
{ getch();
int a,b,c,big=0; }
Back Armstrong number”);
7. Individual Digits else
printf (“The Given Number is Not
# include <stdio.h> Armstrong number”);
# include <conio.h> getch( );
main( ) }
{ Back
int a,b,c,d;
clrscr( ); 10. Program to print ODD numbers from 1 to
printf ( “ Enter a two digit number :”); 10
scanf (“ %d”, &a);
b=a/10; # include <stdio.h>
c=a%10; # include <conio.h>
d=b+c; main( )
printf (“sum of individual digits of {
given numbers id %”, d); int i;
getch( ); clrscr( );
} for (i=1; i<=10; i+=2)
Back printf(“%d\n”,i);
getch( );
8. Program to accept a three digit number and }
print the sum of individual digits. Back

# include <stdio.h> 11. Program to print natural numbers from 1


# include <conio.h> to 10 in Reverse
main( )
{ # include <stdio.h>
int a,b,c,n, sum; # include <conio.h>
clrscr( ); main( )
printf (“ Enter a Three Digit Number:“); {
scanf (“%d”,&n); int i;
a=n/100; clrscr( );
b=( (n%100)/10); for (i=10; i>=1; i--)
c=n%10; printf(“%d\n”,i);
sum=a+b+c; getch( );
printf (“ Sum of Individual Digits of }
Given Numbers is %d”, Sum); Back
getch( );
} 12. Program to print sum of the natural
numbers from 1 to 10.

Back # include <stdio.h>


# include <conio.h>
9. Program to accept a number and check the main( )
given number is Armstrong or not. {
int n,sum=0,i;
# include <stdio.h> clrscr( );
# include <conio.h> for (i=1; i<=10; i++)
main( ) sum=sum+i;
{ printf(“sum of natural numbers from 1
int n, a, b, c, d; to 10 is %d\n”,sum);
clrscr( ); getch( );
printf (“ Enter a Three Digit Number: “); }
scanf (“%d”, &n); Back
a=n/100;
b=((n/10)%10); 13. Program to accept a number and print
c=n%10; mathematical table of the given no.
d=a*a*a*+b*b*b +c*c*c;
if (n= =d) # include <stdio.h>
printf (“The Given Number is # include <conio.h>
main( ) printf(“%d”,j);
{ printf(“\n”);
int i,t; }
clrscr( ); getch();
printf(“which table u want:”); }
scanf(“%d”,&t); Back
for (i=1; i<=10; i++) 17. Program to print numerical pyramid.
printf(“\n%d*%d=%d”,t,i,i*t);
getch( ); # include <stdio.h>
} # include <conio.h>
Back main( )
{
14. Program to print 1 to 10 mathematical int i,j ,l,k=40;
tables . clrscr( );
for(i=1;i<=9;i+=2)
# include <stdio.h> {
# include <conio.h> for(l=1;l<=k;l++)
main( ) printf(“ “ );
{ for(j=1;j<=i;j++);
int i,j; printf(“%d”,j);
clrscr( ); printf(“\n”);
for (i=1; i<=10; i++) k=k-2;
for(j=1;j<=10;j++) }
printf(“\n%d*%d=%d”,i,j,i*j); getch( );
getch( ); }
} Back

Back 18. Program to print numerical diamond.


15. Program to print fibonacci series .
# include <stdio.h>
# include <stdio.h> # include <conio.h>
# include <conio.h> main( )
main( ) {
{ int i,j,l,n,s,k=40;
int a=0,b=1,c=0,i; clrscr( );
clrscr( ); for(i=1;i<=9;i+=2)
printf(“%d”,a); {
printf(“\n%d”,b); for(l=1;l<=k;l++)
for (i=1; i<=10; i++) printf(“ “);
{ for(j=1;j<=i;j++)
c=a+b; printf(“\n”);
printf(“\n%d”,c); k=k-2;
a=b; }
b=c; k=k+4;
} for(n=7;n>=1;n-=2)
getch( ); {
} for(i=1;i<=k;i++)
Back printf(“ “);
for(s=1;s<n;s++)
16. Program to print numeric pyramid printf(“%d”,s);
printf(“\n”);
# include <stdio.h> k=k+2;
# include <conio.h> }
main() getch( );
{ }
int i,j; Back
clrscr( );
for(i=1;i<=5;i++) 19. Program to print character pyramid.
{
for(j=1;j<=i;j++) # include <stdio.h>
# include <conio.h> printf(“biggest of the given numbers IS
main( ) %d”,big);
{ getch();
char i,j; }
clrscr(); Back
for(i=65;i<=70;i++)
{ 22. Program to find biggest of four no by
for(j=65;j<=i;j++) using ternary numbers
printf(“%c”,j);
printf(“\n”); # include <stdio.h>
} # include <conio.h>
getch( ); main( )
} {
Back int a,b,c,d,big;
clrscr( );
20. Program to print character diamond. printf(“enter value a”);
scanf(“%d”,&a);
# include <stdio.h> printf(“enter the value of b”);
# include <conio.h> scanf(“%d”,&b);
main( ) printf(“enter the value of c”);
{ scanf(“%d”,&c);
char i,j,n,r; printf(“enter the value of d”);
int s,sp=40; scanf(“%d”,&d);
clrscr( ); big=(a>b)?(a>c)?(a>d)?a:d:(c>d)?c:d:(b
for(i=65;i<=75;i+=2) >c)?(b>d)?b:d:(c>d)?c:d;
{ printf(“biggest of the given 4 numbers
for(s=1;s<=sp;s++) IS %d”,big);
printf(“ “); getch();
for(j=65;j<i;j++) }
printf(“%c”,j); Back
printf(“\n”);
sp=sp-2; 23. Program to print smallest of four no by
} using ternary operators
sp=sp+4;
for(n=73;n>=65;n-=2) # include <stdio.h>
{ # include <conio.h>
for(s=1;s<=sp;s++) main( )
printf(“ “); {
for(r=65;r<=n;r++) int a,b,c,d,small;
printf(“%c”,r); clrscr( );
sp=sp+2; printf(“enter value a”);
} scanf(“%d”,&a);
getch( ); printf(“enter the value of b”);
} scanf(“%d”,&b);
Back printf(“enter the value of c”);
scanf(“%d”,&c);
21. Program to find biggest of two no by printf(“enter the value of d”);
using ternary numbers scanf(“%d”,&d);
small=(a<b)?(a<c)?(a<d)?a:d:(c<d)?c:d:
# include <stdio.h> (b<c)?(b<d)?b:d:(c<d)?c:d;
# include <conio.h> printf(“biggest of the given 4 numbers
main( ) IS %d”,small);
{ getch();
int a,b,big; }
clrscr( ); Back
printf(“enter value a”);
scanf(“%d”,&a); 24. Program to accept a year and check the
printf(“enter the value of b”); given year is leap or not by using ternary
scanf(“%d”,&b);
big=(a>b)?a:b; # include <stdio.h>
# include <conio.h> 27. Program to natural number from 1 to 10
main( ) by using while loop.
{
int y,leap; # include <stdio.h>
clrscr( ); # include <conio.h>
printf(“enter any yr”); main( )
scanf(“%d”,&y); {
leap=(y%400= =0)?:(y%100!=0)?(y%4= int a=0;
=0)?1:0:0; clrscr();
if(leap= =1) while( a<10)
printf(“ the given year is leap year”); {
else a=a+1;
printf(“given year is not leap year); printf(“%d\n”,a);
getch( ); }
} getch();
Back }

25. Program to accept a character in the Back


uppercase and print in lower case.
28. Program to accept a string and print it by
# include <stdio.h> using the while loop.
# include <conio.h>
main( ) # include <stdio.h>
{ # include <conio.h>
char ch,c1; main( )
clrscr( ); {
printf(“enter a cha in uppercase”); char ch;
ch=getchar(); clrscr();
c1=ch+32; printf(“enter a string”);
printf(“the given char in while(( ch=getchar( ))!=’\n’)
lowercasecase is”); putchar(ch);
putchar(c1); getch();
getch(); }
} Back

Back 29. Program to accept a string in upper case


and print it by lower case.
26. Program to accept a character in any case
and print in another case. # include <stdio.h>
# include <conio.h>
# include <stdio.h> main( )
# include <conio.h> {
main( ) char ch,c;
{ clrscr();
char ch,c1; printf(“enter a string in upper case:”);
clrscr( ); while(( ch=getchar( ))!=’\n’)
printf(“enter a char in anycase”); {
ch=getchar(); c=ch+32;
if(ch>=65 && ch<=90) putchar(c);
c1=ch+32; }
else printf(“ is in lower case”);
if(ch>=97 && ch<=122) getch( );
c1=ch-32; }
printf(“the given char in anothercase Back
IS”);
putchar(c1); 30. Program to accept a string in any case
getch(); and print it by another case .
}
Back # include <stdio.h>
# include <conio.h>
main( ) s1=s1+1;
{ }
char ch; printf(“ no of capital letters are %d”,c);
clrscr( ); printf(“ no of smal1 letters are %d”,s);
printf(“enter a string :”); printf(“ no of special characters are
while(( ch=getchar( ))!=’\n’) %d”,s1);
{ getch( );
if(ch>=’A’ && ch<=’Z’) }
putchar(ch+32); Back
else
if(ch>=’a’ && ch<=’z’) 33. Program to accept any single digit
putchar(ch-32); number and print it in words .
else
putchar(ch); # include <stdio.h>
} # include <conio.h>
printf(“ is the string”); main( )
getch( ); {
} int n;
Back clrscr( );
printf(“enter a number :”);
31. Program to accept a string print each scanf(“%d “,&n);
word in new line. switch(n)
{
# include <stdio.h> case 0: printf(“ZERO”);
# include <conio.h> break;
main( ) case 1: printf(“ONE”);
{ break;
char ch; case 2: printf(“TWO”);
clrscr( ); break;
printf(“enter a string :”); case 3: printf(“THREE”);
while(( ch=getchar( ))!=’\n’) break;
{ case 4: printf(“FOUR”);
putchar(ch); break;
if(ch= =’ ‘) case 5: printf(“FIVE”);
printf(“\n”); break;
} case 6: printf(“SIX”);
getch( ); break;
} case 7: printf(“SEVEN”);
Back break;
case 8: printf(“EIGHT”);
32. Program to accept a string and count no break;
of capital letters, no. of small letters and no. case 9: printf(“NINE”);
of special characters break;
default:
# include <stdio.h> printf(“please enter the number
# include <conio.h> between 0 and 9”);
main( ) }
{ getch( );
char ch; }
int c=0,s=0,s1=0; Back
clrscr( );
printf(“enter a string :”); 34. Program to print prime numbers between
while(( ch=getchar( ))!=’\n’) 1 to 100
{
if(ch>=’A’&& ch>=’Z’) # include <stdio.h>
c=c+1; # include <conio.h>
else main( )
if(ch>=’a’&& ch>=’z’) {
s=s+1; int n, i, check;
else clrscr();
for(i=1;i<=100;i++) int fact(int n)
{ {
check=1; int i, fa=1;
for(n=2;n<=i/2;n++) for(i=n;i>=1;i--)
if(i%n= =0) fa=fa*i;
{ return fa;
check=0; }
break; Back
}
if(check= =1) 37. Program to accept a number and check
printf(“\n %d is a prime”,i); the given number Armstrong or not
else
printf(“\n %d is not a prime”,i); # include <stdio.h>
} # include <conio.h>
getch( ); main( )
} {
Back int n,arm;
clrscr();
35. Program to accept two numbers and print printf(“enter any 3 digit number:”)
sum of two numbers by using functions scanf(“%d”,&n);
arm= armstrong(n);
# include <stdio.h> if(arm= =n)
# include <conio.h> printf(“%d is Armstrong number”,n);
main( ) else
{ printf(“%d not a Armstrong number”,n);
int a,b,c; getch( );
clrscr(); }
printf(“enter the value for a:”)
scanf(“%d”,&a); int Armstrong (int n)
printf(“enter the value for b:”) {
scanf(“%d”,&b); int a,b,c,d;
c=add(a,b); a=n/100;
printf(“sum of two numbers is %d”,c); b=((n/10)%10);
getch( ); c=n%10;
} d=a*a*a+b*b*b+c*c*c;
return d;
int add(int x, int y) }
{ Back
int z;
z=x+y; 38. Program to accept a number and print the
return z; sum of given and Reverse number
}
Back # include <stdio.h>
# include <conio.h>
36. Program to accept a number and find main( )
factorial of given number {
int a,b,n;
# include <stdio.h>
# include <conio.h> clrscr( );
main( ) printf(“enter a number:”)
{ scanf(“%d”,&n);
int n,f; a=rev(n);
clrscr( ); printf(“REVERSE OF A GIVEN NUMBER
printf(“enter a number:”) IS %d”,a);
scanf(“%d”,&n); b=add(n,a);
f= fact(n); printf(“\n sum of a given and reverse
printf(“factorial value is %d”,f); number is %d”,b);
getch(); getch( );
} }
int rev( int n)
{
int r,rev=0,s; 41. Program to accept a string and check
while(n>0) the given string is palindrome or not .
{
r=n%10; # include <stdio.h>
rev=rev*10+r; # include <conio.h>
n=n/10; main( )
} {
return rev; int i,lim,c,check=1;
} char word[80];
int add(int n, int a) clrscr( );
{ printf(“ enter a string”);
return n+a; for(i=0;i<80 && ((word [i]=
} getchar())!=’\n’);i++);
Back lim=i-1;
c=lim/2;
39. Program to accept 10 numbers and print for(i=0;i<=0;i++,lim--)
first five numbers in original order and print if(word[i]!= word[lim])
last five numbers in reverse order. {
check=0;
# include <stdio.h> break;
# include <conio.h> }
main( ) if(check= =1)
{ printf(“the given string is palindrome “);
int i,a[10]; else
for(i=0;i<10;i++) printf(“ not palindrome”);
{ getch( );
printf(“enter value for a[%d]”,i); }
scanf(“%d”,&a[i]); Back
}
for(i=0;i<=4;i++) 42.Program to accept values into 3
printf(“\nA[%d]=%d”,i,a[i]); dimensional array and print .
for(i=9;i>=5;i--)
printf(“\nA[%d]=%d”,i,a[i]); # include <stdio.h>
getch( ); # include <conio.h>
} main( )
Back {
int a[3][3],i,j;
40. Program to accept a string and print the clrscr( );
reverse of the given string by using for loop. for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
# include <stdio.h> {
# include <conio.h> printf(“ enter the value for a[%d][%d]
main( ) :”,i,j);
{ scanf(“%d”,&a[i][j]);
int i,j; }
char name[80]; for(i=0;i<=2;i++)
clrscr( ); {
printf(“ enter a string”); for(j=0;j<=2;j++)
gets(name); printf(“ %d:”,a[i][j]);
for(i=0;i<80 && ((name [i]= printf(‘\n”);
getchar())!=’\n’);i++); }
if(name[i]= =’\n’) getch( );
name[i]=’\0’; }
for(j=i;j>=0;j--) Back
putchar(name[j]); 43. Program to print upper triangle .
printf(“is the reverse of given string”);
getch( ); # include <stdio.h>
} # include <conio.h>
Back main( )
{ int length;
int a[4][4],i,j,c; clrscr( );
clrscr( ); printf(“ enter a string”);
printf(“ enter which no u want”); length=getline(str);
scanf(“%d”,&c); printf(“length of the given string is
for(i=0;i<4;i++) %d”,length);
for(j=0;j<4;j++) getch ( );
if(i<j) }
a[i][j]=c; int getline(char str[])
else {
a[i][j]=0; int i;
for(i=0;i<4;i++) for(i=0;i<80&&((str[i]=getchar( ))!=’\n’);
for(j=0;j<4;j++) i++);
{ if(str[i]= =’\n’)
printf(“ %d:”,a[i][j]); str[i]=’\0’;
printf(‘\n”); return i;
} }
getch( ); Back
}
Back 46. Program to count the number of words,
characters, alphabets, vowels, consonants
44. Program to accept two 3 dimensional and digit in a line of text.
array and store addition of those into arrays
into the third array . #include<stdio.h>
#include<conio.h>
# include <stdio.h> main( )
# include <conio.h> {
main( ) int noa=0,nob=0,noc=0,nov=0,now=0,noch=0,l,I;
{ char ch,s[100];
int a[3][3],b[3][3],c[3][3],i,j; clrscr( );
clrscr( ); printf(“enter 2 lines of text”);
for(i=0;i<3;i++) gets(s);
for(j=0;j<3;j++) l=strlen(s);
{ for(i=0;i<1;i++)
printf(“enter the two values for {
a[%d][%d] & b[%d][%d]”, i,j,i,j); switch(s[i])
scanf(“%d%d”,&a[i][j],&b[i][j]); {
} case ‘a’:
for(i=0;i<3;i++) case ‘e’:
{ case ‘i’:
for(j=0;j<3;j++) case ‘o’:
{ case ‘u’:
c[i][j]=a[i][j]+b[i][j]; case ‘A’:
printf(“%d”,c[i][j]); case ‘E’:
} case ‘I’:
printf(“\n”); case ‘O’:
} case ‘U’:
getch( ); nov++;
} break;
Back }
if(isalpha(s[i]))
45. Program to accept a string and find the noa++;
length of the given string by using functions if(isdigit(s[i]))
nod++;
# include <stdio.h> if(noa[i]==’ ‘) && (noa[i+1]!=’ ‘)
# include <conio.h> now++;
int getline(char str[]); }
main( ) noch=l-nob;
{ noc=noa-nov;
char str[80]; printf(total no of words %d”,now);
printf(total no of characters(without using bubble sort.
blanks)%d”,noch);
printf(total no of characters(including # include <stdio.h>
blanks)%d”,l); # include <conio.h>
printf(total no of main( )
alphabets %d”,noa); {
printf(total no of vowels int a[100],i,j,n,t;
%d”,nov); clrscr( );
printf(total no of printf(“enter the array size”);
characters %d”,noc); scanf(“%d”,&n);
printf(total no of digits %d”,nod); for(i=1;i<n;i++)
getch( ); scanf(“%d”,&a[i]);
} for(i=1;i<=n;i++)
Back for(j=i+1;j<n;j++)
if(a[i]>a[j])
47. Program to accept two string and {
compare the strings are equal or not t=a[i]
a[i]=a[j];
# include <stdio.h> a[j]=t;
# include <conio.h> }
int getline (char line[ ], int lim ); printf(“the sorted elements are “);
int strc(char str1[ ], char str2[] ); for(i=1;i<=n;i++)
main( ) print(“%d”,a[i]);
{ getch( );
char str1[80],str2[80]; }
int comp; Back
clrscr( );
printf(“enter first string:”); 49. Program to read date,month, year and
getline(str1,80); print the next day’s date,month,year.
printf(“enter second string:”);
getline(str2,80); # include <stdio.h>
comp=strc(str1,str2); # include <conio.h>
if(comp>0) main( )
printf(“first string is bigger”); {
else int
if(comp==0) month[12]={31,28,31,30,31,30,31,31,30,
printf(“both the strings are equal”); 31,30,31};
getch( ); int d,m,y,nd,nm,ny,ndays;
} clrscr( );
printf(“enter the date,month,year”);
int getline(char str[], int lin) scanf(“%d%d%d”,&d,&m,&y);
{ ndays=month[m-1];
int i; if(m==2)
for(i=0;i<lin&&((str[i]=getchar())!=’\n’);i {
++); if(y%100==0)
if(str[i]=’\0’) {
return i; if(y%400==0)
} ndays=29;
}
int strc(char str1[],char str2[]) else
{ if(y%4==0)
int i; ndays=29;
for(i=0;str1[i];i++) }
if(str1[i]!=str2[i]) nd=nd+1;
return str1[i]-str2[i]; nm=m;
return str1[i]-str2[i]; ny=y;
} if(nd>ndays)
Back {
nd=1;
48. Program to sort the entered numbers nm++;
} printf(“%2d”,num);
if(nm>12) printf(“\n”);
{ }}
nm=1; getch( );
ny++; }
} Back
printf(“Given date is
%d:%d:%d\n”,d,m,y); 52. Program to check whether a given number
printf(“next days date is is perfect or not.
%d:%d:%d”,nd,nm,ny);
getch( ); # include <stdio.h>
} # include <conio.h>
Back main( )
{
50. Program to interchange two values using int i,n,s=0;
pointers. clrscr();
printf(“enter the number”);
# include <stdio.h> scanf(“%d”,&n);
# include <conio.h> for(i=1;i<n/2;i++)
void interchange(int *x,int *y); if(n%i==0)
main( ) s+=i;
{ if(s= =n)
int a,b; printf(“the number is perfect no”);
clrscr( ); else
printf(“enter values of a and b”); printf(“the number is not perfect “);
scanf(“%d%d”,&a,&b); getch( );
interchange(&a,&b); }
} Back
void interchange(x,y)
int *x,*y; 53. Program to check whether a given number
{ is prime number.
int t;
t=*x; # include <stdio.h>
*x=*y; # include <conio.h>
*y=t; main( )
printf(“%d=x, %d=y”,*x,*y); {
getch( ); int i,n,c=0;
} clrscr( );
Back printf(“enter a number”);
scanf(“%d”,&n);
51. Program to print “PASCAL TRIANGLE”. for(i=0;i<=n;i++)
if(n%i==0)
#include<stdio.h> c++;
#include<conio.h> if(c==2)
main() printf(“given number is a prime
{ number”);
int n,p=1,q,num,sp; else
clrscr( ); printf(“given number is not prime
printf(“enter the number of rows”); number”);
scanf(“%d”,&n); getch( );
for(p=0;p<=n;p++) }
{ Back
for(sp=1;sp<=40-(3*p);sp++)
printf(“ “); 54. Program to read ‘n’ number and print
for(q=0;q<n;q++) them in matrix terms in all orders.
{
if((q==q)||(q==0)) # include <stdio.h>
num=1; # include <conio.h>
else main( )
num=num*((q-q)+1)/q; {
int i,n,c,p,q,r,k,a[20]; printf(“elements is not in list”);
clrscr(); getch( );
printf(“enter the array size”); }
scanf(”%d”,&n); Back
printf(“enter the elements”);
for(i=1;i<=n;i++) 56. Program to accept two numbers and print
scanf(“%d”,&a[i]); the sum of given two numbers by using
i=1; pointers
while(i<=n)
{ # include <stdio.h>
if(n%i==0) # include <conio.h>
{ main( )
r=i; {
c=n/i; int a, b,c;
k=1; clrscr( );
for(p=1;p<=r;p++) a=10;
{ b=20;
for(q=1;q<=c;q++) c=*(&a)+*(&b);
printf(“%d”,a[k++]) printf(“%d”,c);
printf(“\n”); getch( );
} }
i++; Back
getch( );
} 57. Programs to multiply two Matrices
Back
# include <stdio.h>
55. Program to search an element using # include <conio.h>
binary search main( )
{
# include <stdio.h> int
# include <conio.h> a[10][10],b[10][10],c[10],[10],i,j,m,n,p,q,k;
main( ) clrscr( );
{ printf(“enter the size of first matrices”);
int a[100],i,n,x, mid, top, bot,c; scanf(“%d%d’,&m,&n);
clrscr(); printf(“enter the size of second
printf(“enter the array size;”); matrix”);
scanf(“%d”,&n); scanf(“%d%d’,&p,&q);
printf(“enter the array elements”); if(n==p)
for(i=1;i<=n;i++) {
scanf(“%d”,&a[i]); printf(“enter first matrices elements”);
top=1; for(i=1;i<m;i++)
bot=n; for(j=1;j<n;j++)
c=0; scanf(“%d”,&a[i][j]);
printf(“enter the element to searched”); printf(“enter second matrix elements”);
scanf(“%d”,&x); for(i=1;i<p;i++)
while((top <=bot)&&(c==0)) for(j=1;j<q;j++)
{ scanf(“%d”,&b[i][j]);
mid=(top+bot)/2; for(i=1;i<m;i++)
if(a[mid]<x) for(j=1;j<n;j++)
top=mid+1; {
else c[i][j]=0;
if(a[mid]>x) for(k=1;k<n;k++)
bot=mid-1; c[i][j]=c[i][j]+a[i][k]*b[k][j];
else }
c=1; printf(“the multiplication matrix is”);
} for(i=1;i<m;i++)
if(c==1) {
printf(“elements is at for(j=1;j<n;j++)
position;%d”,mid); print(“%2d”,c[i][j]);
else printf(“\n”);
} scanf(“%d%d”,&m,&n);
} printf(“enter the element of matrix”);
else for(i=1;i<=m;i++)
printf(“multiplication is not possible”); for(j=1;j<=n;j++)
getch( ); {
} scanf(“%d”,&a[i][j]);
sum=sum+(a[i][j]*a[i][j])
Back }
norm=sqrt(sum);
58. Program to print prime number between 1 printf(“norm=%f”,norm);
-100 getch( );
}
# include <stdio.h> Back
# include <conio.h>
main( ) 61. Program a structure which reads ‘n’
{ students information (name,3 subjects marks)
int i,n,c; and calculate total marks, result print them in
clrscr( ); a particular format.
for(n=1;n<=100;n++)
{ # include <stdio.h>
c=0; # include <conio.h>
for(i=1;i<=n;i++) main( )
if(n%i==0) {
c++; struct student
if(c==2) {
printf(“\n%d”,n); char name[20];
} int m1,m2,m3, tot;
getch( ); char result[10];
} }stud[10];
Back int i,n;
clrscr( );
59. Program to accept a string and find the printf(“enter no of students \n”);
length of the string scanf(“%d”,&n);
for(i=0;i<n;i++)
# include <stdio.h> {
# include <conio.h> printf(”enter %d student deatails \n”,i);
main( ) printf(”enter name\n”);
{ scanf(“%s”, stud[i].name);
char name[80]; printf(“enter marks of 3 subjects \n”);
int i; scanf(“%d%d%d”,
clrscr( ); &stud[i].m1,&stud[i].m2,&stud[i].m3);
printf(“enter a string ;”); stud[i].tot=stud[i].m1+stud[i].m2+stud[
for(i=0;i<80&&((name[i]=getchar( ))!=’\ i].m3;
n’);i++); if((stud[i].m1>35)&&(stud[i].m2>35)&&
printf(“%d is the size of string”,i); (stud[i].m3>35))
getch( ); strcpy(stud[i].result,”pass”);
} else
Back strtcpy(stud[i].result,”fail”);
}
60. Program to fibanocci of matrix clrscr( );
printf(“name total result
# include <stdio.h> \n”);
# include <conio.h> for(i=0;i<n;i++)
# include <math.h> {
main( ) printf(“%s %d %s \n”,
{ stud[i].name,stud[i].tot,stud[i].result);
int a[10][10],i,j,m,n sum=0; }
float norm; getch( );
clrscr( ); }
printf(‘enter the matrix size”); Back
else
62. Program to find whether a square matrix s=(a+b+c)/2;
is a) symmetric b) skew symmetric c) none of area=sqrt(s*(s-a)*(s-b)*(s-c));
two. printf(“area=%.2f”,area);
getch( );
# include <stdio.h> }
# include <conio.h> Back
main( )
{ 64. Program to print Armstrong number
int a[10][10],i,j,m,n,c=0,c1=0; between 1-500.
clrscr( );
printf(“enter the array size”); #include<stdio.h>
scanf(“%d”,&n); #include <conio.h>
printf(“enter the elements”); main( )
for(i=1;i<=m;i++) {
for(j=1;j<=n;j++) int i,n,s,r;
scanf(“%d”,&a[i][j]); clrscr( );
for(i=1;i<=m;i++) for(i=1;i<=500;i++)
for(j=1;j<=n;j++) {
{ n=i;
if(a[i][j]==a[j][i]) s=0;
c=1; while(n>0)
else {
if(a[i][j]==a[j][i]) r=n%10;
c1=1; s=s+(r*r*r);
} n=n/10;
printf(“the given matrix is \n”); }
for(i=1;i<=m;i++) if(i==s)
{ printf(“\n%d”,s);
for(j=1;j<=n;j++) }
printf(“%4d”,a[i][j]); getch();
printf(“\n”); }
} Back
if(c==0)
printf(“the given matrix is symmetric”); 65. Program to check whether a given number
else is Armstrong or not.
if(c1==0)
printf(“the matrix is skew symmetric”); # include <stdio.h>
else # include <conio.h>
printf(“none of two”); main( )
} {
getch( ); int i,n,s,r,k;
} clrscr( );
Back printf(“enter a number”);
scanf(“%d”,&n);
63. Program to find area of a triangle when k=n;
there sides are given. s=0;
while(n>0)
# include <stdio.h> {
# include <conio.h> r=n%10;
main( ) s=s+(r*r*r);
{ n=n/10;
int a,b,c; }
float s, area; if(k==s)
clrscr( ); printf(“given number is Armstrong
printf(“enter there sides of the %d”,k);
triangle”); else
scanf(“%d%d%d”,&a,&b,&c); printf(“given number is not Armstrong
if((a+b)<c||(b+c)<a||(a+c)<b) %d”,k);
printf(“finding area is not possible”); }
getch();
} 68. Program to print a diagonal matrix.
Back
#include<conio.h>
66. Program to print the floyd’s triangle. #include<stdio.h>
main()
# include <stdio.h> {
# include <conio.h> int a[4][4],i,j;
main( ) clrscr( );
{ for(i=0;i<4;i++)
int i,n,s,r k=1; for(j=0;j<4;j++)
clrscr( ); if(i==j)
printf(“enter a number of rows”); c[i][j]=7;
scanf(“%d”,&n); else
for(i=1;i<=n;i++) a[i][j]=0;
{ for(i=0;i<4;i++)
for(s=1;s<=40-i;s++) {
printf(“ ”); for(j=0;j<4;j++)
for(j=1;j<=i;j++) printf(“%d”,a[i][j]);
printf(“%3d”,k++); printf(“\n”);
printf(“\n”); }
} getch();
getch( ); }
} Back
Back
69. Program to copy contents of one file into
67. Program to read data in 3 structures and another.
print
#include<stdio.h>
# include<stdio.h> #include<conio.h>
# include<conio.h> main( )
{
main( ) FILE *fp1,*fp2;
{ char ch;
struct book fp1=fopen(“text1”,”w”);
{ printf(‘enter the text”);
char code; while((ch=getchar( ))!=EOF)
int piece; putc(ch,fp1);
float price; fclose(fp1);
}; fp1=fopen(“text1”,”r”);
struct book b1,b2,b3; fp2=fopen(“text2”,”w”);
main( ) while((ch=getc(fp1))!=EOF)
{ putc(ch,fp2);
clrscr( ); fclose(fp2);
printf(“enter code,piece,price”); getch( );
scanf(“%c%d%f”,&b1.code,&b1.piece,&b1.price) }
; Back
printf(“enter code,piece,price”);
scanf(“%c%d%f”,&b2.code,&b2.piece,&b2.price) 70. Program to create a file of number and
; copy odd number into second file and even
printf(“enter code,piece,price”); number into third file.
scanf(“%c%d%f”,&b3.code,&b3.piece,&b3.price)
; #include<stdio.h>
printf(“the details are”); #include<conio.h>
printf(“\n %c%d%f”,b1.code,b1.piece,b1.price); main( )
printf(“\n %c%d%f”,b2.code,b2.piece,b2.price); {
printf(“\n %c%d%f”,b3.code,b3.piece,b3.price); FILE *fp1,*fp2,*fp3;
getch( ); int i;
} fp1=fopen(“DATA1”,”w”);
Back printf(“enter the number”);
scanf(“%d”,&i); printf(“enter no of rooms \n”);
while(i!=eof( )) scanf(“%d”,&ht[i].nr);
{ }
putw(i,fp1); for(i=0;i<n;i++)
} for(j=0;j<n-i;j++)
fcolse(fp1); {
fp1=fopen(“DATA1”,”r”); t=ht[j];
fp2=fopen(“DATA2”,”w”); ht[j]=ht[j+i];
fp3=fopen(“DATA3”,”w”); ht[j+1]=t;
while((i=getw(fp1))!=EOF()) }
if(i%2= =0) printf(“enter a grade to print the hotels
putw(i,fp3); \n”);
else gr=getche();
putw(i,fp2); clrscr();
fcolse(fp1); printf(“hotel name city grade
fcolse(fp2); roomcharge no of room”);
fcolse(fp3); for(i=0;i<n;i++)
getch( ); if(gr==ht[i].grade)
} printf(“%s %s %c %d %d”,ht[i].name,h
Back t[i].city,ht[i].grade,ht[i].rc,ht[i].nr);
getch();
71. Program a structure which stores printf(“enter a room charge to print
information about hotels which stores hotels less than given charge \n”);
information about name, grade, room change, scanf(“%d”,&c);
no of rooms. printf(“hotel name city grade
a) a) Print the hotels of roomcharge no of rooms”);
given grade in order of for(i=0;i<n;i++)
roomchange. if(c<=ht[i].rc)
b) b) Print the hotels with printf(“%s %s %c %d %d”,ht[i].name,
roomchange less than a given ht[i].city,h[i].grade,ht[i].rc,ht[i].nr);
change. }

#include<stdio.h> Back
#include<conio.h>
main( ) 72. Program which does the below process
{ after reading on odd no of integer.
struct hotel a) a) Print them in given order.
{ b) b) Replace second elements by
char name[20]; product of first and last element
char city[10]; c) c) Replace middle value by average
char grade; of all elements.
int rc,nr; d) d) Replace all –ve no’s by zero’s.
};
struct hotel ht[20],t; #include<stdio.h>
int i,n,j,c; #include<conio.h>
char gr; main( )
clrscr( ); {
printf(“enter no. of hotels\n”); int a[10],i,n,sum=0;
scanf(“%d”,&n); clrscr( );
for(i=0;i<n;i++) printf(“enter the array sixe “);
{ scanf(“%d”,&n);
printf(“enter name of hotel \n”); printf(“enter the elements”);
scanf(“%s”,&ht[i].name); for(i=0;i<n;i++)
printf(“enter name of city \n”); {
scanf(“%s”,&ht[i].city); scanf(“%d”,&a[i]);
printf(“enter the grade \n”); sum=sum+a[i];
scanf(“%s”.ht[i].grade); }
ht[i].grade=getche( ); printf(“The given arrays is: “);
printf(“enter room charge \n”); for(i=0;i<n;i++)
scanf(“%d”,&ht[i].rc); printf(“%d”,a[i]);
a[2]=a[1]*a[n-1]; #include<conio.h>
printf(“\n the given areay after #include<math.h>
replacing 2nd element is”); main( )
for(i=0;i<n;i++) {
printf(“%d”,a[i]); int a,b,n,evensum=0,oddsum=0,div;
a[(1+n/2)]=sum/n; clrscr( );
printf(“\n the given array after printf(“enter a number”);
replacing middle element by average scanf(“%d”,&n);
of all”); a=n;
for(i=0;i<n;i++) b=n/10;
if(a[i]<0) while(a>0)
a[i]=0; {
printf(“\n given array after replacing oddsum=oddsum+(a%10);
–ve values by zero”); a=a/10;
for(i=0;i<n;i++) }
printf(“%d”,a[i]); while(b>0)
printf(“\n”); {
getch(); evensum=evensum+(b%10);
} b=b/10;
Back }
div=abs(evensum-oddsum);
73. Program to sort the entered elements if(div%11==0)
using selection sort technique. printf(“The number is divisible by 11”);
else
#include<stdio.h> printf(“The number is not divisible by
#include<conio.h> 11”);
main( ) getch();
{ }
int a[100],i,n,j,t,min,pos; Back
clrscr();
printf(“enter the array size”); 75. Program to find maximum and
scanf(“%d”,&n); minimum of entered ’n’ number using
printf(“enter the elements”); arrays.
for(i=0;i<n;i++)
scanf(“%d”,&a[i]); #include<stdio.h>
for(i=0;i<n;i++) #include<conio.h>
{ main( )
min=a[i]; {
pos=i; int i,n,a[10],min,max;
for(j=0;j<n-1;j++) clrscr( );
if(min>a[j]) printf(“ enter how many number”);
{ scanf(“%d”,&n);
min=j; printf(“enter the elements”);
pos=j; for(i=0;i<n;i++)
} scanf(”%d”,&a[i]);
t=a[i]; min=a[0];
a[i]=a[pos]; for(i=0;i<n;i++)
a[pos]=t; if(min>a[i])
} min=a[i];
printf(“the sorted elements are”); printf(“minimum=%d”,min);
for(i=0;i<n;i++) max=0;
printf(“%2d”,a[i]); for(i=0;i<n;i++)
getch( ); if(max<a[i]);
} max=a[i];
Back printf(“\n maximum=%d”,max);
getch( );
74. Program to find whether a number is }
divisible by ‘11’ or not without actual division. Back

#include<stdio.h> 76. Program to print the following series


until there sum exceeds 2.6 term value
exceeds 1.5 #include<stdio.h>
x+x2/2!+x3/3!+------------. #include<conio.h>
main( )
#include<stdio.h> {
#include<conio.h> int a[20],i,n1=0,n2=0,n3=0,n4=0,n5=0;
main( ) clrscr();
{ printf(“enter the any 20 no of range(1-
float x,sum=0,prod=1; 25));
int i; for(i=1;i<=20;i++)
clrscr( ); scanf(“%d”,&a[i]);
printf(“enter x value”); for(i=1;i<=20;i++)
scanf(“%f’,&x); if((a[i]>=1)&&(a[i]<6))
i=1; n1++;
while((sum<2.6)&&(prod<=1.5)) else
{ if((a[i]>5)&&(a[i]<11))
prod=prod*(x/i); n2++;
if(prod<=1.5) else
sum=sum+prod; if((a[i]>10)&&(a[i]<16))
if(sum>2.6) n3++;
{ else
sum=sum-prod; if((a[i]>15)&&(a[i]<21))
break; n4++;
} else
printf(“sum=;%f’,sum); if((a[i]>20)&&(a[i]<26))
i++; n5++;
} printf(“class interval frequency”);
getch( ); printf(“\n 1-5 %d”,n1);
} printf(“\n 6-10 %d”,n2);
Back printf(“\n 11-15 %d”,n3);
printf(“\n 16-20 %d”,n4);
77. Program to print a frequency printf(“\n 21-25 %d”,n5);
distribution table for a class of 20- getch();
students in the following format. }
The marks range form 1-25. Back
class intertval frequency
1-5 1- 78. Program to accept values into an array and
5 print array in reverse and original format by
using three different functions.

- #include<stdio.h>
6-10 6- #include<conio.h>
10 void read_array(int x[]);
void print_array(int y[]);
void rev_array(int z[]);
- main()
11-15 11- {
15 int a[5];
clrscr();
- read_array(a);
16-20 16- printf_array(a);
20 rev_array(a);
getch( );
}
- void read_array(int x[])
21-25 21- {
25 int i;
for(i=0;i<=4;i++)
{
- printf(“enter values for a[%d]:”,i);
scanf(“%d”,&x[i]); for(i=0;i<l;i++)
} {
} if(s[i]!=’ ‘)
void print_array(int y[]) {
{ nc=0;
int i; while(s[i]!=’ ‘)
for(i=0;i<=4;i++) {
printf(“%d”,y[i]); nc++;
} printf(“%c”,s[i]);
void rev_array(int z[]) i++;
{ if(s[i]=’\0’)
int i; break;
for(i=4;i>=0;i--) }
printf(“\n%d”,z[i]); printf(“\t\t %d”,nc);
} printf(“\n”);
Back }
}
79. Program to accept values into single getch();
dimensional array and print the array in }
reverse by using pointers. Back

#include<stdio.h> 81. Program to accept two strings and


#include<conio.h> compare those two strings
main( )
{ #include<stdio.h>
int a[5],*b,i; #include<conio.h>
clrscr( ); int strcomp (char *pt1, char *pt2);
b=&a[0]; void read-string(char*pt);
for(i=0;i<=4;i++)
{ main( )
printf(“enter a value for a[%d];”.i); {
scanf(“%d”,b); char line [80],line2[80];
b++; clrscr( );
} printf(“enter first string;”);
b=&a[4]; read-string (line1);
for(i=0;i<=4;i++) printf(“enter second string”);
{ read-string(line2);
printf(“\n%d”,*b); if(strcomp (line1,line2)>0)
b-- ; printf(“second string biggest”);
} else
getch( ); if(strcomp (line1,line2)>0)
} printf(“ first string biggest;”);
Back else
printf(“both the strins are equal”);
80. Program to read a string and print the getch( );
number of characters in each word of the }
string. void read-string(char*pt)
{
for(;(*pt=getchar( ))!=’\n’;pt++);
#include<stdio.h> *pt=’\0’;
#include<conio.h> }
#include<string.h> int strcomp (char *pt1, char *pt2)
main( ) {
{ for(;*pt1!=’\0’;pt1++;pt2++)
char s[100]; if(*pt1!=*pt2)
int i,l,nc=0; break;
clrscr( ); return *pt1-*pt2;
printf(“enter the sting”); }
gets(s); Back
l=strlen(s);
82. Program to accept a string using
pointers and functions.

#include<stdio.h>
#include<conio.h>
main( ) 85.Program to accept a string and print
{ reverse of the given string by using functions.
int ch[20];
clrscr ( ); #include<stdio.h>
printf(“enter a string”); #include<stdio.h>
read_array(ch); int getline (char str[]);
printf(“%s”,ch); void printline (char str[],int i);
getch( ); main( )
} {
void read_string (char*pt) char str[80];
{ int 1;
for(;(*pt=getchar( ))!=’/n’;pt++); clrscr( );
*pt=’\0’; 1=getline(str );
} printline(str,1);
Back printline(str,1);
getch ( );
83.Program to read a string and print the first }
two characters of each word in the string. int getline(char str[])
{
#include<stdio.h> int 1;
#include<conio.h> printf(“enter a string;”);
main( ) for(i=0;i<80&&((str[i]=getchar())!=’\n’);i++);
{ if(str[i]=’\0’;
char s[100]; return i;
int i,l; }
clrscr( ); void printline(char str[],int 1)
printf(“enter a string”); {
gets(s);l=strlen(s); int j;
for(i=0;i<l;i++) for(j=1;j<=0;j--)
{ printf(“%c”,str[j]);
if(s[i]!=’ ‘ && s[i]=’ ‘) printf(‘is the revefrse string”);
{ }
printf(“%c %c”,s[i],s[i+1]) Back
i=i+2;
while(s[i]!=’ ‘) 86. Program to accept two 3 dimensional
i++; array and store subtraction of those two
} arrays into third array..
} #include<stdio.h>
getch( ); #include<conio.h>
} main( )
Back {
int a[3][3],b[3][3],c[3][3],i,j;
84.Program to accept two numbers and print clrscr( );
the sum of given two numbers by using for(i=0;i<3;i++)
pointers for(j=0;j<3;j++)
{
#include<stdio.h> printf(“enter two values for a[%d][%d] &
#include<conio.h> b[%d][%d]:”,i,j,i,j);
main( ) scanf(“%d%d”,&a[i][j],&b[i][j]);
{ }
int a, b,c; for(i=0;i<3;i++)
clrscr( ); {
a=10; for(j=0;j<3;j++)
b=20; {
c=*(&a)+*(&b); c[i][j]=a[i][j]-b[i][j];
printf(“%d”,c); printf(“%d”,,c[i][j]);
getch( ); }
} printf(“\n”);
Back }
getch( );
return i;
Back }
Back
87.Program to accept a single dimensional
array and print them by using pointers 89.Program to print 4 dimentional matrix with
constant number.
#include<stdio.h>
#include<conio.h> #include<stdio.h>
#include<conio.h>
main( ) main( )
{ {
int a[5],*b,i; int a[4][4],i,j,c;
clrscr( ); clrscr( );
b=&a[0]; printf(“enter constant number”);
for(i=0;i<=4;i++) scanf(“%d”,&c);
{ for(i=0;i<4;i++)
printf(“enter the a value for a[%d]”,i) {
scanf(“%d”,b); for(j=0;j<4;j++)
b++; a[i][j]=c;
} for(i=0;i<4;i++)
b=&a[0]; {
for(i=0;i<=4;i++) for(j=0;j<4;j++)
{ printf(“%d”,a[i][j]);
printf(“\n%d”,*b); printf(“\n”);
b++; }
} getch( );
getch( ); }
} Back
Back
90.Prongram to accept a string and print each
88.Program to accept two strings and biggest word in reverse
among them
#include<conio.h>
#include<stdio.h> #include<stdio.h>
#include<conio.h> main( )
int getline(char line[],int lim); {
main( ) char name[80];
{ int i,j,start=0,end,len;
char str1[80],str2[80]; clrscr( );
int len1,len2; printf(“enter a string”);
clrscr( ); scanf(“%s”,name);
printf(“enter first string”); for(i=0;i<80 &&((name[i]=getchar( ) )!=’\n’);i++);
len1=getline(str1,80); len=i;
printf(“enter second string”); for(i=0;i<len;i++)
len2=getline(str1,80); if(name[i]==’ ‘|| name[i]==’\n’)
if(len1 >len2) {
printf(“first string bigger than second string”); end=i;
else while((end--)>=start)
if(len1<len2) {
printf(“second string bigger than first string”); printf(“%c”,name[end]);
else }
printf(“both strings are equal”); start=i+1;
getch( ); }
} getch( );
int getline(char line[],int lim) }
{ Back
int i;
for(Ii0;i<lim && ((line[i]=getchar( ))!=’\n’);i++) 91. Program to accept elements into single
if(line[i]==’\n’) dimensional array and print the array in
line[i]=’\0’; ascending order by using three different
arrays. if(c==eof( ))
break;
#include<conio.h> putc(c);
#include<stdio.h> }
void read_array(int x[]); fclose(fp);
void sort_array(int y[]); fp=fopen(“data.dat”,”r”);
void print_array(int z[]); while(1)
main() {
{ c=getc(fp);
int a[10]; if(c==eof( ))
clrscr( ); break;
read_array(a); putchar(c);
sort_array(a); }
print_array(a); getch( );
getch( ); fclose(fp);
} }
void read_array(int x[]) Back
{
int i; 93. Program to accept data in lower case and
for(i=0;i<10;i++) store the given data into file into upper case
{ and print the data.
printf(“enter value for a[%d]”,i);
scanf(“%d”,&x[i]); #include<conio.h>
} #include<stdio.h>
} main( )
void sort_array(int y[]) {
{ FILE *fp;
int i,j,k; Char c;
for(i=0;i<9;i++) fp=fopen(“data2.dat”,”w”);
for(j=i+1;j<=9;j++) clrscr( );
if(y[i]>y[j]) printf(“enter text”);
{ while((c=getchar( ))!=eof( ))
k=y[i]; {
y[i]=y[j]; putc(toupper(c),fp)
y[j]=k; }
} fclose(fp);
} fp=fopen(“data2.dat”,”r”);
void print_array(int z[]) while(1)
{ {
int i; c=getc(fp);
for(i=0;i<10;i++) if(c==eof( ))
printf(“%d\n”,z[i]); break;
} putchar(c);
Back }
getch( );
92.Program to accept data and store the fclose(fp);
given data into file print the data. }
Back
#include<conio.h>
#include<stdio.h> 94.Program to copy contents of one file into
main( ) another.
{
FILE *fp; #include<conio.h>
char c; #include<stdio.h>
fp=fopen(“data.dat”,”w”); main( )
clrscr(); {
printf(“enter text”); FILE * fp1,*fp2;
while(1) char ch;
{ fp1=fopen(“text1”,”w”);
c=getchar( ); printf(“enter the text”);
while((ch=getchar()!=EOF); for(i=0;i<length;i++)
putc(ch,fp1); {
fclose(fp1); str1[0]-=32;
fp1=fopen(“text1”,”r”); if(str1[i]= =’ ‘)
fp2=fopen(“text2”,”w”); str1[i+1]-=32;
while((ch=getc(fp1))!=EOF) printf(“%c”.str1[i]);
putc(ch,fp2); }
fcolse(fp1); getch();
fcolse(fp2); }
getch( ); int getline(char line [], int lim)
} {
Back int i;
for(i=0;i<lim &&
95. Program to create a file of numbers and ((line[i]=getchar( ))!=’\n’);i++);
copy odd number into second file and even if(line[i]= =’\n’)
number into third file line[i]=’\0’;
return i;
#include<conio.h> }
#include<stdio.h> Back
main( )
{ 97.Program to accept two numbers and
FILE *fp1,*fp2,*fp3; interchange two values using functions.
int i;
fp1=open(“data1”,w”); #include<conio.h>
printf(“enter the number”); #include<stdio.h>
scanf(“%d”,&i); void swap (int a, int b);
while(i!=eof) main( )
{ {
putw(i,fp1); int a,b;
scanf(“%d”,&i); clrscr( );
} printf(“enter value for a;”);
fcolse(fp1); scanf(“%d”,&a);
fp1=fopen(“data1”,”r”); printf(“enter value for b;”);
fp2=fopen(“data2”,”w”); scanf(“%d”,&b);
fp3=fopen(“data3”,”w”); swap(a,b);
while((i=getc(fp1))!=eof) getch( );
if(i%2==0) }
putc(i,fp3); void swap(int a,int b)
else }
putw(i,fp2); int c;
fcolse(fp1); c=a;
fcolse(fp2); a=b;
fcolse(fp3); b=c;
getch( ); printf(“\na=%d”,a);
} printf(“\nb=%d”,b);
Back }
Back
96.Program to accept a string in lower case
and print first character of each word in upper 98.Program for example of static variable.
case.
#include<conio.h>
#include<conio.h> #include<stdio.h>
#include<stdio.h> static int i=1;
main( ) main( )
{ {
char str1[80]; int j;
int length,i; clrscr( );
clrscr( ); for (j=1;j<=5;j++);
printf(“enter a string; “); fun( );
length=getline(str1,80); getch( );
}
fun( )
{
printf(“\n%d”,i);
i=i+1;
}
Back

99.Program to accept a string and print by


trailing spaces.

#include<conio.h>
#include<stdio.h>
main( )
{
char n,n1;
clrscr ( );
printf(“enter a string;”);
while((n=getchar( )!=’\n’)
if(n>=’a’ && n<=’z’)
putchar(n);
else
if(n>=’a’ && n<=’z’)
putchar(n);
getch( );
}
Back

100. Program to print anti diagonal.

#include<conio.h>
#include<stdio.h>
main( )
{
int a[4][4],i,j,c;
clrscr( );
printf(“enter which number you want;”);
scanf(“%d”,&c);
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(i+j= =3)
a[i]]j]=c;
else
a[i][j]=0
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf(“%d”,a[i][j]);
printf(“\n”);
}
getch( );
}
Back

You might also like