You are on page 1of 26

34.

Program to print prime numbers between 1 to


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

# include <stdio.h>
Back # include <conio.h>
main( )
9. Program to accept a number and check the {
given number is Armstrong or not. int n,sum=0,i;
clrscr( );
# include <stdio.h> for (i=1; i<=10; i++)
# include <conio.h> sum=sum+i;
main( ) printf(“sum of natural numbers from 1 to
{ 10 is %d\n”,sum);
int n, a, b, c, d; getch( );
clrscr( ); }
printf (“ Enter a Three Digit Number: “); Back
scanf (“%d”, &n);
a=n/100; 13. Program to accept a number and print
b=((n/10)%10); mathematical table of the given no.
c=n%10;
d=a*a*a*+b*b*b +c*c*c; # include <stdio.h>
if (n= =d) # include <conio.h>
printf (“The Given Number is Armstrong main( )
number”); {
else int i,t;
printf (“The Given Number is Not clrscr( );
Armstrong number”); printf(“which table u want:”);
getch( ); scanf(“%d”,&t);
} for (i=1; i<=10; i++)
Back printf(“\n%d*%d=%d”,t,i,i*t);
getch( );
10. Program to print ODD numbers from 1 to 10 }
Back
{
14. Program to print 1 to 10 mathematical tables int i,j ,l,k=40;
. 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>
printf(“%d”,j); # include <conio.h>
printf(“\n”); main( )
} {
getch(); char i,j;
} clrscr();
Back for(i=65;i<=70;i++)
17. Program to print numerical pyramid. {
for(j=65;j<=i;j++)
# include <stdio.h> printf(“%c”,j);
# include <conio.h> printf(“\n”);
main( ) }
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>c
for(i=65;i<=75;i+=2) )?(b>d)?b:d:(c>d)?c:d;
{ printf(“biggest of the given 4 numbers IS
for(s=1;s<=sp;s++) %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 using printf(“enter the value of d”);
ternary numbers scanf(“%d”,&d);
small=(a<b)?(a<c)?(a<d)?a:d:(c<d)?c:d:(b
# include <stdio.h> <c)?(b<d)?b:d:(c<d)?c:d;
# include <conio.h> printf(“biggest of the given 4 numbers IS
main( ) %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>
printf(“biggest of the given numbers IS # include <conio.h>
%d”,big); main( )
getch(); {
} int y,leap;
Back clrscr( );
printf(“enter any yr”);
22. Program to find biggest of four no by using scanf(“%d”,&y);
ternary numbers leap=(y%400= =0)?:(y%100!=0)?(y%4=
=0)?1:0:0;
# include <stdio.h> if(leap= =1)
# include <conio.h> printf(“ the given year is leap year”);
else printf(“%d\n”,a);
printf(“given year is not leap year); }
getch( ); getch();
} }
Back
Back
25. Program to accept a character in the
uppercase and print in lower case. 28. Program to accept a string and print it by
using the while loop.
# include <stdio.h>
# include <conio.h> # include <stdio.h>
main( ) # include <conio.h>
{ main( )
char ch,c1; {
clrscr( ); char ch;
printf(“enter a cha in uppercase”); clrscr();
ch=getchar(); printf(“enter a string”);
c1=ch+32; while(( ch=getchar( ))!=’\n’)
printf(“the given char in lowercasecase putchar(ch);
is”); getch();
putchar(c1); }
getch(); Back
}
29. Program to accept a string in upper case and
Back print it by lower case.

26. Program to accept a character in any case # include <stdio.h>


