Sei sulla pagina 1di 48

C PROGRAMS WITH SOLUTIONS- 2

NOTE: THIS ARE THE CONFIDENTAL AND INTERNAL PROGRAMS WITH


OUTPUTS.
C PROGRAMS FOR BEGINEERS(FRESHERS) FOR THE INTERVIEW POINT OF
VIEW.
1.C program to perform arithemetic operations*/

#include<stdio.h>
main()
{
int a,b;
clrscr();
printf("Enter value for a:");
scanf("%d",&a);
printf("/nEnter value for b:");
scanf("%d",&b);
printf("/n%d+%d=%d",a,b,a+b);
printf("/n%d-%d=%d",a,b,a-b);
printf("/n%dX%d=%d",a,b,a*b);
printf("/n%d/%d=%d",a,b,a/b);
}
o/p:
Enter value for a:5
Enter value for b:2
5+2=7
5-2=3
5X2=10
5/2=2

2. C program to calculate simple interest*/


#include<stdio.h>
main()
{
float p,n,r,ci;
clrscr();
printf("Enter princiole :");
scanf("%f",&p);
printf("Enter Time Period:");
scanf("%f",&n);
printf("Enter Rate of Interest:");
scanf("%f",&r);
ci=(p*n*r)/100;
printf("Simple Interest=%f",ci);
}

o/p:
Enter principle :5700.50
Enter Time Period:1.6
Enter Rate of Interest:2.5
Simple Interest=228.020004

3. C program to calculate Compound interest*/


#include<stdio.h>
#include<math.h>
main()
{
float p,n,r,ci,d;
clrscr();
printf("Enter principle :");
scanf("%f",&p);
printf("/nEnter Time Period:");
scanf("%f",&n);
printf("Enter Rate of Interest:");
scanf("%f",&r);
d=(1+r*0.10);
ci=p*pow(d,n);
printf("Simple Interest=%f",ci);
}
o/p:
Enter principle :2000
Enter Time Period:2
Enter Rate of Interest:2
Simple Interest=2880.000244

4. Distance Travelled*/
#include<stdio.h>
main()
{
float a,u,t,dis;
clrscr();
printf("\nEnter velocity, acceleration and time:");
scanf("%f%f%f",&a,&u,&t);
dis=(u*t)+(0.5*a*t*t);
printf("Distance travelled=%f",dis);
getch();
}

5. C program to convert Temparature From Faranheat To Celsiuls*/


#include<stdio.h>
main()
{
float ft,ct;
clrscr();

printf("Enter Faran Heat Temparature:");


scanf("%f",&ft);
ct=(ft-32)*5/9;
printf("/ncelsius Temparature=%f",ct);
}

6. C program to convert Temparature From Celsius To Faranheat*/


#include<stdio.h>
main()
{
float ft,ct;
clrscr();
printf("Enter celsius Temparature:");
scanf("%f",&ct);
ft=(ct*9/5)+32;
printf("/nFaran Heat Temparature=%f",ft);
}

7. C program to calculate cube of the number*/


#include<stdio.h>
main()
{
int a;
clrscr();
printf("Enter value for a:");
scanf("%d",&a);
printf("%d^3=%d",a,a*a*a);
}
o/p:
Enter value for a:5
5^3=125

8. *Swapping 2 nos Without Using Third Variable*/


#include<stdio.h>
main()
{
int a,b;
clrscr();
printf("/nEnter values for a,b:");
scanf("%d%d",&a,&b);
printf("/nBefore swaping a=%d b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("/nAfter swaping a=%d b=%d",a,b);
getch();
}
o/p:

Enter values for a,b:10 15


Before swaping a=10 b=15
After swaping a=15 b=10

9. Even Number Odd Number Checking in C*/


#include <stdio.h>
main()
{
int a;
printf("enter values for a");
scanf("%d",&a);
if(a%2==0)
{
printf("%d is even"a);
}
}

10. Finding Roots Of Quadratic Equations*/


#include<stdio.h>
#include<math.h>
main()
{
int a,b,c;
int alpha,beta,root;
clrscr();
printf("\nEnter a,b,c:");
scanf("%d%d%d",&a,&b,&c);
root=sqrt((b*b)-4*a*c);
alpha=(-b+root)/(2*a);
beta=(-b-root)/(2*a);
printf("alpha=%d",alpha);
printf("beta=%d",beta);
getch();
}

11. /*Comparing 2 Numbers Using Simple if Condition in C*/


#include <stdio.h>
main()
{
int a,b;
printf("enter values for a,b");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("%d is big"a);
}
if(a<b)
{
printf("%d is big"b);
}

if(a==b)
{
printf("%d and %d are equal"a,b);
}
}

12. /*Leap Year Using Simple if-else Condition in C*/


#include <stdio.h>
main()
{
int year;
clrscr();
printf("/nEnter year:");
scanf("%d",&year);
if(year%4==0)
printf("/nLeap year");
else
printf("/nNon Leap year");
getch();
}

13. /*Triangle Checking Using Simple if-else Condition in C*/


#include <stdio.h>
main()
{
int a,b,c;
clrscr();
printf("Enter 3 angles:");
scanf("%d%d%d",&a,&b,&c);
if(a+b+c==180)
printf("/nTriangle is valid");
else
printf("/nTriangle is not valid");
getch();
}
o/p:
Enter 3 angles:60
60
60
Triangle is valid
Enter 3 angles:45
45
80

14. /*Biggest Number Among 4 Numbers*/


#include <stdio.h>
main()
{
int a,b,c,d;
clrscr();

printf("enter values for a,b,c,d");


scanf("%d%d%d%d",&a,&b,&c,&d);
if(a>b && a>c && a>d)
printf("a(%d) is big",a);
else if(b>c && b>d)
printf("b(%d) is big",b);
else if(c>d)
printf("c(%d) is big",c);
else
printf("d(%d) is big",d);
getch();

15. /*Leap Year Using Simple if-else Condition in C*/


#include <stdio.h>
main()
{
int a,b,c,d;
clrscr();
printf("enter values for a,b,c,d");
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a>b && a>c && a>d)
printf("a(%d) is big",a);
else if(b>c && b>d)
printf("b(%d) is big",b);
else if(c>d)
printf("c(%d) is big",c);
else
printf("d(%d) is big",d);
getch();
}

