You are on page 1of 6

1. 2. 3.

#include<stdio.h># include <stdio.h> #include <stdio.h>

#include<conio.h> int main() #define MAX_SIZE 100

void main() { int main()

{ int i, j, cur, lastDigit, m, n; {

int i, sum=0; long fact, sum; int arr[MAX_SIZE];

printf("Enter lower and int size, i, toSearch, found;


printf("All nos. between
upper limit: ");
100 - 200 which is divisible printf("Enter size of array: ");
by 9\n"); scanf("%d%d", &m,&n);
scanf("%d", &size);
for(i=101;i<200;i++) printf("Armstrong numbers
printf("Enter elements in
between %d to %d are:\n",
{ array: ");
m,n);

if(i%9==0) for(i=0; i<size; i++)


for(i=m; i<=n; i++)
{
{ {
scanf("%d", &arr[i]);
printf("%5d",i); cur = i;
}
sum+=i; sum = 0;
printf("\nEnter element to
} while(cur > 0)
search: ");
{
} scanf("%d", &toSearch);
fact = 1;
printf("\n\nsum = for(i=0; i<size; i++)
%d",sum); lastDigit = cur % 10;
{ if(arr[i] == toSearch)
getch(); for( j=1; j<=3; j++)
{
} {
found = 1;
fact = fact * lastDigit;
break;
}
} }
sum += fact;
if(found == 1)
cur /= 10;
{
}
printf("\n%d is found at
if(sum == i) position %d", toSearch, i + 1);

{ }

printf("%d, ", i); else

} { printf("\n%d is not found


in the array", toSearch);
}
}
return 0;
}
5. printf("The Upper Case
of String is %s",strupr(s1));
#include<stdio.h> break;
#include<string.h> }
main() case 6:
{ {
int a,b; printf("The Lower Case
char s1[100],s2[100]; of String is %s",strlwr(s1));
printf("Enter a string.\n"); break;
scanf("%s",s1); }
case 7:
printf("Enter the operation {
you wish to perform on the printf("Enter the string
string:\n1. String Length\n2. you wish to compare with the
String Reverse\n3. String previous string.\n");
Concatenation\n4. String scanf("%s",s2);
Copy\n5. String Upper a=strcmp(s1,s2);
Case\n6. String Lower printf("String Compare
Case\n7. String %d",a);
Comparison\n"); break;
scanf("%d",&a); }

switch(a) default:
{ {
case 1: printf("You have not
{ entered a valid option.");
b=strlen(s1); }
printf("String Length = }
%d",b); }
break;
}
case 2:
{
printf("String Reverse =
%s",strrev(s1));
break;
}
case 3:
{
printf("Enter the target
string.\n");
scanf("%s",s2);
strcat(s2,s1);
printf("Result - %s",s2);
break;
}
case 4:
{
strcpy(s2,s1);
printf("Copied String -
%s",s2);
break;
}
case 5:
{
4. addtion or subtraction of
matrices\n");
{
for(j=0;j<n;j++)
#include<stdio.h> if(n==e){printf("Enter 2 {
#include<conio.h> for multiplication of printf("%3d",sub[i][j]);
int main() matrices\n");} }
{ printf("Enter 3 for printf("\n");
int transpose of first matrices\n"); }
m,n,a[20][20],b[20][20],i,j,sum } }
[20][20],sub[20][20],opt,tr[20] else if(m!=n&&n==e) break;
[20],opt1,ch,e,f; { case 2 :
printf("Note : For Addition printf("Enter 2 for printf("The resultant
or Subtraction , no. of rows multiplication of matrices\n"); matrices is : \n");
and columns should be same printf("Enter 3 for int k;
and for transpose of matrices , transpose of first matrices\n"); for(i=0;i<m;i++)
your first matrices entered } {
should be the desired matrices else for(j=0;j<f;j++)
.\n"); { { sum[i][j]=0;
printf("Enter the no. of printf("Enter 3 for transpose of for(k=0;k<m;k++)
rows: "); first matrices\n"); {
scanf("%d",&m); } sum[i][j]+=a[i][k]*b[k
printf("Enter the no. of scanf("%d",&ch); ][j];
columns: "); switch(ch) }
scanf("%d",&n); { printf("%d\t",sum[i][j]
printf("Enter the Data case 1 : );
Elements of first matrices\n"); for(i=0;i<m;i++) }
for(i=0;i<m;i++) { printf("\n");
{ for(j=0;j<n;j++) }
for(j=0;j<n;j++) { break;
{ sum[i][j]=a[i][j]+b[i][j]; case 3 :
scanf("%d",&a[i][j]); sub[i][j]=a[i][j]-b[i][j]; for(i=0;i<m;i++)
} } {
} printf("Enter the no. of } for(j=0;j<n;j++)
rows for second matrices: "); printf("Enter 1 for Addition {
scanf("%d",&e); or 2 for Subtraction: "); tr[j][i]=a[i][j];
printf("Enter the no. of scanf("%d",&opt); }
columns: "); switch(opt) }
scanf("%d",&f); { printf("The resultant
printf("Enter the Data case 1 : matrices is :\n");
Elements of second printf("The resultant for(i=0;i<n;i++)
matrices\n"); matrices is :\n"); {
for(i=0;i<e;i++) for(i=0;i<m;i++) for(j=0;j<m;j++)
{ { {
for(j=0;j<f;j++) for(j=0;j<n;j++) printf("%3d",tr[i][j])
{ { ;
scanf("%d",&b[i][j]); printf("%3d",sum[i][j]); }
} } printf("\n");
} printf("\n"); }
do } break; }}
{ break; while(ch>0);
if(m==e&&n==f) case 2 : getch();
{ printf("The resultant }
printf("Enter 1 for matrices is :\n");
for(i=0;i<m;i++)
6. lenstr1 =
lengthstr(str1);
}
newstr = (char
#include <stdio.h> lenstr2 = *)malloc(sizeof(char)*(count+1
#include <conio.h> lengthstr(str2); ));
#include <math.h> newstr = (char tempstr = newstr;
#include <stdlib.h> *)malloc(sizeof(char)*(lenstr1+ c--;
int lengthstr(char *str) lenstr2+1)); while(count > 0)
{ tempstr = newstr; {
int count = 0; while(*str1 != '\0')
while(*str != '\0') { *tempstr = *c;
{ *newstr c--;
= *str1;
count++; tempstr++;
str++; newstr++; count--;
} str1++; }
return count; } *tempstr = '\0';
} while(*str2 != '\0') return newstr;
{ }
//For comparing two strings *newstr
int cmpstr(char *str1, char = *str2; int main(int argc, char **argv)
*str2) {
{ newstr++; char str[10],
int lenstr1, lenstr2; str2++; str1[10], str2[10];
lenstr1 = } printf("Enter a
lengthstr(str1); *newstr = '\0'; string: ");
lenstr2 = return tempstr; gets(str);
lengthstr(str2); } printf("\nReversed
if(lenstr1 != lenstr2) int isPalindrome(char *str) string is: %s\n\n",revstr(str));
return {
0; char *tempstr; if(isPalindrome(str)
else tempstr = str; )
{ while(*str != '\0')
str++; printf("Given string
while(lenstr1 > 0) str--; is a palindrome\n\n");
{ while(tempstr <= else
str)
if(*str1 != *str2) { printf("Given string
is not a palindrome\n\n");
return if(*tempstr != *str)
0; printf("Length of
return 0; given string is:
str1++; %d\n\n",lengthstr(str));
tempstr++;
str2++; str--; printf("Enter string
} 1: ");
lenstr1--; return 1; gets(str1);
} } printf("Enter string
} char* revstr(char *c) 2: ");
return 1; { gets(str2);
} char *newstr, printf("\nstr2
char* concatstr(char *str1, *tempstr; concatenated with str1 gives:
char *str2) int count = 0; %s\n\n",concatstr(str1,str2));
{ while(*c != '\0')
int lenstr1, lenstr2; { if(cmpstr(str1,str2))
char c++;
*newstr,*tempstr; printf("Both the
count++; strings are same\n\n");
else
7. 8.
printf("Both the
strings are not same\n\n"); #include <stdio.h> #include<stdio.h>

getch(); void swapx(int x, int y); long int multiplyNumbers(int


return 0; n);
} int main()
int main() {
{
int n;
int a = 10, b = 20;
printf("Enter a positive
swapx(a, b); integer: ");

printf("a=%d b=%d\n", a, b); scanf("%d",&n);

return 0; printf("Factorial of %d =
%ld", n, multiplyNumbers);
}
return 0;
void swapx(int x, int y)
}
{
long int multiplyNumbers(int
int t; n) {

t = x; if (n>=1)

x = y; return
n*multiplyNumbers(n-1);
y = t;
else
printf("x=%d y=%d\n", x, y);
return 1;
}
}

You might also like