and print in another case. # include <conio.h>
main( )
# include <stdio.h> {
# include <conio.h> char ch,c;
main( ) clrscr();
{ printf(“enter a string in upper case:”);
char ch,c1; while(( ch=getchar( ))!=’\n’)
clrscr( ); {
printf(“enter a char in anycase”); c=ch+32;
ch=getchar(); putchar(c);
if(ch>=65 && ch<=90) }
c1=ch+32; printf(“ is in lower case”);
else getch( );
if(ch>=97 && ch<=122) }
c1=ch-32; Back
printf(“the given char in anothercase IS”);
putchar(c1); 30. Program to accept a string in any case and
getch(); print it by another case .
}
Back # include <stdio.h>
# include <conio.h>
27. Program to natural number from 1 to 10 by main( )
using while loop. {
char ch;
# include <stdio.h> clrscr( );
# include <conio.h> printf(“enter a string :”);
main( ) while(( ch=getchar( ))!=’\n’)
{ {
int a=0; if(ch>=’A’ && ch<=’Z’)
clrscr(); putchar(ch+32);
while( a<10) else
{ if(ch>=’a’ && ch<=’z’)
a=a+1; putchar(ch-32);
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 word scanf(“%d “,&n);
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 of break;
capital letters, no. of small letters and no. of case 9: printf(“NINE”);
special characters break;
default:
# include <stdio.h> printf(“please enter the number between 0
# include <conio.h> 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 1
while(( ch=getchar( ))!=’\n’) 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();
s1=s1+1; for(i=1;i<=100;i++)
} {
printf(“ no of capital letters are %d”,c); check=1;
printf(“ no of smal1 letters are %d”,s); for(n=2;n<=i/2;n++)
printf(“ no of special characters are if(i%n= =0)
%d”,s1); {
getch( ); check=0;
} break;
Back }
if(check= =1)
33. Program to accept any single digit number printf(“\n %d is a prime”,i);
and print it in words . 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
printf(“enter a number:”) 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 fact(int n) {
{ int r,rev=0,s;
int i, fa=1; while(n>0)
for(i=n;i>=1;i--) {
fa=fa*i; r=n%10;
return fa; rev=rev*10+r;
} n=n/10;
Back }
return rev;
37. Program to accept a number and check the }
given number Armstrong or not int add(int n, int a)
{
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 dimensional
printf(“\nA[%d]=%d”,i,a[i]); 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( )
{
41. Program to accept a string and check int a[4][4],i,j,c;
the given string is palindrome or not . clrscr( );
printf(“ enter which no u want”);
# include <stdio.h> scanf(“%d”,&c);
# include <conio.h> for(i=0;i<4;i++)
main( ) for(j=0;j<4;j++)
{ if(i<j)
int i,lim,c,check=1; a[i][j]=c;
char word[80]; else
clrscr( ); a[i][j]=0;
printf(“ enter a string”); for(i=0;i<4;i++)
for(j=0;j<4;j++) for(i=0;i<80&&((str[i]=getchar( ))!=’\n’);
{ i++);
printf(“ %d:”,a[i][j]); if(str[i]= =’\n’)
printf(‘\n”); str[i]=’\0’;
} return i;
getch( ); }
} Back
Back
46. Program to count the number of words,
44. Program to accept two 3 dimensional array characters, alphabets, vowels, consonants and
and store addition of those into arrays into the digit in a line of text.
third array .
#include<stdio.h>
# include <stdio.h> #include<conio.h>
# include <conio.h> main( )
main( ) {
{ int noa=0,nob=0,noc=0,nov=0,now=0,noch=0,l,I;
int a[3][3],b[3][3],c[3][3],i,j; char ch,s[100];
clrscr( ); clrscr( );
for(i=0;i<3;i++) printf(“enter 2 lines of text”);
for(j=0;j<3;j++) gets(s);
{ l=strlen(s);
printf(“enter the two values for for(i=0;i<1;i++)
a[%d][%d] & b[%d][%d]”, i,j,i,j); {
scanf(“%d%d”,&a[i][j],&b[i][j]); switch(s[i])
} {
for(i=0;i<3;i++) case ‘a’:
{ case ‘e’:
for(j=0;j<3;j++) case ‘i’:
{ case ‘o’:
c[i][j]=a[i][j]+b[i][j]; case ‘u’:
printf(“%d”,c[i][j]); case ‘A’:
} case ‘E’:
printf(“\n”); case ‘I’:
} case ‘O’:
getch( ); case ‘U’:
} nov++;
Back break;
}
45. Program to accept a string and find the if(isalpha(s[i]))
length of the given string by using functions noa++;
if(isdigit(s[i]))
# include <stdio.h> nod++;
# include <conio.h> if(noa[i]==’ ‘) && (noa[i+1]!=’ ‘)
int getline(char str[]); now++;
main( ) }
{ noch=l-nob;
char str[80]; noc=noa-nov;
int length; printf(total no of words %d”,now);
clrscr( ); printf(total no of characters(without
printf(“ enter a string”); blanks)%d”,noch);
length=getline(str); printf(total no of characters(including
printf(“length of the given string is blanks)%d”,l);
%d”,length); printf(total no of alphabets
getch ( ); %d”,noa);
} printf(total no of vowels
int getline(char str[]) %d”,nov);
{ printf(total no of characters %d”,noc);
int i; printf(total no of digits %d”,nod);
getch( );
} 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 print
getline(str1,80); 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,3
printf(“both the strings are equal”); 1,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 using nm++;
bubble sort. }
if(nm>12)
# include <stdio.h> {
# include <conio.h> nm=1;
main( ) ny++;
{ }
int a[100],i,j,n,t; printf(“Given date is
clrscr( ); %d:%d:%d\n”,d,m,y);
printf(“enter the array size”); printf(“next days date is
scanf(“%d”,&n); %d:%d:%d”,nd,nm,ny);
for(i=1;i<n;i++) getch( );
scanf(“%d”,&a[i]); }
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”);
{ else
int n,p=1,q,num,sp; printf(“given number is not prime
clrscr( ); number”);
printf(“enter the number of rows”); getch( );
scanf(“%d”,&n); }
for(p=0;p<=n;p++) Back
{
for(sp=1;sp<=40-(3*p);sp++) 54. Program to read ‘n’ number and print them
printf(“ “); in matrix terms in all orders.
for(q=0;q<n;q++)
{ # include <stdio.h>
if((q==q)||(q==0)) # include <conio.h>
num=1; main( )
else {
num=num*((q-q)+1)/q; int i,n,c,p,q,r,k,a[20];
printf(“%2d”,num); clrscr();
printf(“\n”); printf(“enter the array size”);
}} scanf(”%d”,&n);
getch( ); printf(“enter the elements”);
} for(i=1;i<=n;i++)
Back scanf(“%d”,&a[i]);
i=1;
52. Program to check whether a given number is while(i<=n)
perfect or not. {
if(n%i==0)
# include <stdio.h> {
# include <conio.h> r=i;
c=n/i; a=10;
k=1; b=20;
for(p=1;p<=r;p++) c=*(&a)+*(&b);
{ printf(“%d”,c);
for(q=1;q<=c;q++) getch( );
printf(“%d”,a[k++]) }
printf(“\n”); Back
}
i++; 57. Programs to multiply two Matrices
getch( );
} # include <stdio.h>
Back # include <conio.h>
main( )
55. Program to search an element using binary {
search int
a[10][10],b[10][10],c[10],[10],i,j,m,n,p,q,
# include <stdio.h> k;
# include <conio.h> clrscr( );
main( ) printf(“enter the size of first matrices”);
{ scanf(“%d%d’,&m,&n);
int a[100],i,n,x, mid, top, bot,c; printf(“enter the size of second matrix”);
clrscr(); scanf(“%d%d’,&p,&q);
printf(“enter the array size;”); if(n==p)
scanf(“%d”,&n); {
printf(“enter the array elements”); printf(“enter first matrices elements”);
for(i=1;i<=n;i++) for(i=1;i<m;i++)
scanf(“%d”,&a[i]); for(j=1;j<n;j++)
top=1; scanf(“%d”,&a[i][j]);
bot=n; printf(“enter second matrix elements”);
c=0; for(i=1;i<p;i++)
printf(“enter the element to searched”); for(j=1;j<q;j++)
scanf(“%d”,&x); scanf(“%d”,&b[i][j]);
while((top <=bot)&&(c==0)) for(i=1;i<m;i++)
{ for(j=1;j<n;j++)
mid=(top+bot)/2; {
if(a[mid]<x) c[i][j]=0;
top=mid+1; for(k=1;k<n;k++)
else c[i][j]=c[i][j]+a[i][k]*b[k][j];
if(a[mid]>x) }
bot=mid-1; printf(“the multiplication matrix is”);
else for(i=1;i<m;i++)
c=1; {
} for(j=1;j<n;j++)
if(c==1) print(“%2d”,c[i][j]);
printf(“elements is at position;%d”,mid); printf(“\n”);
else }
printf(“elements is not in list”); }
getch( ); else
} printf(“multiplication is not possible”);
Back getch( );
}
56. Program to accept two numbers and print
the sum of given two numbers by using pointers Back

# include <stdio.h> 58. Program to print prime number between 1-


# include <conio.h> 100
main( )
{ # include <stdio.h>
int a, b,c; # include <conio.h>
clrscr( ); main( )
{ 61. Program a structure which reads ‘n’
int i,n,c; students information (name,3 subjects marks)
clrscr( ); and calculate total marks, result print them in a
for(n=1;n<=100;n++) particular format.
{
c=0; # include <stdio.h>
for(i=1;i<=n;i++) # include <conio.h>
if(n%i==0) main( )
c++; {
if(c==2) struct student
printf(“\n%d”,n); {
} char name[20];
getch( ); int m1,m2,m3, tot;
} char result[10];
Back }stud[10];
int i,n;
59. Program to accept a string and find the clrscr( );
length of the string printf(“enter no of students \n”);
scanf(“%d”,&n);
# include <stdio.h> for(i=0;i<n;i++)
# include <conio.h> {
main( ) printf(”enter %d student deatails \n”,i);
{ printf(”enter name\n”);
char name[80]; scanf(“%s”, stud[i].name);
int i; printf(“enter marks of 3 subjects \n”);
clrscr( ); scanf(“%d%d%d”,
printf(“enter a string ;”); &stud[i].m1,&stud[i].m2,&stud[i].m3);
for(i=0;i<80&&((name[i]=getchar( ))! stud[i].tot=stud[i].m1+stud[i].m2+stud[i].
=’\n’);i++); m3;
printf(“%d is the size of string”,i); if((stud[i].m1>35)&&(stud[i].m2>35)&&(
getch( ); stud[i].m3>35))
} strcpy(stud[i].result,”pass”);
Back else
strtcpy(stud[i].result,”fail”);
60. Program to fibanocci of matrix }
clrscr( );
# include <stdio.h> printf(“name total result \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
scanf(“%d%d”,&m,&n);
printf(“enter the element of matrix”); 62. Program to find whether a square matrix is
for(i=1;i<=m;i++) a) symmetric b) skew symmetric c) none of two.
for(j=1;j<=n;j++)
{ # include <stdio.h>
scanf(“%d”,&a[i][j]); # include <conio.h>
sum=sum+(a[i][j]*a[i][j]) main( )
} {
norm=sqrt(sum); int a[10][10],i,j,m,n,c=0,c1=0;
printf(“norm=%f”,norm); clrscr( );
getch( ); printf(“enter the array size”);
} scanf(“%d”,&n);
Back printf(“enter the elements”);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
scanf(“%d”,&a[i][j]); for(i=1;i<=500;i++)
for(i=1;i<=m;i++) {
for(j=1;j<=n;j++) n=i;
{ s=0;
if(a[i][j]==a[j][i]) while(n>0)
c=1; {
else r=n%10;
if(a[i][j]==a[j][i]) s=s+(r*r*r);
c1=1; n=n/10;
} }
printf(“the given matrix is \n”); if(i==s)
for(i=1;i<=m;i++) printf(“\n%d”,s);
{ }
for(j=1;j<=n;j++) getch();
printf(“%4d”,a[i][j]); }
printf(“\n”); Back
}
if(c==0) 65. Program to check whether a given number is
printf(“the given matrix is symmetric”); Armstrong or not.
else
if(c1==0) # include <stdio.h>
printf(“the matrix is skew symmetric”); # include <conio.h>
else main( )
printf(“none of two”); {
} int i,n,s,r,k;
getch( ); clrscr( );
} printf(“enter a number”);
Back scanf(“%d”,&n);
k=n;
63. Program to find area of a triangle when s=0;
there sides are given. while(n>0)
{
# include <stdio.h> r=n%10;
# include <conio.h> s=s+(r*r*r);
main( ) n=n/10;
{ }
int a,b,c; if(k==s)
float s, area; printf(“given number is Armstrong
clrscr( ); %d”,k);
printf(“enter there sides of the 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”); }
else getch();
s=(a+b+c)/2; }
area=sqrt(s*(s-a)*(s-b)*(s-c)); Back
printf(“area=%.2f”,area);
getch( ); 66. Program to print the floyd’s triangle.
}
Back # include <stdio.h>
# include <conio.h>
64. Program to print Armstrong number main( )
between 1-500. {
int i,n,s,r k=1;
#include<stdio.h> clrscr( );
#include <conio.h> printf(“enter a number of rows”);
main( ) scanf(“%d”,&n);
{ for(i=1;i<=n;i++)
int i,n,s,r; {
clrscr( ); for(s=1;s<=40-i;s++)
printf(“ ”); }
for(j=1;j<=i;j++) getch();
printf(“%3d”,k++); }
printf(“\n”); Back
}
getch( ); 69. Program to copy contents of one file into
} another.
Back
#include<stdio.h>
67. Program to read data in 3 structures and #include<conio.h>
print main( )
{
# include<stdio.h> FILE *fp1,*fp2;
# include<conio.h> char ch;
fp1=fopen(“text1”,”w”);
main( ) printf(‘enter the text”);
{ while((ch=getchar( ))!=EOF)
struct book putc(ch,fp1);
{ fclose(fp1);
char code; fp1=fopen(“text1”,”r”);
int piece; fp2=fopen(“text2”,”w”);
float price; while((ch=getc(fp1))!=EOF)
}; putc(ch,fp2);
struct book b1,b2,b3; fclose(fp2);
main( ) getch( );
{ }
clrscr( ); Back
printf(“enter code,piece,price”);
scanf(“%c%d%f”,&b1.code,&b1.piece,&b1.price); 70. Program to create a file of number and copy
printf(“enter code,piece,price”); odd number into second file and even number
scanf(“%c%d%f”,&b2.code,&b2.piece,&b2.price); into third file.
printf(“enter code,piece,price”);
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);
68. Program to print a diagonal matrix. while(i!=eof( ))
{
#include<conio.h> putw(i,fp1);
#include<stdio.h> }
main() fcolse(fp1);
{ fp1=fopen(“DATA1”,”r”);
int a[4][4],i,j; fp2=fopen(“DATA2”,”w”);
clrscr( ); fp3=fopen(“DATA3”,”w”);
for(i=0;i<4;i++) while((i=getw(fp1))!=EOF())
for(j=0;j<4;j++) if(i%2= =0)
if(i==j) putw(i,fp3);
c[i][j]=7; else
else putw(i,fp2);
a[i][j]=0; fcolse(fp1);
for(i=0;i<4;i++) fcolse(fp2);
{ fcolse(fp3);
for(j=0;j<4;j++) getch( );
printf(“%d”,a[i][j]); }
printf(“\n”); Back
printf(“%s %s %c %d
71. Program a structure which stores %d”,ht[i].name,ht[i].city,ht[i].grade,ht[i].r
information about hotels which stores c,ht[i].nr);
information about name, grade, room change, getch();
no of rooms. printf(“enter a room charge to print hotels
a) a) Print the hotels of less than given charge \n”);
given grade in order of scanf(“%d”,&c);
roomchange. printf(“hotel name city grade roomcharge
b) b) Print the hotels with no of rooms”);
roomchange less than a given for(i=0;i<n;i++)
change. if(c<=ht[i].rc)
printf(“%s %s %c %d
#include<stdio.h> %d”,ht[i].name,ht[i].city,h[i].grade,ht[i].rc
#include<conio.h> ,ht[i].nr);
main( ) }
{
struct hotel Back
{
char name[20]; 72. Program which does the below process after
char city[10]; reading on odd no of integer.
char grade; a) a) Print them in given order.
int rc,nr; b) b) Replace second elements by
}; product of first and last element
struct hotel ht[20],t; c) c) Replace middle value by average of
int i,n,j,c; all elements.
char gr; d) d) Replace all –ve no’s by zero’s.
clrscr( );
printf(“enter no. of hotels\n”); #include<stdio.h>
scanf(“%d”,&n); #include<conio.h>
for(i=0;i<n;i++) main( )
{ {
printf(“enter name of hotel \n”); int a[10],i,n,sum=0;
scanf(“%s”,&ht[i].name); clrscr( );
printf(“enter name of city \n”); printf(“enter the array sixe “);
scanf(“%s”,&ht[i].city); scanf(“%d”,&n);
printf(“enter the grade \n”); printf(“enter the elements”);
scanf(“%s”.ht[i].grade); for(i=0;i<n;i++)
ht[i].grade=getche( ); {
printf(“enter room charge \n”); scanf(“%d”,&a[i]);
scanf(“%d”,&ht[i].rc); sum=sum+a[i];
printf(“enter no of rooms \n”); }
scanf(“%d”,&ht[i].nr); printf(“The given arrays is: “);
} for(i=0;i<n;i++)
for(i=0;i<n;i++) printf(“%d”,a[i]);
for(j=0;j<n-i;j++) a[2]=a[1]*a[n-1];
{ printf(“\n the given areay after replacing
t=ht[j]; 2nd element is”);
ht[j]=ht[j+i]; for(i=0;i<n;i++)
ht[j+1]=t; printf(“%d”,a[i]);
} a[(1+n/2)]=sum/n;
printf(“enter a grade to print the hotels printf(“\n the given array after replacing
\n”); middle element by average of all”);
gr=getche(); for(i=0;i<n;i++)
clrscr(); if(a[i]<0)
printf(“hotel name city grade roomcharge a[i]=0;
no of room”); printf(“\n given array after replacing –ve
for(i=0;i<n;i++) values by zero”);
if(gr==ht[i].grade) for(i=0;i<n;i++)
printf(“%d”,a[i]);
printf(“\n”); {
getch(); evensum=evensum+(b%10);
} b=b/10;
Back }
div=abs(evensum-oddsum);
73. Program to sort the entered elements using if(div%11==0)
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