16. /*program to check whether a point lies on x-axis or y-axis or on


the origin*/
#include <stdio.h>
main()
{
int x,y;
clrscr();
printf("Enter a point(x,y)");
scanf("%d%d",&x,&y);
if(x==0 && y==0)
printf("/nPoint lies on the origin");
else if(x!=0 && y==0)
printf("/nPoint lies on x-axis");
else
printf("/nPoint lies on y-axis");
getch();
}
o/p:
Enter a point(x,y)0 0

Point lies on the origin


Enter a point(x,y)2 0
Point lies on x-axis
Enter a point(x,y)0 10
Point lies on y-axis

17. /*program to check whether a point lies inside or outside or on the


circle*/
#include <stdio.h>
main()
{
int x,y,r,d,ds;
clrscr();
printf("Enter a point(x,y)");
scanf("%d%d",&x,&y);
printf("/nEnter radius of the circle");
scanf("%d",&r);
d=r*r;
ds=((x*x)+(y*y));
if(d==ds)
printf("/point lies on the circle");
else if(ds>d)
printf("/nPoint lies outside of the circle");
else
printf("/nPoint lies inside of the circle");
getch();
}

18. /*Program to find whether entered character is in uppercase or


lowercase*/
#include <stdio.h>
main()
{
char ch;
clrscr();
printf("/nEnter a character:");
scanf("%c",&ch);
if(ch>=65 && ch<=90)
printf("/ncharacter(%c) entered in uppercase",ch);
else if(ch>=97 && ch<=122)
printf("/ncharacter(%c) entered in lowercase",ch);
else if(ch>=48 && ch<=57)
printf("/nentered character(%c) is a digit",ch);
getch();
}

19. /*Finding ASCII Values of characters using while loop*/


#include<stdio.h>
main()
{
int i=65;
clrscr();
while(i<=122)
{
printf("/t%d%c",i,i);
i++;
}
getch();
}

20. /*Finding Sum Of Digits Using While Loop*/


#include<stdio.h>
main()
{
long int n,d,sum=0,m;
clrscr();
printf("Enter any number:");
scanf("%ld",&n);
m=n;
while(n!=0)
{
d=n%10;
sum=sum+d;
n=n/10;
}
printf("Sum of digits of %ld =%ld",m,sum);
}
o/p:
Enter any number:32767
Sum of digits of 32767 =25

21. /*Reversing Number Using While Loop*/


#include<stdio.h>
main()
{
long int n,d,sum=0,m;
clrscr();
printf("Enter any number:");
scanf("%ld",&n);
m=n;
while(n!=0)
{
d=n%10;
sum=(sum*10)+d;
n=n/10;
}

printf("Sum of digits of %ld =%ld",m,sum);


}
o/p:
Enter any number:92346
Sum of digits of 92346 =64329

22. /*Palindromme Number Using While Loop*/


#include<stdio.h>
main()
{
long int n,d,sum=0,m;
clrscr();
printf("Enter any number:");
scanf("%ld",&n);
m=n;
while(n!=0)
{
d=n%10;
sum=(sum*10)+d;
n=n/10;
}
if(m==sum)
printf("%d-Palindrome",m);
else
printf("%d-Not Palindrome",m);
}
o/p:
Enter any number:1234
1234-Not Palindrome
Enter any number:121
121-Palindrome

23. /*Amstrong Number Using While Loop*/


#include<stdio.h>
main()
{
long int n,d,sum=0,m;
printf("Enter any number:");
scanf("%ld",&n);
m=n;
while(n!=0)
{
d=n%10;
sum=sum+(d*d*d);
n=n/10;
}
if(m==sum)
printf("%ld is amstrong number",m);
else
printf("%ld is not amstrong number",m);

}
o/p:
Enter any number:153
153 is amstrong number
Enter any number:235
235 is not amstrong number

24. /*strong number: The sum of factorial of individual digits should be equal to the
original no. eg:145=(1!+4!+5!)*
#include<stdio.h>
main()
{
long int n,d,sum=0,m,i,f;
clrscr();
printf("Enter any number:");
scanf("%ld",&n);
m=n;
while(n!=0)
{
d=n%10;
f=1;
for(i=d;i>=1;i--)
f=f*i;
sum=sum+f;
n=n/10;
}
if(m==sum)
printf("%ld is strong number",m);
else
printf("%ld is not strong number",m);
getch();
}
o/p:
Enter any number:145
145 is strong number
Enter any number:568
568 is not strong number

25. /*strong number: The sum of factorial of individual digits should be equal to the
original no. eg:145=(1!+4!+5!)*/

#include<stdio.h>
main()
{
long int n,d,sum=0,m,i,f;
clrscr();
printf("Enter any number:");
scanf("%ld",&n);
m=n;

while(n!=0)
{
d=n%10;
f=1;
for(i=d;i>=1;i--)
f=f*i;
sum=sum+f;
n=n/10;
}
if(m==sum)
printf("%ld is strong number",m);
else
printf("%ld is not strong number",m);
getch();
}
o/p:
Enter any number:145
145 is strong number
Enter any number:568
568 is not strong number

26. /*GCD of two numbers using while loop*/


#include<stdio.h>
main()
{
int a,b,l;
clrscr();
printf("/nEnter nos:");
scanf("%d%d",&a,&b);
l=gcd(a,b);
printf("GCD=%d",l);
getch();
}
gcd(int a,int b)
{
int c=0;
while(1)
{
c=a%b;
if(c==0)
return b;
a=b;
b=c;
}
}
o/p:
Enter nos:200 800
GCD=200

27. /*LCM of two numbers using while loop*/


#include<stdio.h>
main()
{
int a,b,l;
clrscr();
printf("/nEnter nos:");
scanf("%d%d",&a,&b);
l=lcm(a,b);
printf("Lcm=%d",l);
getch();
}
lcm(int a,int b)
{
int i=1;
while(1)
{
if(i%a==0 && i%b==0)
return i;
i++;
}
}
o/p:
Enter nos:35 50
Lcm=350

