You are on page 1of 51

1. Write a program to print the digit at 5.

Print the count of even numbers b/w 1 and


hundreds place in 4 digit number. 200.Also print their sum.
int a,s,h; int i,n=200,c=0,s=0;
pf(“enter a:”); for(i=1;i<=200;i++)
sf(“%d”,&a); { if(i%2==0)
s=a/100; { s=s+I;
h=s%10 c++;
pf(“%d”,h); }
2. convert Celsius to Fahrenheit. }
foat fahren,cel; printf(“Sum:”,s);
pf(“cel:”) pf(“count:”,c);
sf(“%d”,&cel); 6.Count a number of vowels in text.
fahren=(cel*9/5)+32; Int n,c=0;
pf(“fahren:”, fa); char a[20];
3.Print floating point value in exponential pf(“size:”);
format with 2 decimal places.
sf(“%d”,&n);
float fl;
pf(“String:”);
pf(“Enter:”);
for(i=0;i<n;i++)
sf(“%f”,&fl);
{ sf(“%c”,a[i]);
pf(“value %0.2f”,fl);
If(a[i]==’a’ || a[i]==’e’|| a[i]==’I’||
pf(“value:%0.2e”,fl); a[i]==’o’||a[i]==’u’||a[i]==’A’||a[i]==’E’||a[i]== ’I’||
a[i]==’O’||a[i]==’U’)
4 .write a program to read 10 integers.Display
thes numbers by printing three numbers in a c++;
line separated by comma.
}
int i,a[10];
Pf(“count:%d”,c);
for(i=0;i<10;i++)
7.Write a program to read a floating point
{ number.Display the right most digit of the
integer part.
pf(“Enter :”);
Float a=9986.65;
sf(“%d”,a[i]);
int c,r;
}
c=a;
for(i=0;i<10;i++)
r=c%10;
{ pf(“%d”,a[i]);
pf(“right digit:”,r);
If((i+1)%3!=0 && (i+1)!=10)
8. Write a program to calculate simple interest
printf(“,”); and compound interest.
else Int p,t;
printf(“\n”); float si,a,ci,r;
} pf(“Enter principal,time,rate:”)
sf(“%d%d%f”,&p,&t,&r);
si=p*t*r/100; n=n/2;
pf(“simple interest:”,si); i++;
a=p*pow((1+r/100),t); }
pf(“amount:”,a); for(j=i-1;j>=0;j--)
ci=a-p; pf(“Octal:”,binary[j]);
pf(“compound interest:”,ci); 12. Decimal to hexa decimal.
9.Program to display laegest of 5 numbers int n, i,r,j;
using ternary operator.
char hex[100];
int a,b,c,d,e,f,g,,h,i;
pf(“Enter no:”);
pf(“enter the numbers:”)
sf(“%d”,&n);
sf(“%d %d %d %d %d”,&a,&b,&c,&d,&e);
while(n>0)
f=a>b?a:b;
{
g=c>d?c:d;
r=0;
h=f<g?f:g;
r=n%16;
i=h>e?h:e;
if(r<10)
pf(“largest number is %d”,i);
{
10. Decimal to binary
hex[i] = 48 + r;
int i=0,j, n;
i++;
pf(“enter number:”);
}
sf(“%d”,&n);
Else
int binary[32];
{
while(n>0)
hex[i]=48+55;
{
i++;
binary[i]=n%2;
}
n=n/2;
n=n/16;
i++;
}
}
for(j=i-1;j>=0;j--)
for(j=i-1;j>=0;j--)
pf(“Hexa:”,hexa[j]);
pf(“binary:”,binary[j]);
13. Binary to decimal
11. Decimal to octal
long long n;
int i=o, j ,n;
int d=0,i=0,r;
int binary[32];
pf(“Enter no:”,);
pf(“enter no:”);
sf(“%d”,&n);
sf(“%d”,&n);
while(n>0)
while(n>0)
{
{
r=n%10;
Binary[j] = n%8;
n= n/10;
d=d+r*pow(2,i); (hex[i]>=’A’ && hex[i]<=’F’)
++I; {
} D=d+(hex[i]-55)*base;
Pf(“Decimal:”,d); Base = base*16;
14. octal to decimal }
Long long n; Pf(“Decimal:”,d);
Int i=0,r,d=0; 16. GCD of two numbers
pf(“Enter no:”,); Int n1,n2,I,gcd;
sf(“%d”,&n); Pf(“Enter n1:”)
while(n>0) Sf(“%d”,&n1);
{ Pf(“Enter n2:”);
r=n%10; Sf(“%d”,&n2);
n=n/10; For(i=1;i<=n1 && i<=n2; ++i)
d=d+r*pow(8,i); {
++i; If(n1%i==0 && n2%i == 0)
} Gcd=I;
pf(“Decimal:”,d); }
15. Hexa decimal to decimal Pf(“GCD of two numbers:%d”,gcd);
int I,b,=1,len, d=0,n; 17. Program to read a floating point number
and an integer .If the value of the floating point
char hex[32]; number is 3.14 then add 10 to the integer.
pf(“Enter the no of elements:”); Float a;
sf(“%d”,&n); Int b;
pf(“enter no:”); Pf(“Enter a :”);
for(i=0;i<n;i++) Sf(“%d”,&a);
{ Pf(“Enter b:”);
Sf(“%d”,&hex[i]); Sf(“%d”,&b);
} If(a>3.14)
Len= strlen(hex); B=b+10;
For(i=len-1;i>=0;i--) Pf(“a=%d,b=%d”,a,b);
{ 18. Program to print the prime factors of the
If(hex[i]>=’0’ && hex[i]<=’9’) numbers.

{ int i, j, num, isPrime;

D=d+(hex[i]-48)*base;
/* Input a number from user */
Base = base *16; printf("Enter any number to print Prime
factors: ");
} scanf("%d", &num);
Else if
printf("All Prime Factors of %d are: \
{ n", num);
20. Print the Floyd’s triangle.
/* Find all Prime factors */
for(i=2; i<=num; i++) Int n,a=1;
{ Pf(“Enter the no rows:”);
/* Check 'i' for factor of num */
if(num%i==0) Sf(“%d”,&n);
{
/* Check 'i' for Prime */ For(i=1;i<=n;i++)
isPrime = 1;
{
for(j=2; j<=i/2; j++)
{ For(j=1;j<=I;j++)
if(i%j==0)
{ {
isPrime = 0;
Pf(“%d”,a);
break;
} a++;
}
}
/* If 'i' is Prime number and
}
factor of num */
if(isPrime==1) O/P
{
printf("%d, ", i); 1
}
}
23
} 456

19. Check given number is power of two. 7 8 9 10

int num; 11 12 13 14 15

pf(“Enter the no:”); 21.Write a program to read two numbers then


find whether the first number is multiple of the
sf(“%d”,&num); second number.
if(check(num)==1) Int a,b;
Pf(“\n %d is the power of 2\n”); Pf(“Enter no 1:”);
Else Sf(“%d”,&a);
Pf(“\n %d is not a power of 2\n”); Pf(“Enter no 2:”);
Int check(int x) Sf(“%d”,&b);
{ If(a%b==0)
If(x==0) Pf(“%d is multiple of %d”,a,b);
Return 0; Else
While(x!=1) Pf(“%d is not a multiple of %d”);
{ 22. Write a program using switch case to
If(x%2!=0) express a menu that offers 5 options: read
three numbers, calculate total, calculate
Return 0; average, display the smallest, and display the
largest value.
Else
Int a,b,c,s,n;
Return 1;
Pf(“1.Read three numbers\n2.Calculate total\
X=x/2; n3.calculate average\n4.display the smallest\n5.
} Display the largest”);
Pf(”Enter the option:”);
Sf(“%d”,&n); {
Switch(n) p = 1;
{
fact = 1;
Case 1:pf(“Enter 3 numbers:”);
for (j = 1; j <= i; j++)
Sf(“%d %d %d”,&a,&b,&c);
Case 2: s=a+b+c; {

Pf(“Total:”,s); p = p * x;

Case 3:av=a+b+c/3; fact = fact * j;

Pf(“Average:”,av); }
Case 4: if(a<b) sign = - 1 * sign;
{ if(a<c)
sum += sign * p / fact;
pf(“Small:”,a);
}
if(c<b)
printf("sin %0.2f = %f", x, sum); return 0;
pf(“Small:”,c);
}
}
Else 24. Write a program to display the sin(x) value
where x ranges from 0 to 360 in steps of 15.
Pf(“Small:”,b);
#include<math.h>
Case 5: if(a>b)
#include<stdio.h>
{ if(a>c)
Pf(“Large:”,a); Void main()

Else If(c>b) {
Pf(“Large:”,c); Int i=0;
} While(i<=360)
Else {
Pf(“Large:”,b);
Pf(“sin(%d)=%d \n”,I,sin(i));
23.Write a program to display the sin(x) value
where x ranges from 0 to 360 in steps of 15. i=i+15; (i=i+45)

#include <stdio.h> }

int main() }

{ 25. Write a program to display the cos(x) and


tan(x) value where x ranges from 0 to 360 in
int i, j, n, fact, sign = - 1; float x, p, sum = 0; steps of 15.
printf("Enter the value of x :");
#include<math.h>
scanf("%f", &x);
#include<stdio.h>
printf("Enter the value of n :");
Void main()
scanf("%d", &n);
{
for (i = 1; i <= n; i += 2)
Int i=0;
While(i<=360) }
{ 27. Write a program that accepts the current
date and date of birth of the user. Then
Pf(“sin(%d)=%d \n”,I,cos(i));
calculate the age of the user and display it on
Pf(“sin(%d)=%d \n”,I,tan(i)); the screen.

i=i+15; (i=i+45) Int main()

} {

} Int present_date = 14;

26. Write a program to read an angle from the Int present_month = 3;


user and then display its quadrant.
Int present_year = 2021;
int angle;
Int birth_date = 2;
pf(“Enter an angle:”);
Int birth_month = 8;
sf(“%d”,&angle);
Int birth_year = 2001;
if(angle>0 and angle<90)
Age(present_date,present_month,present_year,bir
pf(“I quadrant”); th_date,birth_month,birth_year);

else if(angle>90 && angle<180) Return 0;

pf(“II quadrant”); }

else if(angle>180 && angle<270) Void age(int present_date,int present_month, int


present_year, int birth_date, int birth_month,int
pf(“III quadrant”); birth_year)
else if(angle>270 && angle<360) {
pf(“IV quadrant”); Int moth[] =
else if(angle%90==0) {31,28,31,30,31,30,31,31,30,31,30,31};

switch(angle/90) If(birth_date > present_date)

{ {

Case 0:pf(“X axis”); Pesent_date= present_date + month[birth_date-


1];
Break;
Present_month=present_month-1;
Case 1:pf(“Y axis”);
}
Break;
If(birth_month.present_month)
Case 2:pf(“X axis”);
{
Break;
Present_year=present_year -1;
Case 3:pf(“Y axis”);
Present_month= present_month + 12;
Break;
}
Case 4:pf(“X axis”);
int date = present_date – birth_date;
Break;
int month = present_month – birth_month;
Default:pf(“angle invalid”);
int year = present_yesr – birth_year;
Break;
pf(“Present Age\n Years:%d\n Months:%d\n Days: S=s+I;
%d”,year , month, date);
}
}
Pf(“Sum:”,s);
28. A class has 50 students. Every students is
31. Write a program to read an integer. If it is
supposed to give two examinations. Write a
positive then display the corresponding binary
program to read the marks obtained by each
representation of that number.Incase the user
student in all three examinations. Calculate
enters a negative number then ignore that
and display total marks and average of the
input and ask the user to re-enter any different
each student.
number.
Int I;
int i=0,j, n;
Float m, p, c, total, avg;
pf(“enter number:”);
For(i=1;i<=50;i++)
sf(“%d”,&n);
{ while(n!=999)
Pf(“Enter maths marks of %d:”,i); {
Sf(“%f”,&m); if(n>0)
Pf(“Enter physics marks of %d:”,i); binary(n);
Sf(“%f”,&p); if(n<0)
Pf(“Enter chemistry marks of %d:”,i); negative(n);
Sf(“%f”,&c); }

Toal = m + p + c; int binary(int n)

Avg = total/3; {

Pf(“ Total marks of student %d:”,I,total); int binary[32];

Pf(“Average of student %d:”,I,avg); while(n>0)


{
}
binary[i]=n%2;
29. Write a program that displays all the
numbers from 1 to 100 that are not divisible by n=n/2;
2 as well as by 3.
i++;
Int I,s=0;
}
For(i=1;i<=100;i++) for(j=i-1;j>=0;j--)
{ pf(“binary:”,binary[j]);
If(i%2!=0 && i%3!=0) }
Pf(“%d”,i); Int negative(int n);
} {
30. Sum of all odd numbers from 1 to hundred. Pf(“Enter other number:”);
Int I; Sf(“%d”,&n);

For(i=1;i<=100;i++) }

{ 32. Print 20 asterisks.

If(i%2!=0) Int I;
For(i=1;i<=20;i++) Else
{ Pf(“ “);
Pf(“*”); }
} }
33. Print number of digits in the number. }
Int n,c=0, r; 35. Generate a Pattern
Pf(“Enter the number:”); $****
Sf(“%d”,&n); *$ *
While(n!=0) * $ *
{
* $*
R=n%10;
****$
N=n/10;
Int I,j;
C++;
For(i=1;i<=5;i++)
}
{
Pf(“Number of digits:”,c);
For(j=1;j<=5;j++)
34. Generate the pattern.
{
*****
If(i==1 || i==5)
* *
{
* *
If(i==j)
* *
Pf(“$”);
*****
Else
Int I;
Pf(“*”);
For(i=1;i<=5;i++)
}
{
Else
If(i=1 || i=5)
{
{
Pf(“ “);
For(j=1;j<=5;j++)
}
{
}
Pf(“*”);
}
}
36. Generate the pattern.
}
$***$
Else
*$ $*
{
* $ *
For(j=1;j<=5;j++)
*$ $*
{
$***$
If(j=1 or j=5)
Int I,j;
Pf(“*”);
For(i=1;i<=5;i++) 37. Write programs to implement the following
sequence of numbers.
{
1,8,27,64,…
For(j=1;j<=5;j++)
Int,I,s;
{
For(i=1;i<=10;i++)
If(i==1 || i==5)
{
{
S=i*i*I;
If(j==1)
Pf(“%d,”,s);
Pf(“$”);
}
Else if(j==5)
-6,-3,0,3,6,9,…
Pf(“$\n”);
Int I,n,s;
Else
Pf(“Enter starting number:”,n);
Pf(“*”);
Sf(“%d”,&n);
}
For(i=1;i<=20;i++)
Else if(i==2 || i==4)
{
{
S=n+3;
If(j==2 || j==4)
Pf(“%d”,s);
Pf(“$”);
N=s;
Else if(j==1)
}
Pf(“*”);
-2,-4,-6,-8,-10,-12,…
Else if(j==5)
Int I,n,s;
Pf(“*\n”);
Pf(“Enter starting number:”,n);
Else
Sf(“%d”,&n);
Pf(“ “);
For(i=1;i<=20;i++)
}
{
Else
S=n-2;
{
Pf(“%d”,s);
If(j==1)
N=s;
Pf(“*”);
}
Else if(j==5)
38. Write a program that reads integers until
Pf(“*\n”); the user wants to stop. When the user stops
Else if(j==3) entering numbers, display the largest of all the
numbers entered.
Pf(“$”);
Int n,l,s;
Else
Pf(“Enter any number,enter -1 to stop:”);
Pf(“ “);
Sf(“%d”,&n);
}
Printf(“Second number:”);
}
Sf(“%d”,s);
}
While(n!=-1) C++;
{ }
If(n>s) If(c==5)
{ {
L=n; For(i=n;i>=1;--i);
S=l; {
} For(j=1;j<=I;++j)
Else {
{ Printf(“*”);
L=s; }
S=l; Pf(“\n”);
} }
Print(“Enter any number,enter -1 to stop:”); }
Sf(“%d”,n); 40. Print the following pattern.
} 1
Printf(“Largset number is %d”,l); 212
} 32123
39. Print the following pattern. Int I;
* For(i=1;i<=3;i++)
** {
*** If(i==1)
**** {
***** Pf(“%d\n”,i);
**** }
*** Else if(i==2)
** {
* Pf(“%d%d%d\n”,I,i-1,i);
Int I,j,n,c=0; }
Printf(“Enter no of rows:”) Else if(i==3)
Sf(“%d”,&n); {
For(i=1;i<=n;i++) Pf(“%d%d%d%d%d”,I,i-1,i-2,i-1,i);
{ }
For(j=1;j<=I;j++) }
{ 41. Print the pattern.
Pf(“*”); 12345
} 2345
Pf(“\n”); 345
45 }
5 Pf(“%d”,fact);
Int I,j,n; With recursion
Printf(“Enter the no of rows:”); main()
Sf(“%d”,&n); {
For(i=1;i<=n;i++) Int n;
{ Pf(“Enter the no:”);
For(j=I;j<=n;j++) Sf(“%d”,&n);
{ F=fact(n);
Pf(“%d”,j); Pf(“Factorial:%d”,f);
} Return 0;
Printf(“\n”); }
} Int fact(num);
42. Print the pattern. If(n==1)
1 Return 1;
12 Else
123 Return(n*fact(n-1))
1234 }
12345 44. Write a program using function that
calculates the hypotenuse of a right-angled
Int I,j,n; triangle.
Printf(“Enter the no of rows:”); Main()
Sf(“%d”,&n); {
For(i=1;i<=n;i++) Float side1,side2,result;
{ Pf(“side1:”);
For(j=1;j<=I;j++) Sf(“%f”,&side1);
{ Pf(“side2:”);
Pf(“%d”,j); Sf(“%f”,&side2);
} Result=hypotenuse(side1,side2);
Pf(“\n”): Pf(“%d”,result);
} }
43. Factorial without recursion Int hypotenuse(float side1,float side2)
Int n,I,fact=1; {
Pf(“Enter the no:”); Float h;
Sf(“%d”,&n); H=sqrt((side1*side1)+(side2* side2))
For(i=n;i>=1;i--) Return h;
{ }
Fact=fact*I;
45. Write a function that accept a number n as {
input and returns the average of numbers from
1 to n. Flag=1;

Main() Break;

{ }

Int n,a; }

Pf(“n=”); If(n==1)

Sf(“%d”,&n); {

A=average(n); Pf(“neither prime nor composite”);

Pf(“Average:%d”,a); }

} Else{

Int average(int n) If(flag==0)

{ Return 1;

Int s=0,r; Else

For(i=1;i<=n;i++) Return 0;

{ }

S=s+I; }

} 47.Write a program to concatenate two strings


using recursion.
R=s/n;
#include<string.h>
Return r;
Stringconc(cahar *s1,char *s2)
}
{
46. write a function is_prime that returns 1 if
the argument passed to it is a prime number Static int I,j;
and a 0 otherwise. J=strlen(s1);
If(!s2[i])
Main() {
{ S2[i]=’\0’;
Int n,p; }
Pf(“Enter the no:”); Else
Sf(“%d”,&n); {
P=Is_prime(n); S1[i+j]=s2[i];
Pf(“%d”,p); I++;
} Stringconc(s1,s2);
Int is_prime(int n) }
{ }
For(i=2;i<=n/2;++i) Int main()
{ {
If(n%i==0) Char s1[1000],s2[1000];
Pf(“s1:”); ********
Gets(s1); Int I,j;
Pf(“s2:”); For(i=0;i<=5;i++)
Gets(s2); {
Stringconc(s1,s2); If((i==1)||(i==5))
Pf(“Combine=’%s’\n”,s1); {
Return 0;
For(j=1;j<=8;j++)
}
{
48. Write a program to read an integer number.
Print the reverse of this number using Printf(“*”);
recursion. }
int sum=0,rem; Pf(“\n”);
reverse_fun(int num)
}
{
Else
If(num)
{
{
For(j=1;j<=8;j++)
Rem=num%10;
{
Sum=sum*10+rem;
If(j==1)
Reverse_fun(num/10);
Pf(“!”);
}
Else if(j==8)
Else
Pf(“!\n”);
Return sum;
Else
Return sum;
Pf(“ “);
}
}
Void main()
{ }

Int num,reverse_n; }

Pf(“numbe:”); 50. first hal ascending order second half


decending order.
Sf(“%d”,&num);
#include <stdio.h>
Reverse_n=reverse_fun(num);
#include <string.h>
Pf(“Reverse”%d”,string_n);
#include <math.h>
}
#include <stdlib.h>
49.Print the following pattern.
int main() {
********
int a[10],i,j,n,mid,beg,end,temp;
! !
scanf("%d",&n);
! !
for(i=0;i<n;i++)
! !
{
scanf("%d",&a[i]); For(i=0;i<n;i++)
} {
beg=0; Scanf(“%d”,&a[i]);
end=n-1; }
mid=(beg+end)/2; Max=a[0];
for(i=0;i<n;i++){ For(i=0;i<n;i++)
for(j=i+1;j<n;j++) {
{ If(a[i]>max)
if(i<mid) {
{ Max=a[i];
if(a[i]>a[j]) }
{ }
temp=a[i]; Y=max+1;
a[i]=a[j]; For(i=0;i<n;i++)
a[j]=temp; {
} For(j=i+1;j<n;j++)
} {
if(i>mid) If(a[i]==a[j])
{ {
if(a[i]<a[j]) A[i]=y;
{ A[j]=y;
temp=a[i]; }
a[i]=a[j]; }
a[j]=temp; For(i=0;i<n;i++)
} {
} If(a[i]!=y)
} {
} Printf(“%d “,&a[i]);
for(i=0;i<n;i++) }
{ }
printf("%d ",a[i]); 52. Print the count of duplicate elements.
} Int n,a[i],j,max,count;
return 0; Scanf(“%d”,&n);
} For(i=0;i<n;i++)
51.Delete duplicate elements in array {
Int n,a[10],I,j,max,y; Scanf(“%d”,&a[i]);
Scanf(“%d”,&n); }
Max=a[0]; Int max=a[i];
For(i=0;i<n;i++) For(in p=i+1;p<=j;p++)
{ If(a[p]>max)
If(a[i]>max) Max=a[p]
{ Printf(“max);
Max=a[i];
} 54. Input{5287439}
} Output{9,2,8,3,7,4,5} (min and max order)
Y=max+1; Int a[10,I,j,k,n;
For(i=0;i<n;i++) //get an array
{ //sorting
Count=1; For(int i=0,j=n-1;i<j;i++,j--)
If(a[i]!=y) {
{ Printf(“%d”,a[j]);
For(j=i+1;j<n;j++) Pf(a[i])
{ }
If(a[i]==a[j]) If(n%2==1)
{ Int k=n/2;
Flag=1; Pf(a[k]);
A[j]=y; //another way hashing technique
Count++; //get an array
} //find max
} //Copy to b array
Printf(“%d -> %d”,a[i],count); //make entire array 0
} Y=max+1;
} For(i=0;i<n;i++)
{
53.Input-{3,4,5,2,6,8,9,6,7} k=3 K=a[i];
Like{3,4,5} {4,5,2} B[k]++;
Output{5,5,6,8,9,9,9} }
int I,a[10],n,I,j,k=3,p,max; for(int i=0,j=max,i<j;i++,j--)
scanf(“%d”,&n); {
for(i=0;i<n;i++) While(b[j]==0)
{ {
Scanf(“%d”,&a[i]); j--;
} }
For(inti=0;j=k-1;i<n;i++,j++) While(b[i]==0)
{ {
I++; Printf(“%d “,a[i]);
} }
If(i<j) }
{ For(i=0;i<n;i++)
Pf(“%d”,j); {
Pf(“%d”,i); If(b[i]!=y)
} {
if(i==j) Pf(“%d “,b[i]);
pf(“%d”,i); }
} }
55. Input A-{1,3,4,5,6,7} 56. array left rotation
b-{2,6,5,8,9,10} //get an array
output{3,4,8,9,10} Scanf(“%d”,&k);
While(k)
//get array1 {
//get array2 Y=a[n-1];
//find max1 For(i=n-1;i>0;i--)
//find max2 A[i]=a[i-1];
If(max1>max2) A[0]=y;
Y=max1+1; K--;
Else }
Y=max2+1; //print the array
For(i=0;i<m;i++)
{ 57. Array right rotation.
For(j=0;j<n;j++) //get an array
{ Scanf(“%d”,&k);
If(a[i]==b[j]) While(k)
{ {
A[i]=y; Y=a[0];
B[j]=y; For(i=0;i<n;i++)
} A[i]=a[i+1];
} A[n-1]=y;
} k--;
For(i=0;i<m;i++) }
{ //print the array
If(a[i]!=y)
58. check two arrays equal or not. //find max and min in one for loop
//get aaray1 For(i=0;i<n;i++)
//get array 2 {
If(n1!=n2) For(j=i+1;j<n;j++)
Pf(“not equal”); {
For(i=0;i<n1;i++) If(((a[j]==max) &&(a[i]==min)) ||
((a[j]==min)&&(a[i]==max)))
{
{
For(j=0;j<n;j++)
Temp=a[i];
{
A[i]=a[j];
If(a[i]==b[j])
A[j]=temp;
Flag++;
}
}
}
}
}
If(flag==n1)
61. Write a program to interchange second
Pf(“Equal”); element with the second last element.
Else // get an array
Pf(“not equal”); Temp=a[1];
59. Write apgm that reads an array of 100 A[1]=a[n-2];
integers.Display all pairs of elements whose
sum is 50. A[n-2]=a[1];
For(i=0;i<n;i++) 62. Write a program to calculate sum of
squares of the elements.
{
//get an array
A[i]=i+1;
For(i=0;i<n;i++)
}
{
For(i=0;i<n;i++)
Y=(a[i]*a[i]);
{
Sum+=y;
For(j=I;j<n;j++)
}
{
63. Print even numbers precede odd numbers
If(a[i]<50) in araay.
{ //get an array
If((a[i]+a[j])==50) Int j=0,i=0,k=0,i_even=0.i_odd=0;
Pf(“%d + %d=50”,a[i],a[j]); For(i=0;i<n;i++)
} {
} If(a[i]%2==0)
} Even[j]=a[i];
60. Write a program to input an array and swap J++;
the max element and min element.
Else
//get an array
Odd[k]=a[i]; 5 {3,2} 2
K++; 3 {3} 1
} 4 {3,1} 2
While(i_even<=j &&i_odd<=k) 5 {3,2} 2
{ 6 {3,3} 2
If(i_even<j) 9 {3,3,3} 3
{ Threshold=3 o/p count=17
Pf(“%d “,even[i_even]); int a[10],n,i,threshold,sum=0;
I_even++; printf("size:");
} scanf("%d",&n);
If(i_odd<k) for(i=0;i<n;i++)
{ {
Pf(“%d “,odd[i_odd]); scanf("%d",&a[i]);
I_odd++; }
} printf("Threshold:");
} scanf("%d",&threshold);
64. Write a program to calc the for(i=0;i<n;i++)
sum ,mean,variance and standard deviation of
the numbers in the array. {

//get an array sum+=a[i]/threshold;

//calc sum and avg(mean) if((a[i]%threshold)!=0)

For(i=0;i<n;i++) sum+=1;

{ }

Sum1+=(x[i]-avg)*(x[i]-avg); printf("Count=%d",sum);

} return 0;

Variance=sum1/2; 66. Input {2,-3,-4,5,9,7,8}

Standar_dev=sqrt(sum1); o/p 2 5 9

//sqrt without inbuild function if element is greater than all previous elements.

Sqrt=num/2;
Temp=0; int a[10],n,i,j,flag=0;

While(sqrt!=temp) printf("size:");

{ scanf("%d",&n);

Temp=sqrt; for(i=0;i<n;i++)

Sqrt=(num/temp + temp)/2; {

} scanf("%d",&a[i]);

Pf(“%d”,sqrt); }

65. Input{5,3,4,5,2,6,9} printf("%d",a[0]);


for(i=1;i<n;i++)
{ }
flag=0; }
for(j=0;j<i;j++) if(a[i]==max){
{ printf("%d<,",max);
if(a[i]<a[j]) }
{ }
flag++; return 0;
break;
} 68. N=18
} Input{2,4,3,6,12,7,1}
if(flag==0) o/p 6+12=18
{ //get an array
printf("%d ",a[i]); For(int i=0;i<n-1;i++)
} {
} Sum=a[i];
67.Input-{2,6,5,3,1,8,7} For(j=i+1;j<n;j++)
o/p 2<3,6<7,5<6,3<5,1<2,8<,7<8 {
imeediate greatest element of the number.
//get an array Sum+=a[j];
//find maximum If(sum==N)
n2=max+1; Pf(“%d +%d=%d”,a[i],a[j],N);
for(i=0;i<n2;i++){ Else
b[i]=0; Sum-=a[j];
} }
for(i=0;i<n;i++) }
{ 69. replace 0s to 1s and 1s to 0s in given
integer.
b[a[i]]++;
Int a,h,count=0,
}
Scanf(“%d”,&a);
for(i=0;i<n;i++)
//convert integer to array
{
H=a;
k=a[i];
While(h)
for(j=k+1;j<n2;j++)
{
{
Count++;
if(b[j]!=0)
N=n/10;
{
}
printf("%d<%d,",k,j);
Int a[count];
break;
Int j=count-1; Longint c=a+b;
While(a) //print c like an array
{ longInt d=c;
Int k=a%10; Int digit=0;
A[j]=k; While(d)
j--; {
a=a/10; Digit++;
} D=d/10;
For(i=0;i<count;i++) }
{ Int result[digit];
Int y=a[i]; Int j=digit-1;
If(y==1) While(c)
Pf(“0”); {
Else Int k= c%10;
Pf(“1”); Result[j]=k;
} j--;
c=c/10;
70.A={9 2 8 1 3 5 6 7 3 1 1 6} }
B={7 8 4 6 2 1 9 9 7} For(i=0;i<digit;i++)
Add both array like integer and the result is 9 2 Printf(“%d “,result[i]);
8920295113
71. Find the second maximum element without
//get array 1 sorting or hashing (i.e no O(n^2))
//get array2 //get an array
//convert array1 to integer Int min=a[0];
Long int a=0; For(int i=1;i<n;i++)
For(i=0;i<n1;i++) {
{ If(min>a[i])
K=a[i]; Min=a[i];
A=(a*10)+k; }
} Int y=min-1;
//convert array2 to integer Int max1=0;
Longint b=0; Int h=2;
For(i=0;i<n2;i++) While(h){
{ Int max=a[0];
Int k=b[i]; Int index=0;
B=(b*10)+k; For(int i=1;i<n;i++){
} If(max<a[i]){
Max=a[i]; }
Index=I; }
} for(i=0;i<m;i++){
} for(j=0;j<n;j++){
A[index]=y; printf("%d ",a[i][j]);
Max1=max; }
For(int i=0;i<n;i++){ printf("\n");
If(max==a[i]){ }
A[i]=y; for(i=0;i<m;i++){
} for(j=0;j<n;j++){
} if(i==j){
h--; sum=sum+a[i][j];
} }
Printf(“%d”,max1); }
Return 0; }
} printf("%d",sum);
//hashing method
//get an array 73. Input 1 3 9 7 8 2 5 6
//Store in array b[a[i]] Output
Int count=0; //get an array
Int index=0; //sorting
For(int i=max;i>=0;i--){ //finding the maximum continuous occurance.
If(b[i]!=0){ int maxcount=0;
Count++; int count=1;
Index=i; for(int i=1;i<n;i++){
} if(a[i-1]==a[i]-1){
If(count==2){ count++;
Pf(“%d”,index); if(i==(n-1)){
} if(maxcount<count)
} maxcount=count;
72. sum of diagonal elements in square matrix. }
int a[5][5],i,j,m,n,sum=0; }
scanf("%d",&m); Else{
scanf("%d",&n); If(maxcount<count)
for(i=0;i<m;i++){ Maxcount=count;
for(j=0;j<n;j++){ Count=1;
scanf("%d",&a[i][j]); }
} If((k%b[i]==0){
int count=1; Flag=0;
int end=0; For(m=2;m<j;m++){
for(int i=1;i<n;i++){ If(j%m==0){
if(a[i-1]==a[i]-1){ Flag++;
count++; Break;
if(i==(n-1)){ }
if(maxcount<count){ }
end=I; If(flag==0){
for(int k=end-maxcount+1;k<=end;k+ Printf(“%d”,j);
+){
Break;
printf(“%d “,a[k]);
}
}
}
}
}
}
}
}
Else{
75. Input 16 17 4 3 5 2
If(maxcount<count){
Output 17 5 5 5 2 -1
End=i-1;
Maximum element from current element.1
For(int k=end-maxcount;k<=end;k++){
(16…(max)),(17(max)),…..
Printf(“%d “,a[k]);
int a[10],i,j,n,max;
}
scanf("%d",&n);
Printf(“\n”);
for(i=0;i<n;i++){
}
scanf("%d",&a[i]);
Count=1;
}
}
for(i=0;i<n;i++){
}
max=a[i+1];
74. //Input [20,7]
for(j=i+1;j<n;j++){
[11,5]
if(a[j]>max){
Output [2,3]
max=a[j];
(20+2)%11=0
}
(7+3)%5=0
}
//get two arrays
printf("%d ",max);
//check prime
}
For(i=0;i<n;i++){
return 0;
For(j=1;j<1000;j++){
76. Input 4 3 5 6 7 8 1 9 7 2 1
Int k=a[i]+j;
Output 2 1 4 3 5 1 9 7 6 7 8 }
Print kth no.of elments. return 0;
If k=2 divide 2 index, and print front part…and }
back part vice versa.
77. Print maximum contiguous sum.
int main() {
int main() {
int a[15],i,n,g=0,k;
int a[10],n,i,j=0,m=0,l=0,max=0,sum;
scanf("%d",&n);
scanf("%d",&n);
for(i=0;i<n;i++){
for(i=0;i<n;i++){
scanf("%d",&a[i]);
scanf("%d",&a[i]);
}
}
scanf("%d",&k);
for(i=0;i<n;i++){
int y=n%k;
sum=0;
if(y!=0){
for(j=i;j<n;j++){
for(i=n-y;i<n;i++){
sum=sum+a[j];
printf("%d ",a[i]);
if(sum>max){
}
max=sum;
}
m=i;
i=0;
l=j;
int j=k-1;
}
int q=n-k;
}
int h=n-y-k;
}
while(i<h && j<q){
for(i=m;i<=l;i++){
for(g=i;g<=j;g++){
printf("%d ",a[i]);
printf("%d ",a[g]);
}
}
return 0;
for(g=h;g<=q;g++){
}
printf("%d ",a[g]);
78. Print sum of the elements above main
} diagonal in matrix.
i=i+k; Input 3
j=j+k; 3
h=h-k; 123456789
q=q-k; Output 123
} 456
if(i==h && j==q){ 789
for(g=i;g<=j;g++){ 11
printf("%d ",a[g]); int a[5][5],i,j,m,n,sum=0;
} scanf("%d",&m);
scanf("%d",&n); {
for(i=0;i<m;i++){ Count++;
for(j=0;j<n;j++){ }
scanf("%d",a[i][j]); Char y[count+1];
} For(i=count-1;j=0;i>=0;i--;j++){
} Y[j]=x[i];
for(i=0;i<m;i++){ }
for(j=0;j<n;j++){ Y[count]=’\0’;
printf("%d ",a[i][j]); Int flag=0;
} For(int i=0;x[i];i++){
printf("/n"); If(x[i]!=y[i]){
} Flag++;
for(i=0;i<m;i++){ Break;
for(j=0;j<n;j++){ }
if(i<j){ }
sum+=a[i][j]; If(flag==0)
} Pf(“Palindrome”);
} Else
} Pf(“Not a Palindrome”);
printf("%d",sum); //Another method
return 0; Int flag=0;
For(int i=0;j=count-1;i<j;i++,j--){
79. String . If(x[i]!=x[j]){
Int count=0; Flag++;break;
For(i=0;x[i];i++){ }
Count++; }
} If(flag==0)
Int i=0; int j=count-1; Pf(“Palindrome”);
While(i<j){ Else
Char m=x[i]; Pf(“Not a palindrome”);
X[i]=x[j]; 81. Count vowels and consonets
X[j]=m; Int vowel=0;
I++;j--; Int consonant=0;
} For(int i=0;x[i];i++){
80. Palindrome or not. Char m=x[i];
Int count=0; If(m==’a’ || m==’e’ || m==’I’ || m==’o’ || m==’u’ ||
m==’A’ || m==’E’ || m==’I’ || m==’O’ || m==’U’)
For(i=0;x[i];i++)
Vowel++; X[j]=’0’;
Else }
Consonant++; }
} Pf(“%c - %d\n”,x[i],count);
Printf(“vowel:%d”,vowel); }
Pf(“Consonet”%d”,consonant); }

82. Swap vowels 83. Write a pgm to calc XA+YB where A and B
are matrices and X=2,Y=3.
Input – Vinoth
int a[5][5],m,n,i,x=2,y=3,b[5][5],j,s=0;
Output – vonith
scanf("%d",&m);
Input - Vinothua
scanf("%d",&n);
Output - vanuthoi
for(i=0;i<m;i++){
//find count
for(j=0;j<n;j++){
Int i=0;j=count-1;
scanf("%d",&a[i][j]);
While(i<j){
}
While(!(x[i]==’a’ || x[i]==’e’ || x[i]==’I’ || x[i]==’o’ ||
x[i]==u){ }
I++; for(i=0;i<m;i++){
} for(j=0;j<n;j++){
While(!(x[j]==’a’ || x[j]==’e’ || x[j]== ‘I’ || x[j]==’o’ || scanf("%d",&b[i][j]);
x[j]==’u’){
}
j--;
}
}
for(i=0;i<m;i++){
If(i<j){//if condition optional
for(j=0;j<n;j++){
Char m=x[i];
printf("%d",a[i][j]);
X[i]=x[j];
}
X[j]=m;i++;
printf("\n");
J--;
}
}
printf("\n");
}
for(i=0;i<m;i++){
83. Count number of occurences of a letters in
string. for(j=0;j<n;j++){

For(int i=0;x[i];i++){ printf("%d",b[i][j]);

Int count=1; }

If(x[i]!=’0’{ printf("\n");

For(int j=i+1;x[j];j++){ }

If(x[i]==x[j] && x[j]!=’0’){ printf("\n");

Count++; for(i=0;i<m;i++){
for(j=0;j<n;j++){ scanf("%d",&m);
a[i][j]=x*a[i][j]; for(i=0;i<m;i++){
printf("%d ",a[i][j]); scanf("%d",&b[i]);
} }
printf("\n"); while(k){
} y=a[n-1];
printf("\n"); for(i=n-1;i>0;i--){
for(i=0;i<m;i++){ a[i]=a[i-1];
for(j=0;j<n;j++){ }
b[i][j]=y*b[i][j]; a[0]=y;
printf("%d ",b[i][j]); k--;
} }
printf("\n"); for(i=0;i<m;i++){
} s=b[i];
printf("\n"); printf("%d\n",a[s]);
for(i=0;i<m;i++){ }
for(j=0;j<n;j++){
s=a[i][j]+b[i][j]; 85. Count the no of pair of elements in an
array.
printf("%d ",s);
Input - 10 10 20 40 40 30 70 10 20 70
}
Output - 4
printf("\n");
int a[15],i,j,y,max,count=0,n;
}
scanf("%d",&n);
84. Input 4 //no of ele
for(i=0;i<n;i++){
1 2 3 4 //frst array
scanf("%d",&a[i]);
3 //k=3 no of rotations
}
2 // no of ele
max=a[0];
2 3 //2nd array
for(i=0;i<n;i++){
Output 4
if(max<a[i])
1
max=a[i];
//element of second array’s index in
first array. }
int a[10],b[10],n,m,i,y,k,s; y=max+1;
scanf("%d",&n); for(i=0;i<n;i++){
for(i=0;i<n;i++){ if(a[i]!=y){
scanf("%d",&a[i]); for(j=i+1;j<n;j++){
} if(a[i]==a[j]){
scanf("%d",&k); count++;
a[j]=y; k=n/2;
break; printf("%d ",a[k]);
} }
} for(i=0;i<n;i++){
} if(i%2==1)
} sum+=b[i];
printf("%d",count); }
printf("\n%d",sum);
86. Sort in alternatively like max and min 87. Input- how are you
orde…then print sum of even index elements
Output – you are how
Input 5
//find count
42513
Char x[20];
Output 5 2 4 1 3
Scanf(“%[^\n]s”,x);//for read one full sentence
3
Int count1=0;
int a[10],b[10],i,j,temp,k,n,sum=0,p=0;
For(int i=count-1;i>=0;i--){
scanf("%d",&n);
If(x[i]!=” “)
for(i=0;i<n;i++){
Count1++;
scanf("%d",&a[i]);
Else{
}
For(int j=I+1;j<=(i+count1);j++){
for(i=0;i<n;i++){
Printf(“%c”,x[j]);
for(j=i+1;j<n;j++){
}
if(a[i]>a[j]){
Printf(“ “);
temp=a[i];
Count1=0;
a[i]=a[j];
}
a[j]=temp;
}
}
For(k=0;x[k];k++){
}
If(x[k]!=” “){
}
Printf(“%c”,x[k]);
for(i=0,j=n-1;i<j;i++,j--){
}
printf("%d ",a[j]);
Else
b[p]=a[j];
Break;
p++;
}
printf("%d ",a[i]);
//another method
b[p]=a[i];
//find count
p++;
Char x[20];
}
Scanf(“%[^\n]s”,x);//for read one full sentence
if(n%2==1){
Int count1=0;
For(int i=count-1;i>=0;i--){ Input 8
If(x[i]!=” “){ 5
Count1++; Output – 58
If(i==0){ 13
For(int j=i;j<=(i+count1);j++){ Char a=’5’;
Printf(“%c”,x[j]); Char b=’8’;
} Int x=a-‘0’;
} Int y=b-‘0;
} Int z=(x*10)+y;
Else{ Int m=x+y;
For(int j=I+1;j<=(i+count1);j++){ 90. Input - a3b4d2
Printf(“%c”,x[j]); Outbut – aaabbbbdd
} //find count
Printf(“ “); For(int i=1;i<count;i=i+2){
Count1=0; Int m=x[i]-‘0’;
} For(int i=0;i<m;i++){
} Pf(“%c”,x[i-1]);
88. Input – how are you }
Output – woh era uoy }
Count1=0; 91. Input – a4d5y2
For(int i=0;x[i];i++){ Output - aaaabbbbbyy
If(x[i]!=” “) For(int i=0;x[i];i++){
Count1++; If(x[i]>=’a’ && x[i]<=’z’){
Else{ Pf(“%c”,x[i]);
For(int j=i-1;j>=(i-count);j--){ }
Pf(“%c”,x[j]); Else{
} Int m=x[i]-‘0’;
Pf(“ “);count1=0; For(int j=1;j<m;j++){
} Pf(“%c”,x[i-1]);
} }
For(int k=count-1;k>=0;k--){ }
If(x[k]!=” “) }
Pf(“%c”,x[k]); 92. Input – a2g12m3
Else Output – aaggggggggggggmmm
Break; For(int i=0;x[i];i++){
} If(x[i]>=’a’ && x[i]<=’z’ || x[i]>=’A’ && a[i]<=’Z’)
89. convert char to number Pf(“%c”,x[i]);
Else{ for(i=0;a[i];i++){
Int m=x[i]-‘0’; count++;
If(x[i+1]>=’0’ && x[i+1]<=’9’){ }
Int d=x[i+1]-‘0’; for(i=0;i<count;i++){
Int k=(m*10)+d; count1=0;
For(int j=1;j<k;++){ while(a[i]>='a' && a[i]<='z'){
Pf(“%c”,x[i-1]); count1++;
} if(i==count-1)
I++; printf("%c",a[i]);
} i++;
Else{ }
For(int j=1;j<m;j++){ if(a[i]>='0' && a[i]<='9'){
Pf(“%c”,x[i-1]); int m=a[i]-'0';
} if(a[i+1]>='0' && a[i+1]<='9'){
} int d=a[i+1]-'0';
} int k=(m*10)+d;
} while(k){
93. Input – abc2 for(j=i-count1;j<i;j++){
Output – abcabc printf("%c",a[j]);
Int i=0; }
Int j=i+1; k--;
Int h=2; }
While(x[j]>=’a’ && x[j]<=’z){ i++;
J++; count1++;
} }
Int h=x[j]-‘0’; else{
While(h){ while(m){
For(intk=I;k<j;k++){ for(j=i-count1;j<i;j++){
Pf(“%c”,x[k]); printf("%c",a[j]);
} }
h--; m--;
} }
94. Input - abc2de3f3h }
Output – abcabcdedefffh }
char a[100]; 95. Input -aaabbbbbbbbbb
int i,j,count=0,count1=0; Output – a3b10
scanf("%s",a); //find count
Int count=1; If(flag==0){
For(int i=1;x[i];i++){ Pf(“Anagram”);
If(x[i]==x[i-1]){ Else
Count++; Pf(“not an anagram”);
If(i==count1-1) 97. Pangram.
Printf(“%c%d”,x[i-1],count); Input – abCDEfghiJKLmnoPqrstuVWYz
} Ouptu – True
Else{ Input – College of Engineering
Pf(“5c%d”,x[i-1],count); Output – False
Count=1; //check all alphabets are present or not
If(i==count1-1) Char x[100];
Pf(“%c%d”,x[i],count) Scanf(“%[^n]s”,x);
} Char A[]=”abcdefghijklmnopqrstuvwxyz”;
} For(int i=0;x[i];i++){
96. Anagram. Char m=x[i];
Input – Integral If(m>=’A’ && m<=’Z’){
Triangle M=m+32;
Output – Anagram }
//find count1 For(int j=0;A[j];j++0{
//find count2 If(m==A[j]){
If(count1==count2){ A[j]=’0’;
For(int i=0;x[i];i++){ Break;
Char m=x[i]; }
For(int j=0;y[j];j++){ }
Char h=y[j]; }
If(m==h){ Int flag=0;
Y[j]=’0’;break; For(int j=0;A[j];j++){
} If(A[j]!=’0’){
} Flag++;
} Break;
} }
Int flag=0; }
For(int k=0;y[k];k++){ If(flag==0)
If(y[k]!=’0’){ Printf(“True”);
Flag++;break; Else
} Pf(“False”);
} //try it with ascii value
98. Input – Vinoth If((y[j-1]==’(’ && m=’)‘)|| (y[j-1)==’{’ && m==’}‘)||
(m==’]’ && y[j-1==’[‘)){
Output – v
Y[j-1]=’0’;
Input – vinothv
J--;
Output – i
}
///print first non repeating character.
Else{
For(int i=0;x[i];i++){
Flag++;
Int flag=0;
Break;
If(x[i]!=’0’){
}
For(int j=i+1;x[j];j++){
}
If(x[i]==x[j] && x[j]!=’0’){
}
X[j]=’0’;
Int flag=0;
Flag++;break;
For(int i=0;i<len;i++){
}
If(y[i]!=’0’){
}
Flag++;
}
Break;
If(flag==0){
}
Pf(“%c”,x[i]);
}
Break;
If(flag==0)
}
Pf(“Balanced”);
}
Else
99. Input – “[()]{}{[()()]()}”
Pf(“Not balanced”);
Output – Balanced
Input – Y - TEST
Char x[20];
X – THIS IS A TEST TEXT
Scanf(“%s”,x);
Input – A&X#
Int len=strlen(x);
Output – X&A#
Char y=len;
//reverse the string without affecting the string.
For(int i=0i<len;i++){
//get string
Y[i]=’0’;
//find count
}
For(int i=0;j=count-1;i<j;i++;j--){
Int j=0;
While(!((x[i]>=’a’ && x[i]<=’z’) || (x[i]>=’A’ &&
For(int i=0;x[i];i++0{ x[i]<=’Z’)(){
Char m=x[i]; I++;
If(m==’[‘ || m==’(‘ || m==’{‘){ }
Y[j]=m; While(!((x[j]=’a’ && x[j]<=’z’) || (x[j]>=’A’ &&
J++; x[j]<=’Z’))){

} j--;

Else{ }
If(i<j){ for(i=0;a[i];i++){
Char m=x[i]; count++;
X[i]=x[j]; }
X[j]=m; count1=count;
} for(i=0;i<(count*2);i++){
} if(i<count){
Pf(“%s”,x); for(j=0;j<=i;j++){
Input – geeks for geeks printf("%c",a[j]);
Output – gks fr gks }
//Print without vowels }
char a[100]; else if(i>=count){
int i,j,count=0; for(j=0;j<count1;j++){
scanf("%[^n]s",a); printf("%c",a[j]);
for(i=0;a[i];i++){ }
count++; count1--;
} }
for(i=0;i<count;i++){ printf("\n");
if(!(a[i]=='a' || a[i]=='e' || a[i]=='i' || a[i]=='o' || }
a[i]=='u' || a[i]=='A' || a[i]=='E' || a[i]=='I' || a[i]=='O' ||
a[i]=='U')){ Input – x - AABAACAADAABAABA

printf("%c",a[i]); Y – AABA

} Output – 0

} 9

Print the following pattern. 12

H Char x[30];

HE Char y[30];

HEL Scabf(“%[^\n]s”,x);

HELL Scanf(“\n%[^\n]s”,y);

HELLO For(int i=0;x[i];i++){

HELLO Int count=0;

HELL For(int j=0;y[j];j++){

HEL If(x[i+j]==y[j]){

HE Count++;

H }

char a[20]; Else

int i,j,count=0,count1=0; Break;

scanf("%s",a); }
If(count==count1){
Pf(“%d\n”,i); Pf(“%c”,a[i]);
} }
Input – x - heap Input – this is a test string only
Y – pea Output – only test
Output – minimum deletion-2 Index=12;//above remaing code missing☹
Minimum insertion- 1 Int start1=0;
Int start2=0;
Input – forgeeksskeegfor For(int i=index;i>=0;i--){
Output – geeksskeeg If(x[i]==’ ‘){
3 Start1=i+1;
12 Break;
Int start=0; }
Int end=0; }
Int max=0; Int count1=strlen(x);
For(int i=0;x[i];i++){ For(int i=count-1;i>=0;i--;){
For(int j=i+1;x[j];j++){ If(x[i]==’’){
Int h=I; Start2=i+1;break;
Int y=j; }
Int flag=0; }
While(h<y){ For(int i=0;x[i];i++){
If(x[h]!=x[y]){ If(i==start1){
Flag++;Break; For(int j=start2;x[j];j++){
} Pf(“%c”,x[j]);
Else{ I++;
H++;y--; }
} }
} If(i==start2){
If(flag==0){ For(int j=start1; x[j];j++){
Int count=j-i+1; If(x[j]!=’’){
If(max<count){ Pf(“%c”,x[j]);
Max=count; I++;
Start=I; }
End=j; Else{
} Pf(“%c”,x[j]);
} I++;
} }
For(i=start;i<end;i++){ }
} }
Else
Pf(“%c”,x[j]); Rotation
#include<stdio.h>
Second Most frequent cagracter int main() {
Input -geegeks int m;
Output – g int n;
char a[30]; int v=0;
scanf("%[^\n]",a); int rotate=0;
int i,max=0,sec_max=0; scanf("%d",&m);
int b[123]={0}; scanf("%d",&n);
for(i=0;i<a[i];i++) int A[m][n];
{ for(int i=0;i<m;i++){
if(a[i]==' ') for(int j=0;j<n;j++){
continue; scanf("%d",&A[i][j]);
b[a[i]]++; }
} }
for (i = 0; i <123; i++) { int B[m][n];
if (b[i]>b[max]) { for(int i=0;i<m;i++){
sec_max=max; for(int j=0;j<n;j++){
max = i; scanf("%d",&B[i][j]);
} }
else if(b[i]>b[sec_max] && b[i]!=b[max]){ }
sec_max=i; int h=3;
} while(h){
} rotate++;
printf("%c",sec_max); int C[m][n];
return 0; int k = 0;
Print minimum in each row. int g=0;
//get 2D array for(int j=0;j<n;j++){
For(int i=0;i<m;i++){ for(int i=m-1;i>=0;i--){
Int min=a[i][0]; C[k][g] = A[i][j];
For(j=0;j<n;j++){ g++;
If(a[i][j]<min) }
Min=a[i][j]; g=0;
} k++;
Printf(“%d\n”,min); }
int flag=0; }
for(int i=0;i<m;i++){ scanf("%d",&k);
for(int j=0;j<n;j++){ int sum=0;
if(B[i][j]!=C[i][j]){ int max=0;
flag++; for(i=0;i<n1;i++){
break; for(j=0;j<n2;j++){
} sum=a[i]+b[j];
} if(sum<=k){
if(flag==1){ if(max<sum){
break; max=sum;
} }
} }
v++; }
for(int i=0;i<m;i++){ }
for(int j=0;j<n;j++){ printf("%d",max);
A[i][j] = C[i][j];
} //Get matrix A.
} Input - 5
} 5
} 12345
h--; 12345
} 12345
if(v==3){ 12345
printf("FALSE\n"); 12345
} Output - 123455554321111234443223
printf("%d",rotate);
return 0; int a=c=0;
} int b=n-1;
Monica’s Problem int d=m-1;
int a[10],b[10],n1,n2,i,j,k; while(a<=b && c<=d){
scanf("%d",&n1); for(int i=a;i<=b;i++){
scanf("%d",&n2); pf(“%d”,A[c][i]);
for(i=0;i<n1;i++){ }
scanf("%d",&a[i]); C++;
} For(int i=c;i<=d;i++){
for(i=0;i<n2;i++){ Pf(“%d”,A[i][b]);
scanf("%d",&b[i]); }
B--; scanf("%d",&A[i][j]);
For(int i=b;i>=a;i--){ }
Pf(“%d”,A[[d][i]); }
} int row = 0, col = 0;
d--; int prev, curr;
for(int i=d;i>=c;i--){ int R=m;
pf(“%d”,A[i][a]); int C=n;
} while (row < m && col < n)
A++; {
} if (row + 1 == m || col + 1 == n)
break;
Array rotation // Store the first element of next row, this
Input – 3 // element will replace first element of current
3 // row
123 prev = A[row + 1][col];
456 /* Move elements of first row from the
remaining rows */
789
for (int i = col; i < n; i++)
Output – 4 1 2
{
753
curr = A[row][i];
896
A[row][i] = prev;
Input – 4
prev = curr;
4
}
1234
row++;
5678
/* Move elements of last column from the
9 10 11 12 remaining columns */
13 14 15 16 for (int i = row; i < m; i++)
Output – 5 1 2 3 {
9 10 6 4 curr = A[i][n-1];
13 11 7 8 A[i][n-1] = prev;
14 15 16 12 prev = curr;
#include<stdio.h> }
int main() { n--;
int A[10][10],m,n,i,j,k; /* Move elements of last row from the
scanf("%d",&m); remaining rows */

scanf("%d",&n); if (row < m)

for(i=0;i<m;i++){ {

for(j=0;j<n;j++){ for (int i = n-1; i >= col; i--)


{ //get an square matrix
curr = A[m-1][i]; Int a=0;int b=n-1;
A[m-1][i] = prev; Int c=0; int d=n-1;
prev = curr; Int B[n*n];
} Int k=0;
} While(a<=b && c<=d){
m--; For(int i=a;i<=b;i++){
/* Move elements of first column from the B[k]=A[c][i];
remaining rows */
K++;
if (col < n)
}
{
C++;
for (int i = m-1; i >= row; i--)
For(int i=c;i<=d;i++){
{
B[k]=A[i][b];
curr = A[i][col];
K++;
A[i][col] = prev;
}
prev = curr;
b--;
}
for(int i=b;i>=a;i—0{
}
B[k]=[d][i];
col++;
K++;
}
}
// Print rotated matrix
d--;
for (int i=0; i<R; i++)
for(int i=d;i>=c;i--){
{
B[k]= [i][a];
for (int j=0; j<C; j++){
K++;
printf("%d ",A[i][j]);
}
}
A++;
printf("\n");
}
}
forIny i=0;i<(n*n);i++){
return 0;
pf(“%d”,B[i]);
}
}
Input
Pf(“\n);
1234
For(int i=((n*n)-1);ii>=0;i--){
5678
Pf(“%d”,b[i]);
9 10 11 12
}
13 14 15 16
Output
Input - N=4 //4 *4 matrix.
10 11 7 6 5 9 13 14 15 16 12 8 4 3 2 1
Output 4444
4334 1001
4334 1001
4444 1111
Int n; Int n;
Scanf(“%d”,&n); Scanf(“%d”,&n);
Int A[n][n]; Int A[n][n];
Int a=0;int b=n-1; Int a=0;int b=n-1;
Int c=0;int d=n-1; Int c=0;int d=n-1;
Int h=n; Int h=0;
While(a<=bc<=d){ Int count=1;
For(int i=a;i<=b;i++){ While(a<=bc<=d){
A[c][i]=h; If(count%2==1){
} H=1;
C++; }
For(i=c;i<=d;i++){ Else
A[i][]b]=h; H=0;
} For(int i=a;i<=b;i++){
b--; A[c][i]=h;
for(int i=b;i>=a;i—0{ }
A[d][i]=j; C++;
} For(i=c;i<=d;i++){
d--; A[i][]b]=h;
for(int i=d;i>=c;i--){ }
A[i][a]=h; b--;
} for(int i=b;i>=a;i—0{
A++; A[d][i]=j;
h--; }
} d--;
For(int i=0;i<n;i++){ for(int i=d;i>=c;i--){
For(int j=0;j<n;j++){ A[i][a]=h;
Pf9”%d”,A[i][j]); }
} A++;
Pf(“\n”); h--;
} count++;
}
Input – 4 For(int i=0;i<n;i++){
Output – 1 1 1 1 For(int j=0;j<n;j++){
Pf9”%d”,A[i][j]); Int m=1;
} Int h=0;
Pf(“\n”); Int k=count-1;
} For(i=0;i<count;i++){
Input – n=5 For(j=0;j<count;j++){
Output If(i==j){
* * Pf(“%c”,x[h]);
* * If(h==k)
* k--;
* * }
* * H++;
Int k=1; }
For(int i=0;i<n;i++){ Else if(j==(count-m)){
For(j=0;j<n;j++){ Pf(“%c”,x[k]);
If(i==j){ K--;
Pf(“*”); }
} Else
Else if(j==(n-k)) Pf(“ “);
Pf(“*”); }
Else M++;
Pf(“ “); Printf(“\n”);
} }
K++;
Pf(“\n’);
} Input – PROGRAM
Output
Input – RAJAN G
Output GR
R N GRA
A A GRAM
J GRAMP
A A GRAMPR
R N GRAMPRO
//find the coutn of the input array Char y[20];
Char x[20]; Scanf(“%s”,y);
Scanf(“%s”,x); INT LEN=STRLEN(y);
Int count=strlen(x); Char x[len+1];
Int d=0; GRAMPRO
For(int i=len/2;y[i];i++){ IN ABOVE PROGRAM CHANGE…H=LEN-1
X[d]=y[i]; J<len i<len
D++;
} Input – 4
For(int i=0;i<(len/2);i++){ Output
X[d]=y[i]; 1234
D++; 8765
} 9 10 11 12
Int h=(2*len)-2; 16 15 14 13
Int k=0; Int n;
For(int i=0;i<len;i++){ Scanf(“%d”,&n);
For(int j=0;j<(2*len-1);j++){ Int k=1;
If(j==h){ Int g=1;
For(int m=0;m<=k;m++){ H=(2*n)-(n+1);
Pf(“%c”,x[m]); For(i=0;i<n;i++){
} For(j=0;j<(2*n-1);j++){
K++; If(j==h && g%2==1){
Break; For(int m=0;m<n;m++){
} Printf(“%d”,k);
Else K++;
Pf(“ “); }
} K=k+(n-1);
H=h-2; G++;
Print(“\n”); h--;Break;
} }
Else if(j==h && g%2==0){
For(int m=0;m<n;m++){
Input – PROGRAM Pf(“%d”,k);k--;
Output }
G K=k+(n+1);
GR G++;
GRA h--;break;
GRAM }
GRAMP Else
GRAMPR Pf(“ “);
}
Pf(“\n”); M=m+k;
} k--;
Input – 6 }
Output Pf(“\n”);
1 7 12 16 19 21 h--;
2 8 13 17 20 k=n;m=1;
3 9 14 18 m=m+t;
4 10 15 t++;
5 11 }
6
N=6 Input – RACECAR
Int k=1;
Int A[n][n]; IF(J==J &&J==G){
Int h=n; X[H];
For(int j=0;j<n;j++){ H++;g--;
For(int i=0;i<h;i++){ Break;
A [i][j] =k; }
K++; Else if(j==g){
} X[g];
h--; }
} Else
Int g=n; Pf(“ “)
For(int i=0;i<n;i++){ g--;h++;
For(j=0;j<g;j++){ if(i==(len/2){
Pf(“%d”,A[i][j]); h=1;g=len-2;
} }
Pf(“\n”); Input
g--; 0*0s
} *0**
//row method 0***
Int h=n; d***
Int k=n; int n;
Int m=1; scanf(“%d”,&n);
Int t=1; char A[n][n];
For(int i=0;i<n;i++){ for(int i=0;i<n;i++){
For(int j=0;j<h;j++){ for(j=0;j<n;j++){
Pf(“%d”) scanf(“%c”,&A[i][j]);
} j++;
} printf(" ");
For(int i=0;i<n;i++){ j++;
For(j=0;j<n;j++){
while(j!=c){
Printf(“%c”,A[i][j]);
j++;
}
l=m+d;
Printf(“\n”);
d=l;
}
printf("%d",l);

Input – 7 j++;

1 printf(" ");

1 1 }

1 2 1 printf("%d",k);

1 3 4 1 c++;

1 5 6 7 1 h--;

1 8 9 10 11 1 }

1 12 13 14 15 16 1 }

int main() { else

int i,j,n,m=1,l,d=1; printf(" ");

scanf("%d",&n); }

int p=n*2; printf("\n");

int a[n][p]; return 0;

int c=(p/2)-1; }

int h=c; Input

int k=1; 1234

for(i=0;i<n;i++){ 5678

for(j=0;j<=c;j++){ 9 10 11 12

if(j==h){ 13 14 15 16

if(c==h){ Output

printf("%d",k); 1 2 3 4 8 7 6 5 9 10 11 12 16 15 14 13

h--; int a[10][10],m,n,i,j;

c++; scanf("%d",&m);

} scanf("%d",&n);

else{ for(i=0;i<m;i++){

printf("%d",k); for(j=0;j<n;j++){
scanf("%d",&a[i][j]); Output – 10 11 11

} Input – 120

} Output – 10 110

for(i=0;i<m;i++){ //maximum posiibility

if(i%2==0){

for(j=0;j<n;j++){ 123456

printf("%d ",a[i][j]); Height 6 15

} o/p 123 & 456

else{
Input
for(j=n-1;j>=0;j--){
house no : 123, cbe
printf("%d ",a[i][j]);
Output
}
ebc32 lo : nes, uoh
} int main() {
}

Input – N=13 /* Enter your code here. Read input from


STDIN. Print output to STDOUT */
Find the number of digits from 1 to N.
char a[100];
N=13 then output is 17.
scanf("%[^\n]s",a);
Int k=9;
int i,j;
Int y=1;int sum0;
char b[100];
While(n>0){ int count=0;
Int m=n-k; for(i=0;a[i];i++)
If(m>0){ count++;
Sum=sum+k*y; j=count-1;

} i=0;

Else int k=0;


for(i=0,j=count-1;a[i];){
Sum=sum+(n*y);
if(a[i]==' ' || a[i]==',' || a[i]==':' || a[i]=='-'){
Y++;
b[k]=a[i];
K=k*10;
k++;
N=m;
i++;
}
continue;
Pf(“%d”,sum); }
Represent in binary numbers if(a[j]==' ' || a[j]==':' || a[j]==',' || a[j]=='-'){
Input – 32
j--; j++;
} printf("%d ",max);
if(!(a[j]==' ' || a[j]==',' || a[j]==':' || a[j]=='-')){ }
b[k]=a[j]; else{
j--; while(i<=j){
k++; k=max;
i++; if(a[i]>max){
}
} max=a[i];
b[k]='\0'; }
for(i=0;b[i];i++){ i++;
printf("%c",b[i]); }
} j++;
return 0; if(k!=max){
} printf("%d ",max);
}

Sample Input 0 }

6 }
1 3 4 -5 2 6 return 0;
Sample Output 0 }

1 3 4 6

int main() { Find the largest sum contiguous sub array


which should not have negative numbers.
/* Enter your code here. Read input from We
STDIN. Print output to STDOUT */ have to print the sum and the
int n,a[10],i,k=0,max; corresponding array elements which
scanf("%d",&n); brought up the sum.
for(i=0;i<n;i++)
Input Format
scanf("%d",&a[i]);
8
max=0;
2 7 -5 1 3 2 9 -7
int j=0;
while(j<n){ Constraints
i=0;
4<=n<=10
if(j==0){
max=a[i]; Output Format
15  arr: 2 8 3 5 7 4 1 2
1329
Output:
int main() {
4
int a[10],n,i,j=0,m=0,l=0,max=0,sum;
scanf("%d",&n); Explanation:
for(i=0;i<n;i++){
Total amount of food required for all rats = r *
scanf("%d",&a[i]);
unit= 7 * 2 = 14.The amount of food in 1st
} houses = 2+8+3+5 = 18. Since, amount of food
for(i=0;i<n;i++){ in 1st 4 houses is sufficient for all the rats.
Thus, output is 4.
if(a[i]>=0){
sum=0; int r,n,unit,a[20];
for(j=i;j<n;j++){
scanf("%d",&r);
if(a[j]>=0){
sum=sum+a[j]; scanf("%d",&unit);

if(sum>max){ scanf("%d",&n);
max=sum;
int i,j;
l=i;
m=j; for(i=0;i<n;i++){

}
scanf("%d",&a[i]);
}
}
else{
break; int s=r*unit;
}
int sum=0,c=0;
}
} for(i=0;i<n;i++){

} c++;
printf("%d\n",max);
sum=sum+a[i];
for(i=l;i<=m;i++){
printf("%d ",a[i]); if(sum>=s){
}
break;
return 0;
} }

Input: }

 r: 7 printf("%d",c);
 unit: 2
 n: 8
c++;
You are given a function.
int CheckPassword(char str[], int n); }

The function accepts string str of size n as an if(c<4)

argument. Implement the function which printf("0");


returns 1 if given string str is valid password
else{
else 0.
if(s[0]-'0'>=0 && s[0]-'0'<=9){
str is a valid password if it satisfies the below
printf("0");
conditions.
}
 – At least 4 characters
 – At least one numeric digit else{
 – At Least one Capital Letter
 – Must not have space or slash (/) for(i=0;s[i];i++){
 – Starting character must not be a
if(s[i]==' ' || s[i]=='/'){
number
printf("0");
Assumption:
b++;
Input string will not be empty.
break;

Example: }

else if(s[i]-'0'>=0 && s[i]-'0'<=9){


Input:
aA1_67 n++;

Output: }
1 if(s[i]>='A' && s[i]<='Z'){

Sample Input: l++;

a987 abC012 }

Output: }
0
if(b==0){
int main() {
if(n==0 || l==0){
char s[100];
printf("0");
int i=0,b=0;
}
int c=0,n=0,l=0;
else{
scanf("%[^\n]s",s);
printf("1");
for(i=0;s[i];i++){
} scanf("%d",&n);

} scanf("%d",&m);

int i,s=0,s2=0;
}
for(i=1;i<=m;i++){
}
if(i%n==0){
return 0;
s=s+i;
} }

else{
The function accepts two integers n, m as
s2=s2+i;
arguments Find the sum of all numbers in
}
range from 1 to m(both inclusive) that are not
}
divisible by n. Return difference between sum
int d;
of integers not divisible by n with sum of
if(s>s2){
numbers divisible by n.
d=s-s2;

Assumption: }

else{
 n>0 and m>0
 Sum lies between integral range d=s2-s;

}
Example printf("%d",d);

return 0;
Input
}
n:4
m:20 Input
Output
arr:3 2 1 7 5 4
90

Output
Explanation

 Sum of numbers divisible by 4 are 4 + 8 7


+ 12 + 16 + 20 = 60
 Sum of numbers not divisible by 4 are 1 Explanation
+2 + 3 + 5 + 6 + 7 + 9 + 10 + 11 + 13 +
14 + 15 + 17 + 18 + 19 = 150  Second largest among even position
 Difference 150 – 60 = 90 elements(1 3 5) is 3
 Second smallest among odd position
int main() { element is 4
int n,m;  Thus output is 3+4 = 7
int n,i; }
scanf("%d",&n); for(i=0;i<max+1;i++){
int a[n]; if(c[i]!=0){
for(i=0;i<n;i++){ d++;
scanf("%d",&a[i]); if(d==2){
} d=i;
int max=0; break;
for(i=0;i<n;i++){ }
if(max<a[i]){ }
max=a[i]; }
} printf("%d",e+d);
} Write a program to accept a text. Count and
display the number of times the word ‘the’
int b[max+1];
appears in the text
int c[max+1];
int main()
for(i=0;i<max+1;i++){
{
b[i]=0;
char s[30];
c[i]=0;
char w[50];
}
int i,j,c=0,f=0,l=0;
for(i=0;i<n;i++){
fgets(s, 30, stdin);
if(i==0 || i%2==0){
printf("%s",s);
b[a[i]]++;
scanf("%[^\n]s",w);
}
printf("%s",w);
else{
i=0;
c[a[i]]++;
while(w[i]!='\0'){
}
l++;
}
i++;
int e=0,d=0;
}
for(i=max;i>=0;i--){
for(i=0;s[i];i++){
if(b[i]!=0){
f=0;
e++;
for(j=0;w[j];j++){
if(e==2){
if(s[i-1]==' ' || i==0 || s[i-1]==w[j-1]){
e=i;
if(s[i]==w[j]){
break;
f++;
}
i++;
}
}
else if(s[i]==w[j]){
break; f++;

} i++;

else }

break; else

} break;
}
if(f==l && s[i]==' ')
else
c++;
break;
}
}
if(f==l && s[i]==' ')
if(f==l)
c=i-l;
c++;
printf("%d",c);
}
if(f==l)
return 0;
c=i-l-1;
}
printf("%d",c);
Write a program to find the last instance of return 0;
occurrence of a sub-string within a text.
}
int main()
Write a program to find the last instance of
{ occurrence of a sub-string within a string.
char s[30]; int main()
char w[50]; {
int i,j,c=0,f=0,l=0; char a[15];
fgets(s, 30, stdin); scanf("%s",a);
printf("%s",s);
scanf("%[^\n]s",w); int i,j;
printf("%s",w); char b[15];
i=0; scanf("%s",b);
while(w[i]!='\0'){ printf("%s",a);
l++; printf("%s",b);
i++; int l=0,f=0;
} i=0;
for(i=0;s[i];i++){ j=0;
f=0; while(b[i]!='\0'){
for(j=0;w[j];j++){ l++;
if(s[i-1]==' ' || i==0 || s[i-1]==w[j-1]){ i++;
} if(s[i]==' '){

for(i=0;a[i];i++){ for(k=i+1;k<=j;k++){
while(b[j]!='\0'){ printf("%c",s[k]);
if(a[i]==b[j]){ }
i++; printf("%c",s[i]);
j++; j=i-1;
f++; }
} else if(i==0){
else for(k=i;k<=j;k++){
break; printf("%c",s[k]);
} }
if(f==l){ }
printf("%d",i-l); }
break; return 0;
} }
}
return 0;
}
Write a program to input an array of strings.
Then, reverse the string in the format shown
below. "HAPPY BIRTHDAY TO YOU" should be
displayed as "YOU TO BIRTHDAY HAPPY"
int main()
{
char s[50];
int i,j,k;
scanf("%[^\n]s",s);
printf("%s\n",s);
int l=0;
i=0;
while(s[i]!='\0'){
i++;
l++;
}
j=l-1;
for(i=l-1;i>=0;i--){

You might also like