C Programs
C Programs
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
int num; 11 12 13 14 15
Pf(“Total:”,s); p = p * x;
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() }
} {
pf(“II quadrant”); }
{ {
Avg = total/3; {
For(i=1;i<=100;i++) }
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); {
Pf(“Average:%d”,a); }
} Else{
{ Return 1;
For(i=1;i<=n;i++) Return 0;
{ }
S=s+I; }
Int num,reverse_n; }
For(i=0;i<n;i++) sum+=1;
{ }
Sum1+=(x[i]-avg)*(x[i]-avg); printf("Count=%d",sum);
} return 0;
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); }
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++){
Int count=1; }
If(x[i]!=’0’{ printf("\n");
For(int j=i+1;x[j];j++){ }
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
H Char x[30];
HE Char y[30];
HEL Scabf(“%[^\n]s”,x);
HELL Scanf(“\n%[^\n]s”,y);
HEL If(x[i+j]==y[j]){
HE Count++;
H }
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 */
for(i=0;i<m;i++){ {
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 }
scanf("%d",&n); }
int c=(p/2)-1; }
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
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
if(i%2==0){
for(j=0;j<n;j++){ 123456
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() {
}
} i=0;
Sample Input 0 }
6 }
1 3 4 -5 2 6 return 0;
Sample Output 0 }
1 3 4 6
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); }
Example: }
Output: }
1 if(s[i]>='A' && s[i]<='Z'){
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
} 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--){