28. *Printing Table using while loop*/

#include <stdio.h>
main()
{
int n,i=1,t=1;
clrscr();
printf("/nEnter a table:");
scanf("%d",&n);
while(i<=10)
{
t=n*i;
printf("%2d X%2d=%2d/n",n,i,t);
i++;
}
getch();
}
o/p:
Enter a table:5
5 X 1= 5
5 X 2=10
5 X 3=15
5 X 4=20

5
5
5
5
5
5

X 5=25
X 6=30
X 7=35
X 8=40
X 9=45
X10=50

29. /*Printing First 20 Odd Numbers using while loop*/

#include <stdio.h>
main()
{
int count=0,i=1;
clrscr();
while(count!=20)
{
if(i%2!=0)
{
printf("%d\n",i);
count++;
}
i++;
}
getch();
}
30.

/*Decimal To Binary Conversion using while loop*/

#include<stdio.h>
main()
{
int n,i=0,a[20],d,j,m;
clrscr();
printf("Enter decimal number:");
scanf("%d",&n);
m=n;
while(n!=0)
{
d=n%2;
a[++i]=d;
n=n/2;
}
printf("Binary equivalent of %d=",m);
for(j=i;j>=1;j--)
printf("%d",a[j]);
getch();
}
31./*Binary

To Decimal Conversion using while loop*/

#include<stdio.h>
#include<math.h>
main()
{
long int n,m;
int i=0,sum=0,d,j;
clrscr();
printf("Enter binary number:");
scanf("%ld",&n);
m=n;
while(n!=0)
{
d=n%10;
sum=sum+(d*pow(2,i));
n=n/10;
i++;
}
printf("Decimal equivalent of %ld=%d",m,sum);
getch();
}

32.

/*Menu Driven Program For Arithematic Operations*/

#include<stdio.h>
main()
{
int a,b,res;
char ch;
printf("\n Enter values for a and b:");
scanf("%d%d",&a,&b);
printf("\nEnter choice:");
scanf("%s",&ch);
switch(ch)
{
case '+': res=a+b; break;
case '-': res=a-b; break;
case '*': res=a*b; break;
case '/': res=a/b; break;
case '%': res=a%b; break;
default: printf("\n Enter correct choice:");
}
printf("Result=%d",res);
getch();
}
33. /*Menu driven program having the following options 1. Factorial of a number 2.

prime number 3. Even number*/


main()
{

int n,f,np,a,count=0,ch,i;
do
{
printf("/n1.Factorial of a Number");

printf("/n2.Prime Number or Not");


printf("/n3.Even Number or Not");
printf("/n4.Exit");
printf("/nEnter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("/nEnter number:"); scanf("%d",&n);
f=fact(n);
printf("/n%d!=%d/n",n,f);
break;
case 2:
printf("Enter number:");
scanf("%d",&np);
for(i=1;i<=np;i++)
{
if(np%i==0)
count++;
}
if(count==2)
printf("%d-Prime/n",np);
else
printf("%d-Not Prime/n",np);
break;
case 3:
printf("enter values for a"); scanf("%d",&a);
if(a%2==0)
printf("%d is even number/n",a);
else
printf("/n%d is odd number/n",a);
break;
case 4:
exit(0);
default:
printf("/nYour choice wrong enter correctly/n");
}
}while(ch!=4);
}
/*Fact function*/
int fact(n)
int n;
{
int i,f=1;
for(i=n;i>=1;i--)
f=f*i;
return f;

34.About U/*Printing Number And its Squares Using For Loop*/s|

s|

Contact Usmain()
{
int i;
clrscr();
printf("Number/tSquare");
for(i=1;i<=10;i++)
{
printf("/n%d/t%d",i,i*i);
}
}
o/p:
Number
1
2
3
4
5
6
7
8
9
10

Square
1
4
9
16
25
36
49
64
81
100

35. /*Printing Squares And Cubes Of Even Numbers Using For Loop */
#include
main()
{
long int i;
clrscr();
printf("Number/tSquare/tCube");
for(i=1;i<=50;i++)
{
if(i%2==0)
{
printf("/n%ld/t/t%ld/t/t%ld",i,i*i,i*i*i);
}
}
}
36. /*Printing Format Using For Loop */
main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%2d",i);
}
printf("/n");
}
getch();
}

o/p:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
37. /*Printing Format Using For Loop */
main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%2d",j);
}
printf("/n");
}
getch();
}
o/p:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
38. /*Printing Format Using For Loop */
main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf(" ");
for(j=i;j<=5;j++)
{
printf("%d",j);
}
printf("/n");
}
}
o/p:
12345
2345
345

45
5

39. /*Printing Format Using For Loop 1

1
main()
{
int i,j,n;
clrscr();
printf("Enter number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=i;j>=1;j--)
printf("%3d",j);
printf("\n");
}
getch();
}
o/p:
Enter number:9
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1

40. /*Printing Format Using For Loop 5

o/p:
Enter number:5
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

3
1

1 */
main()
{
int i,j,n,m;
clrscr();
printf("Enter number:");
scanf("%d",&n);
m=n;
for(i=1;i<=m;i++)
{
for(j=n;j>=1;j--)
printf("%3d",j);
printf("\n");
n=n-1;
}
getch();
}

41. /*Printing Format Using For Loop 1


8 9

42./*Printing Format Using For Loop */.


main()
{
int i,n;
clrscr();

7
8

1 */
main()
{
int i,j,n,m;
clrscr();
printf("Enter number:");
scanf("%d",&n);
m=n;
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
printf("%3d",j);
printf("\n");
n=n-1;
}
getch();
}
o/p:
Enter number:9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

printf("Enter the range:");


scanf("%d",&n);
for(i=n;i>=0;i--)
printf("%2d",i);
for(i=1;i<=n;i++)
printf("%2d",i);
getch();

}
o/p:
Enter the range:5
5 4 3 2 1 0 1 2 3 4 5