#include<conio.h> until there sum exceeds 2.6 term value
#include<math.h> exceeds 1.5
main( ) x+x2/2!+x3/3!+------------.
{
int a,b,n,evensum=0,oddsum=0,div; #include<stdio.h>
clrscr( ); #include<conio.h>
printf(“enter a number”); main( )
scanf(“%d”,&n); {
a=n; float x,sum=0,prod=1;
b=n/10; int i;
while(a>0) clrscr( );
{ printf(“enter x value”);
oddsum=oddsum+(a%10); scanf(“%f’,&x);
a=a/10; i=1;
} while((sum<2.6)&&(prod<=1.5))
while(b>0) {
prod=prod*(x/i); else
if(prod<=1.5) if((a[i]>15)&&(a[i]<21))
sum=sum+prod; n4++;
if(sum>2.6) else
{ if((a[i]>20)&&(a[i]<26))
sum=sum-prod; n5++;
break; printf(“class interval frequency”);
} printf(“\n 1-5 %d”,n1);
printf(“sum=;%f’,sum); printf(“\n 6-10 %d”,n2);
i++; printf(“\n 11-15 %d”,n3);
} printf(“\n 16-20 %d”,n4);
getch( ); printf(“\n 21-25 %d”,n5);
} getch();
Back }
Back
77. Program to print a frequency
distribution table for a class of 20-students 78. Program to accept values into an array and print
in the following format. array in reverse and original format by using three
The marks range form 1-25. different functions.
class intertval frequency
1.5 1-5 #include<stdio.h>
#include<conio.h>
void read_array(int x[]);
- void print_array(int y[]);
6.10 6-10 void rev_array(int z[]);
main()
{
- int a[5];
11.15 11-15 clrscr();
read_array(a);
- printf_array(a);
16.20 16-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]);
#include<stdio.h>
}
#include<conio.h>
}
main( )
void print_array(int y[])
{
{
int a[20],i,n1=0,n2=0,n3=0,n4=0,n5=0;
int i;
clrscr();
for(i=0;i<=4;i++)
printf(“enter the any 20 no of range(1-
printf(“%d”,y[i]);
25));
}
for(i=1;i<=20;i++)
void rev_array(int z[])
scanf(“%d”,&a[i]);
{
for(i=1;i<=20;i++)
int i;
if((a[i]>=1)&&(a[i]<6))
for(i=4;i>=0;i--)
n1++;
printf(“\n%d”,z[i]);
else
}
if((a[i]>5)&&(a[i]<11))
Back
n2++;
else
79. Program to accept values into single
if((a[i]>10)&&(a[i]<16))
dimensional array and print the array in reverse
n3++;
by using pointers.
81. Program to accept two strings and compare
#include<stdio.h> those two strings
#include<conio.h>
main( ) #include<stdio.h>
{ #include<conio.h>
int a[5],*b,i; int strcomp (char *pt1, char *pt2);
clrscr( ); void read-string(char*pt);
b=&a[0];
for(i=0;i<=4;i++) main( )
{ {
printf(“enter a value for a[%d];”.i); char line [80],line2[80];
scanf(“%d”,b); clrscr( );
b++; printf(“enter first string;”);
} read-string (line1);
b=&a[4]; printf(“enter second string”);
for(i=0;i<=4;i++) read-string(line2);
{ if(strcomp (line1,line2)>0)
printf(“\n%d”,*b); printf(“second string biggest”);
b-- ; else
} if(strcomp (line1,line2)>0)
getch( ); printf(“ first string biggest;”);
} else
Back printf(“both the strins are equal”);
getch( );
80. Program to read a string and print the }
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);
for(i=0;i<l;i++) 82. Program to accept a string using pointers
{ and functions.
if(s[i]!=’ ‘)
{ #include<stdio.h>
nc=0; #include<conio.h>
while(s[i]!=’ ‘)
{
nc++;
printf(“%c”,s[i]);
i++;
if(s[i]=’\0’)
break;
}
printf(“\t\t %d”,nc);
printf(“\n”);
}
}
getch();
}
Back
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 array
i++; 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 pointers for(i=0;i<3;i++)
for(j=0;j<3;j++)
#include<stdio.h> {
#include<conio.h> printf(“enter two values for a[%d][%d] &
main( ) b[%d][%d]:”,i,j,i,j);
{ scanf(“%d%d”,&a[i][j],&b[i][j]);
int a, b,c; }
clrscr( ); for(i=0;i<3;i++)
a=10; {
b=20; for(j=0;j<3;j++)
c=*(&a)+*(&b); {
printf(“%d”,c); c[i][j]=a[i][j]-b[i][j];
getch( ); printf(“%d”,,c[i][j]);
} }
Back printf(“\n”);
}
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.
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 given fclose(fp);
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”);
if(c==eof( )) while((ch=getchar()!=EOF);
putc(ch,fp1); str1[0]-=32;
fclose(fp1); if(str1[i]= =’ ‘)
fp1=fopen(“text1”,”r”); str1[i+1]-=32;
fp2=fopen(“text2”,”w”); printf(“%c”.str1[i]);
while((ch=getc(fp1))!=EOF) }
putc(ch,fp2); getch();
fcolse(fp1); }
fcolse(fp2); int getline(char line [], int lim)
getch( ); {
} int i;
Back for(i=0;i<lim && ((line[i]=getchar( ))!
=’\n’);i++);
95. Program to create a file of numbers and if(line[i]= =’\n’)
copy odd number into second file and even line[i]=’\0’;
number into third file return i;
}
#include<conio.h> Back
#include<stdio.h>
main( ) 97.Program to accept two numbers and
{ interchange two values using functions.
FILE *fp1,*fp2,*fp3;
int i; #include<conio.h>
fp1=open(“data1”,w”); #include<stdio.h>
printf(“enter the number”); void swap (int a, int b);
scanf(“%d”,&i); main( )
while(i!=eof) {
{ int a,b;
putw(i,fp1); clrscr( );
scanf(“%d”,&i); printf(“enter value for a;”);
} scanf(“%d”,&a);
fcolse(fp1); printf(“enter value for b;”);
fp1=fopen(“data1”,”r”); scanf(“%d”,&b);
fp2=fopen(“data2”,”w”); swap(a,b);
fp3=fopen(“data3”,”w”); getch( );
while((i=getc(fp1))!=eof) }
if(i%2==0) void swap(int a,int b)
putc(i,fp3); }
else int c;
putw(i,fp2); c=a;
fcolse(fp1); a=b;
fcolse(fp2); b=c;
fcolse(fp3); printf(“\na=%d”,a);
getch( ); printf(“\nb=%d”,b);
} }
Back Back

96.Program to accept a string in lower case and 98.Program for example of static variable.
print first character of each word in upper 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( );
for(i=0;i<length;i++) }
{ 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