43. /*Biggest And Smallest Elements Without Using Arrays */


main()
{
int n,i,l=0,s=999,a;
clrscr();
printf("\nEnter no.of elements");
scanf("%d",&n);
printf("\n Enter elements:");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a);
if(l<a)
l=a;
if(s>a)
s=a;
}
printf("Large=%d",l);
printf("\nSmall=%d",s);
getch();
}
44. /*Fibnacci Series Using For Loop */
main()
{
int a=0,b=1,fib,n,i;
printf("\nEnter no.of terms:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fib=a+b;
a=b;
b=fib;
printf("\t%d",fib);
}
}
45. /*Printing Table Using For Loop */
main()
{
int n,i,t=1;
clrscr();
printf("/nEnter a table:");
scanf("%d",&n);
for(i=1;i<=10;i++)

t=n*i;
printf("%2dX%2d=%d/n",n,i,t);

}
getch();

}
o/p:

Enter a table:5
5 X 1= 5
5 X 2=10
5 X 3=15
5 X 4=20
5 X 5=25
5 X 6=30
5 X 7=35
5 X 8=40
5 X 9=45
5 X10=50
46. /*Printing Table Using For Loop */
main()
{
int n,i,count=0;
clrscr();
printf("Enter number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
count++;
}
if(count==2)
printf("%d-Prime",n);
else
printf("%d-Not Prime",n);
}
o/p:
Enter number:958
958-Not Prime
Enter number:83
83-Prime
47. /*Printing Prime Numbers From 1 t0 100 Using For Loop */
main()
{
int i,j,count=0;
clrscr();
for(i=1;i<=100;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
count++;

}
if(count==2)
printf("%5d",i);
count=0;
}
}
o/p:
2
41
97.

3
43

5
47

7
53

11
59

13
61

17
67

19
71

23
73

48. /*Printing Prime Numbers From m t0 n Using For Loop */


main()
{
int m,n;
int i,j,count=0;
clrscr();
printf("Enter Starting Number:");
scanf("%d",&m);
printf("Enter Ending Number:");
scanf("%d",&n);
for(i=m;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
count++;
}
if(count==2)
printf("%5d",i);
count=0;
}
}
o/p:
Enter Starting Number:250
Enter Ending Number:275
251 257 263 269 271
49. /*Geometric Progression Using For Loop */
#include<stdio.h>
#include<math.h>
main()
{
int x,n,sum=0,i,t;
clrscr();
printf("\nEnter value for x:");
scanf("%d",&x);
printf("\nEnter value for n:");
scanf("%d",&n);
if(n>0)
{
goto xy;
}

29
79

31
83

37
89

else
{
printf("\nEnter non -ve exponent:");
scanf("%d",&n);
goto xy;
}
xy:
printf("\nGeometric Progression:\n");
for(i=0;i<=n;i++)
{
t=pow(x,i);
sum=sum+t;
printf("%d+",t);
}
printf("=%d",sum);
getch();
}
50. /*Finding Sum Of Array Elements*/
#include
main()
{
int a[10],i,s=0;
clrscr();
printf("Enter elements into array:");
for(i=0;i<=4;i++)
{
scanf("%d",&a[i]);
s=s+a[i];
}
printf("Sum of array elements=%d",s);
}
o/p:
Enter elements into array: 4 7 2 9 1
Sum of array elements=23
51. /*Finding Large And Small elements in Array*/
main()
{
int n,i,l=0,s=999,a[10];
clrscr();
printf("Enter Range:");
scanf("%d",&n);
printf("/n Enter elements:");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
if(l< a[i])
l=a[i];
else
s=a[i];
}
printf("Large=%d",l);

printf("/n Small=%d",s);

o/p:
Enter Range:5
Enter elements:52 58 0 -8 6
Large=58
Small=-8
52. /*Finding Sum of even and odd Nos in Array*/
main()
{
int n,i,ds=0,es=0,a[10];
clrscr();
printf("Enter Range:");
scanf("%d",&n);
printf("/n Enter elements:");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
if(a[i]%2==0)
es=es+a[i];
else
ds=ds+a[i];
}
printf("Even Nos Sum =%d",es);
printf("/nOdd Nos Sum=%d",ds);
}
o/p:
Enter Range:5
Enter elements:
1
2
3
4
5
Even Nos Sum =6
Odd Nos Sum=9
53. /*Sorting Array Elements*/
main()
{
static int a[10],n,i,j,temp;
clrscr();
printf("/n Enter no.of elements:");
scanf("%d",&n);
printf("/nEnter elements:");
for(i=0;i<=n-1;i++)
scanf("%d",&a[i]);
for(i=0;i<=n-1;i++)
{
for(j=i+1;j<=n-1;j++)
{
if(a[i]>a[j])
{

temp=a[i];
a[i]=a[j];
a[j]=temp;

}
printf("/nElements after sorting:");
for(i=0;i<=n-1;i++)
printf("%5d",a[i]);
getch();
}
o/p:
Enter no.of elements:5
Enter elements:9
8
0
-3
2
Elements after sorting:

-3

54./*Addition Of Matrices Using Arrays*/


main()
{
int i,j,r,c;
static int a[20][20],b[20][20],sum[20][20];
clrscr();
printf("Enter no.of rows:");
scanf("%d",&r);
printf("Enter no.of columns:");
scanf("%d",&c);
printf("Entet Matrix A:");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&a[i][j]);
}
printf("Enter Matrix B:");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&b[i][j]);
}
printf("Sum of two matrices=/n");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
{
sum[i][j]=a[i][j]+b[i][j];
printf("%4d",sum[i][j]);
}
printf("/n");
}

}
55.
/*Subtraction Of Matrices Using Arrays*/
main()
{
int i,j,r,c;
static int a[20][20],b[20][20],sum[20][20];
clrscr();
printf("Enter no.of rows:");
scanf("%d",&r);
printf("Enter no.of columns:");
scanf("%d",&c);
printf("Entet Matrix A:");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&a[i][j]);
}
printf("Enter Matrix B:");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&b[i][j]);
}
printf("Subtraction of two matrices=/n");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
{
sum[i][j]=a[i][j]-b[i][j];
printf("%4d",sum[i][j]);
}
printf("/n");
}
}
56. /*Multiplication Of Matrices Using Arrays*/
main()
{
int i,j,rA,cA,rB,cB,k;
static int a[20][20],b[20][20],mul[20][20];
clrscr();
printf("Enter no.of rows for Matrix A:");
scanf("%d",&rA);
printf("Enter no.of columns:");
scanf("%d",&cA);
printf("Enter no.of rows for Matrix B:");
scanf("%d",&rB);
printf("Enter no.of columns for Matrix B:");
scanf("%d",&cB);
if(cA!=rB)
printf("Matrix Multiplication Not Possible");
else
{
printf("Enter Matrix A:");
for(i=0;i<=rA-1;i++)
{
for(j=0;j<=cA-1;j++)
scanf("%d",&a[i][j]);
}

printf("Enter Matrix B:");


for(i=0;i<=rB-1;i++)
{
for(j=0;j<=cB-1;j++)
scanf("%d",&b[i][j]);
}
printf("Multiplication of two matrices=/n");
for(i=0;i<=rA-1;i++)
{
for(j=0;j<=cB-1;j++)
{
for(k=0;k<=rB-1;k++)
mul[i][j]=mul[i][j]+(a[i][k]*b[k][j]);
printf("%4d",mul[i][j]);
}
printf("/n");
}
}

57. /*Row And Column Sum in the Array*/


main()
{
static int a[10][10],b[10][10],rs[10],cs[10];
int i,j,r,c;
printf("/nEnter No.of rows:");
scanf("%d",&r);
printf("/nEnter No.of columns:"); scanf("%d",&c);
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
rs[i]=rs[i]+a[i][j];
printf("/n%d Row sum=%d",i+1,rs[i]);
}
for(j=0;j<=c-1;j++)
{

for(i=0;i<=r-1;i++)
cs[j]=cs[j]+a[i][j];
printf("/n%d Column Sum=%d",j+1,cs[j]);

}
}
o/p:
Enter No.of rows:2
Enter No.of columns:2
1 2
3 4
1 Row sum=3
2 Row sum=7
1 Column Sum=4

2 Column Sum=6
58./*Greatest Row Sum in the Array*/
main()
{
static int a[10][10],b[10][10],rs[10];
static int i,j,r,c,l;
clrscr();
printf("/nEnter No.of rows:");
scanf("%d",&r);
printf("/nEnter No.of columns:");
scanf("%d",&c);
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
rs[i]=rs[i]+a[i][j];
if(rs[i]>l)
l=rs[i];
}
printf("/n Greatest row sum=%d",l);

}
o/p:
Enter No.of rows:2
Enter No.of columns:2
1 2
3 4
Greatest row sum=7

59. /*Setting Diagonal Elements to 0 in C*/

main()
{
static int a[10][10];
static int i,j,r,c;
clrscr();
printf("/nEnter No.of rows:");
printf("/nEnter No.of columns:");
printf("/nEnter elements:");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)

scanf("%d",&r);
scanf("%d",&c);

if(i==j)
a[i][j]=0;
printf("%2d",a[i][j]);

}
printf("/n");
}

o/p:
Enter No.of rows:3
Enter No.of columns:3
Enter elements:
1 2 3
4 5 6
7 8 9
0 2 3
4 0 6
7 8 0
60. /*Identity Matrix Using Arrays*/
main()
{
static int a[10][10],b[10][10];
static int i,j,r,c;
printf("/nEnter No.of rows:");
scanf("%d",&r);
printf("/nEnter No.of columns:");
scanf("%d",&c);
printf("/nEnter elements:");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
{
if(i==j)
a[i][j]=1;
else
a[i][j]=0;
printf("%2d",a[i][j]);
}
printf("/n");
}
}
61. /*Transpose Of A Matrix*/
main()
{
static int a[10][10],b[10][10];
static int i,j,r,c;
clrscr();
printf("/nEnter No.of rows:");
scanf("%d",&r);

printf("/nEnter No.of columns:");


scanf("%d",&c);
printf("/nEnter elements:");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
{
b[i][j]=a[j][i];
printf("%2d",b[i][j]);
}
printf("/n");
}
}
62. /*Sample program to read given character using getchar()*/
main()
{
char s[50],c;
int i=0;
clrscr();
printf("/nEnter the string");
printf("/n*****Reading string*****/n");
c=getchar();
while(c!='/n')
{
s[i++]=c;
c=getchar();
}
s[i]='/0';
printf("/n*****Printing string*****/n");
i=0;
while(s[i]!='/0')
{
putchar(s[i]);
i++;
}
}
o/p:
Enter the string
*****Reading string*****
This is the first sample program in strings
*****Printing string*****
This is the first sample program in strings

63. /*Program to count vowels and consonents and the special characters in the text*/
#include<ctype.h>
main()
{

char s[20];
static int i,v,c,sc;
clrscr();
printf("/nEnter the string:");
gets(s);
for(i=0;s[i]!='/0';i++)
{
if(isalpha(s[i]))
{
if(s[i]=='a' || s[i]=='e' || s[i]=='i'||
s[i]=='o' || s[i]=='u')
v++;
else
c++;
}
esle
sc++;
}
printf("/nVowels=%d",v);
printf("/nConsonants=%d",c);
printf("/nSpecial Characters=%d",sc);
getch();
}
o/p:
Enter the string:this is the computer lab
Vowels=7
64. /*Program to count Number of lines, Words and characters in the text*/
#include<stdio.h>
main()
{
char str[81], ctr;
int i=0,c=0,words= 0,lines = 0;
clrscr();
printf("Enter the string:");
while(1)
{
while((ctr=getchar()) != '\n')
str[i++] = ctr;
str[i] = '\0';
if(str[0] == '\0')
break ;
else
{
words++;
for(i=0; str[i] != '\0';i++)
{
c++;
if(str[i] == ' ' || str[i] == '\t')
words++;
}
}
lines = lines +1;
}
printf("\nNumber of lines = %d\n", lines);

printf("Number of words = %d\n", words);


printf("Number of characters = %d\n", c);
getch();

65. /*Program to check the character in the text*/


main()
{
char s[100],c;
int i;
clrscr();
printf("/nEnter the string:");
gets(s);
printf("/nEnter character to search:");
scanf("%c",&c);
for(i=0;s[i]!='/0';i++)
{
if(s[i]==c)
{
printf("/n %c found at %d",c,i+1);
break;
}
}
if(s[i]=='/0')
printf("/n%c not found",c);
getch();
}
o/p:
Enter the string:this is c programming
Enter character to search:c
c found at 9
Enter the string:this is c programming
Enter character to search:d
d not found
66. /*Program to find number of occurances of a character
main()
{
char s[100],c;
int i,count=0;
clrscr();
printf("/nEnter the string:");
gets(s);
printf("/nEnter character to search:");
scanf("%c",&c);
for(i=0;s[i]!='/0';i++)
{
if(s[i]==c)
count++;
}
printf("/n%c found %d times",c,count);
getch();
}
o/p:
Enter the string:this is c programming

Enter character to search:m


m found 2 times

67. strlen()
68.strrev()
69.strcpy()
70.strcat()
71.strcmp()
72.strupr()
73.strlwr()
74. /*Finding String Length Without Using Library Function */
main()
{
char s[20];
static int i,len;
clrscr();
printf("/nEnter string:");
gets(s);
for(i=0;s[i]!='/0';i++)
len++;
printf("Length of the string=%d",len);
getch();
}
o/p:
Enter string:this is c programming
Length of the string=21
75. /*String Reverse Without Using Library Function */
main()
{
char s[100],c[100];
static int i,len,j;
clrscr();
printf("/nEnter string:");
gets(s);
len=strlen(s);
for(i=len-1;i>=0;i--)
{
c[j++]=s[i];
}
printf("Length of the string=%s",c);
getch();
}
o/p:
Enter string:this is c programming
Length of the string=gnimmargorp c si siht

76. /*String Copy Without Using Library Function */


main()
{
char s[100],c[100];
static int i,len;
clrscr();
printf("/nEnter string:");
gets(s);
for(i=0;s[i]!='/0';i++)
{
c[i]=s[i];
}
c[i]='/0';
printf("copied string=%s",c);
getch();
}
o/p:
Enter string:this is c programming
copied string=this is c programming
77. /*String Concatenation Without Using Library Function */
main()
{
char s[100],s1[100],c[100];
static int i,j;
clrscr();
printf("/nEnter first string:");
gets(s);
printf("/nEnter second string:");
gets(s1);
for(i=0;s[i]!='/0';i++)
c[i]=s[i];
for(j=0;s1[j]!='/0';j++)
c[i++]=s1[j];
c[i]='/0';
printf("string concatenation=%s",c);
getch();
}
o/p:
Enter first string:college
Enter second string:bus
string concatenation=collegebus.
78. /*Program to check whether the given string is palindrome or not*/
main()
{
char s[100],c[100];
static int i,j,len,count;
clrscr();
printf("/nEnter first string:");
gets(s);

len=strlen(s);
for(i=len-1;i>=0;i--)
c[j++]=s[i];
/*reversing two strings*/
c[i]='/0';
for(i=0;s[i]!='/0';i++)
{
if(s[i]==c[i])
/*Comparision of two strings*/
count++;
}
if(len==count)
printf("palindrome");
else
printf("Not palindrome");
getch();
}
o/p:
Enter first string:madam
palindrome
Enter first string:college
Not palindrome
79. /*Program to convert given string into uppercase*/
main()
{
char s[100],c[100];
static int i,j,len,count;
clrscr();
printf("/nEnter first string:");
gets(s);
for(i=0;s[i]!='/0';i++)
{
c[i]=(s[i]>='a' && s[i]<='z')?('A'+s[i]-'a'):s[i];
}
c[i]='/0';
printf("/nstring in uppercase:");
puts(c);
getch();
}
o/p:
Enter first string:this is c programming
string in uppercase:THIS IS C PROGRAMMING
80. /*Program to convert given string into lowercase*/
main()
{
char s[100],c[100];
static int i,j,len,count;
clrscr();

printf("/nEnter first string:");


gets(s);
for(i=0;s[i]!='/0';i++)
{
c[i]=(s[i]>='A' && s[i]<='Z')?('a'+s[i]-'A'):s[i];
}
c[i]='/0';
printf("/nstring in uppercase:");
puts(c);
getch();
}
O/P:
Enter first string:THIS IS C PROGRAMMING
string in uppercase:this is c programming
81. /*Inserting substring into original string*/
#include<string.h>
main()
{
char s[50],a[50],k[50];
int ls,as,p,i,j=0;
clrscr();
printf("\n Enter string:");
gets(s);
ls=strlen(s);
printf("\nEnter text to be inserted:");
gets(a);
as=strlen(a);
printf("\n Enter the position:");
scanf("%d",&p);
for(i=p;i<=ls;i++)
k[j++]=s[i];
for(i=0;i<=as;i++)
s[p++]=a[i];
strcat(s,k);
puts(s);
getch();
}
82. /*Deleting n-characters from the original string*/
#include<string.h>
main()
{
char s[50],a[50],k[50];
int ls,as,p,i,n,j;
clrscr();
printf("\n Enter string:");
gets(s);
ls=strlen(s);
printf("\n Enter no.of characters to delete:");
scanf("%d",&n);
printf("\nEnter the position:");
scanf("%d",&p);
j=n+p-1;
for(i=p-1;i<n-1||i<=ls;++i)

if(s[i]!=' ')
{
s[i]=s[j++];
}
else
{
s[i]=s[i+1];
s[i]=s[j++];
}

}
s[i]='\0';
printf("\nString after %d characters deletion
from %d position:",n,p);
puts(s);
getch();
}
o/p:
Enter string: This is beatiful world
Enter no.of characters to delete: 4
Enter the position:5
string after 4 characters deletion from 5 position:
thisbeatiful world.
83. Sorting Strings
main()
{
char s[20][100],temp[20];
static int i,j,n;
printf("/nEnter no.of strings:");
scanf("%d",&n);
for(;i<=n;i++)
gets(s[i]);
for(i=0;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(s[i],s[j])>0)
{
strcpy(temp,s[i]);
strcpy(s[i],s[j]);
strcpy(s[j],temp);
}
}
}
printf("/nstrings after sorting:");
for(i=0;i<=n;i++)
puts(s[i]);
}
84. Addition And Multiplication of Complex Numbers
#include<stdio.h>
struct complex
{
int real,img;
}comp,comp1;

main()
{
clrscr();
compread();
compwrite();
compadd();
compmul();
getch();
}
compread()
{
printf("\nEnter Complex No1:");
scanf("%d%d",&comp.real,&comp.img);
printf("\nEnter Complex No2:");
scanf("%d%d",&comp1.real,&comp1.img);
}
compwrite()
{
printf("\nFirst Complex Number:");
printf("%di%d\n",comp.real,comp.img);
printf("\nSecond Complex Number:");
printf("%di%d\n",comp1.real,comp1.img);
}
compadd()
{
struct complex cadd;
cadd.real=comp.real+comp1.real;
cadd.img=comp.img+comp1.img;
printf("\nAddtion of two complex nos:");
printf("%di%d",cadd.real,cadd.img);
}
compmul()
{
struct complex cmul;
cmul.real=(comp.real*comp1.real)-(comp.img*comp1.img);
cmul.img=(comp.real*comp1.img)+(comp.img*comp1.real);
printf("\nMultiplication of two complex nos:");
printf("%di%d",cmul.real,cmul.img);
}
85. /*Calculating Power Using Functions*/
main()
{
int b,p;
long int res;
clrscr();
printf("/nEnter base,power:");
scanf("%d%d",&b,&p);
res=power(b,p);
printf("/n%d^%d=%d",b,p,res);
getch();
}
/*power function*/
power(int b,int p)
{
long int i,res=1;

for(i=1;i<=p;i++)
res=res*b;
return res;

}
86. /*Amstrong Number Using Functions*/
main()
{
long int n;
clrscr();
printf("/nenter no:");
scanf("%ld",&n);
amstrom(n);
/*we are passing 'n' value as the argument
to the function amstrom and 'n' is the
actual argument*/
getch();
}
amstrom(a)
/*'a' is the formal argument and it gets the
value of 'n' */
int a;
{
int c,s=0,d;
c=a;
while(a!=0)
{
d=a%10;
s=s+(d*d*d);
a=a/10;
}
if(s==c)
printf("/nAmstrom number");
else
printf("/nNot amstrom number");
}
87. /*Finding Factorial Of A Number*/
main()
{
int n,f;
clrscr();
printf("/nEnter number:");
scanf("%d",&n);
f=fact(n);
printf("/n%d!=%d",n,f);
getch();
}
int fact(n)
int n;
{
int i,f=1;
for(i=n;i>=1;i--)
f=f*i;
return f;
}
88. /* Finding LCM of two numbers*/
#include<stdio.h>
main()

int a,b,l;
clrscr();
printf("/nEnter nos:");
scanf("%d%d",&a,&b);
l=lcm(a,b);
printf("Lcm=%d",l);
getch();

}
lcm(int a,int b)
{
int i=1;
while(1)
{
if(i%a==0 && i%b==0)
return i;
i++;
}
}
o/p:
Enter nos:35 50
Lcm=350
89. /*Finding GCD of two numbers*/
#include<stdio.h>
main()
{
int a,b,l;
clrscr();
printf("/nEnter nos:");
scanf("%d%d",&a,&b);
l=gcd(a,b);
printf("GCD=%d",l);
getch();
}
gcd(int a,int b)
{
int c=0;
while(1)
{
c=a%b;
if(c==0)
return b;
a=b;
b=c;
}
}
o/p:
Enter nos:200 800
GCD=200
90. /*Evaluating expression*/
#include<stdio.h>
#include<math.h>
main()

int x;
double sum=0;
clrscr();
printf("\nEnter x value:");
scanf("%d",&x);
sum=1-pow(x,2)/fact(2)+pow(x,4)/fact(4)-pow(x,6)/fact(6)
+pow(x,8)/fact(8)-pow(x,10)/fact(10);
printf("%f",sum);
getch();

/*fact function*/
fact(int f)
{
long int res=1,i;
for(i=1;i<=f;i++)
res=res*i;
return(res);
}
91. /*Matrices Addition Using Functions*/
#include<stdio.h>
main()
{
int i,j,r,c;
static int a[20][20],b[20][20];
clrscr();
printf("Enter no.of rows:");
scanf("%d",&r);
printf("Enter no.of columns:");
scanf("%d",&c);
printf("Enter Matrix A:");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&a[i][j]);
}
printf("Enter Matrix B:");
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
scanf("%d",&b[i][j]);
}
printf("\nSum of two matrices=\n");
matadd(a,b,c,r);
getch();
}
/*Addition function*/
int matadd(int a[20][20],int b[20][20],int c,int r)
{
static int sum[20][20],i,j;
for(i=0;i<=r-1;i++)
{
for(j=0;j<=c-1;j++)
{
sum[i][j]=a[i][j]+b[i][j];
printf("%4d",sum[i][j]);
}

printf("\n");

}
92. /*Matrices Multiplication Using Functions*/
#include<stdio.h>
main()
{
int ra,ca,rb,cb;
clrscr();
printf("Enter no.of rows for Matrix A:");
scanf("%d",&ra);
printf("Enter no.of columns:");
scanf("%d",&ca);
printf("Enter no.of rows for Matrix B:");
scanf("%d",&rb);
printf("Enter no.of columns for Matrix B:");
scanf("%d",&cb);
if(ca!=rb)
printf("Matrix Multiplication Not Possible");
else
matmul(ra,ca,rb,cb);
getch();
}
/*Matmul() function*/
matmul(ra,ca,rb,cb)
int ra,ca,rb,cb;
{
static int i,j,k,b[20][20],a[20][20],mul[20][20];
printf("Enter Matrix A:");
for(i=0;i<=ra-1;i++)
{
for(j=0;j<=ca-1;j++)
scanf("%d",&a[i][j]);
}
printf("Enter Matrix B:");
for(i=0;i<=rb-1;i++)
{
for(j=0;j<=cb-1;j++)
scanf("%d",&b[i][j]);
}
printf("Multiplication of two matrices=\n");
for(i=0;i<=ra-1;i++)
{
for(j=0;j<=cb-1;j++)
{
for(k=0;k<=rb-1;k++)
mul[i][j]=mul[i][j]+(a[i][k]*b[k][j]);
printf("%4d",mul[i][j]);
}
printf("\n");
}
}
93. /*Passing Array As An Argument Of A Function*/
main()

int n,i;
float a[10],res;
clrscr();
printf("/n enter no.of values");
scanf("%d",&n);
printf("/nenter values for array a:");
for(i=0;i<=n-1;i++)
scanf("%f",&a[i]);
res=sum(a,n);
printf("/nSum=%f",res);
getch();

}
sum(a,n)
float a[];
int n;
{
int j;
float s=0;
for(j=0;j<=n-1;j++)
s=s+a[i];
return s;
}
o/p:
enter no.of values5
enter values for array a:
2.5
6.2
2.3
1.2
5.8
Sum=18.000000
94./*What Happens When Formal Arguments Are More Than Actual Arguments*/
main()
{
int x,y,c;
clrscr();
printf("/nenter 2 nos:");
scanf("%d%d",&x,&y);
c=add(x,y);
printf("/nsum=%d",c);
getch();
}
int add(int a,int b,int c)
{
int s=0;
s=a+b;
printf("a=%d/tb=%d/tc=%d",a,b,c);
return s;
}
95. /*Finding Factorial Using Recurssion*/main()
{
int n;
clrscr();

printf("/nEnter number:");
scanf("%d",&n);
printf("/n%d!=%d",n,fact(n));
getch();
}
int fact(n)
int n;
{
if(n==0 || n==1)
return 1;
else
return (n*fact(n-1));
}
o/p:
Enter number:6
6!=720
96. /*Generating Fibnacci Series Using Recurssion*/
main()
{
int n,f,i;
clrscr();
printf("/nEnter no.of terms:");
scanf("%d",&n);
for(i=0;i<=n-1;i++)
printf("%5d",fibnacci(i));
getch();
}
/*fibnacci series*/
fibnacci(int n)
{
if(n==0 || n==1)
return 1;
else
return(fibnacci(n-1)+fibnacci(n-2));
}
o/p:
Enter no.of terms:12
1
1
2
3

13

97. /*GCD Using Recurssion*/


#include<stdio.h>
main()
{
int a,b,gcd;
clrscr();
printf("\nEnter two numbers:");
scanf("%d%d",&a,&b);
gcd=hcf(a,b);
printf("\nGCD of two nos:%d",gcd);
getch();
}
hcf(int x,int y)
{

21

34

55

89

144

int r,f;
r=x-(x/y * y);
if(r==0)
return(y);
else
f=hcf(y,r);
return f;

98. /*Addition Of Two Values Using Pointors in C*/


main()
{
int *a,*b,*c;
clrscr();
printf("/nEnter 2 values:");
scanf("%d%d",a,b);
*c=*a+*b;
printf("/nsum=%d",*c);
getch();
}
99. /*Comparing Two Values Using Pointors in C*/
main()
{
int *a,*b;
clrscr();
printf("/nEnter 2 values:");
scanf("%d%d",a,b);
if(*a>*b)
printf("/n%d is big",*a);
else
printf("/n%d is big",*b);
getch();
}

100. /*program to copy elements of array into another in reverse


order using pointors*/
main()
{
static int a[10],b[10];
int i,n=5,j;
clrscr();
printf("/nenter elements");
for(i=0;i<=n-1;i++)
scanf("%d",&a[i]);
for(i=0,j=n-1;i<=n-1,j>=0;i++,j--)
*(b+j)=*(a+i);
printf("/nElements in the reverse order");
for(i=0;i<=n-1;i++)
printf("/t%d",*(b+i));
getch();
}
o/p:

enter elements 2 3 5 6 0
Elements in the reverse order
0
6
5
3

101. /*program To check if a[0]=a[n-1], a[1]=a[n-2] so on in the array


of elements a[n]*/
main()
{
static int a[10];
int i,n=5;
clrscr();
printf("/nenter elements");
for(i=0;i<=n-1;i++)
scanf("%d",&a[i]);
for(i=0,j=n-1;i<=n-1,j>=0;i++,j--)
{
if(*(a+i)==*(a+j))
printf("/t%d",*(a+i));
}
getch();
}
(or)
main()
{
static int a[10];
int i,n=5;
clrscr();
printf("/nenter elements");
for(i=0;i<=n-1;i++)
scanf("%d",&a[i]);
for(i=0;i<=n-1;i++)
{
if(*(a+i)==*(a+(n-(i+1))))
printf("/t%d",*(a+i));
}
getch();
}
102. /*program To check if a[0]=a[n-1], a[1]=a[n-2] so on in the array of elements a[n]*/
main()
{
static int a[10];
int i,n=5,s=999;
clrscr();
printf("/nenter elements");
for(i=0;i<=n-1;i++)
scanf("%d",&a[i]);
for(i=0;i<=n-1;i++)
{
if(*(a+i)<s)
s=*(a+i);
}
printf("/tsmallest element in the array%d",s);
getch();
}

o/p:
enter elements
2
3
6
-6
-3
smallest element in the array-6
103. /*program To Reverse The String Using Pointors*/
#include<stdio.h>
main()
{
char *s,*c;
static int i=0,j=0,len;
clrscr();
printf("/nEnter string:");
gets(s);
len=strlen(s);
for(i=len-1;i>=0;i--)
{
*(c+j)=*(s+i);
j++;
}
*(c+j)='/0';
printf("/nReverse string:");
puts(c);
getch();
}
o/p:
Enter string:abc
Reverse string:cba

Potrebbero piacerti anche