#include <stdio.h>
int main()
{
int num[] = {2,8,7,6,0};
int i;
for(i=0;i<5;i++) {
printf("\nArray Element of num[%d] : %d",i+1,num[i]);
}
return 0;
}
///different way
int main()
{
int arr[3],i;
printf(“Enter 3 values:”);
for(i=0;i<3;i++)
{
scanf("%d",&arr[i])
}
printf(“\nThe entered values are:”);
for(i=0;i<3;i++)
{
printf("%d ",arr[i]);
}
return 0;
}
Tuesday, June 30, 2015
Calculator by function
#include<stdio.h>
int add(int x, int y );
int sub(int a, int b );
int mult(int d, int e);
int div(int g, int h);
int main(){
int num1, num2, choice;
printf("[0] Exit\n[1] Addition\n[2] Subtraction\n[3] Multiplication\n[4] Division\n");
scanf("%d", &choice);
switch(choice){
case 0:
exit(0);
case 1:
printf("Enter 1st number:");
scanf("%d", &num1);
printf("\nEnter 2nd number:");
scanf("%d", &num2);
printf("\nThe addition is:%d\n", add( num1,num2));
break;
case 2:
printf("Enter 1st number:");
scanf("%d", &num1);
printf("\nEnter 2nd number:");
scanf("%d", &num2);
printf("\nThe subtraction is:%d\n", sub(num1,num2));
break;
case 3:
printf("Enter 1st number:");
scanf("%d", &num1);
printf("\nEnter 2nd number:");
scanf("%d", &num2);
printf("\nThe multiplication is:%d\n", mult(num1,num2));
break;
case 4:
printf("Enter 1st number:");
scanf("%d", &num1);
printf("\nEnter 2nd number:");
scanf("%d", &num2);
printf("\nThe division is:%d\n", div(num1,num2));
break;
default:
printf("\nInvalid choice!!!!!!!\n");
break;
}
}
int add(int x,int y){
int z;
z = x + y;
return z;
}
int sub(int a,int b){
int c;
c = a - b;
return c;
}
int mult(int d,int e){
int f;
f = d * e;
return f;
}
int div(int g,int h){
int i;
i = g / h;
return i;
}
int add(int x, int y );
int sub(int a, int b );
int mult(int d, int e);
int div(int g, int h);
int main(){
int num1, num2, choice;
printf("[0] Exit\n[1] Addition\n[2] Subtraction\n[3] Multiplication\n[4] Division\n");
scanf("%d", &choice);
switch(choice){
case 0:
exit(0);
case 1:
printf("Enter 1st number:");
scanf("%d", &num1);
printf("\nEnter 2nd number:");
scanf("%d", &num2);
printf("\nThe addition is:%d\n", add( num1,num2));
break;
case 2:
printf("Enter 1st number:");
scanf("%d", &num1);
printf("\nEnter 2nd number:");
scanf("%d", &num2);
printf("\nThe subtraction is:%d\n", sub(num1,num2));
break;
case 3:
printf("Enter 1st number:");
scanf("%d", &num1);
printf("\nEnter 2nd number:");
scanf("%d", &num2);
printf("\nThe multiplication is:%d\n", mult(num1,num2));
break;
case 4:
printf("Enter 1st number:");
scanf("%d", &num1);
printf("\nEnter 2nd number:");
scanf("%d", &num2);
printf("\nThe division is:%d\n", div(num1,num2));
break;
default:
printf("\nInvalid choice!!!!!!!\n");
break;
}
}
int add(int x,int y){
int z;
z = x + y;
return z;
}
int sub(int a,int b){
int c;
c = a - b;
return c;
}
int mult(int d,int e){
int f;
f = d * e;
return f;
}
int div(int g,int h){
int i;
i = g / h;
return i;
}
Swapping elements by function
#include<stdio.h>
///Swapping by function
void swap(int a, int b);
int main()
{
int x, y;
printf("Enter the value of x and y:");
scanf("%d%d",&x,&y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
swap(x,y);
return 0;
}
void swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
printf("After Swapping\nx = %d\ny = %d\n", a, b);
}
///Swapping by function
void swap(int a, int b);
int main()
{
int x, y;
printf("Enter the value of x and y:");
scanf("%d%d",&x,&y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
swap(x,y);
return 0;
}
void swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
printf("After Swapping\nx = %d\ny = %d\n", a, b);
}
Sunday, June 28, 2015
Hello world
#include <iostream>
/***
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
***/
/***
// my second program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World! ";
cout << "I'm a C++ program";
}
***/
/***
// my second program in C++
#include <iostream>
int main ()
{
std::cout << "Hello World! ";
std::cout << "I'm a C++ program";
}
***/
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World! ";
cout << "I'm a C++ program";
}
***/
/***
// my second program in C++
#include <iostream>
int main ()
{
std::cout << "Hello World! ";
std::cout << "I'm a C++ program";
}
***/
The value of EOF
#include <stdio.h>
int main(void)
{
printf("EOF == %d\n", EOF);
return 0;
}
output:
EOF = = -1
int main(void)
{
printf("EOF == %d\n", EOF);
return 0;
}
output:
EOF = = -1
Sort a string
#include<stdio.h>
#include<conio.h>
///sort a string
int main()
{
char str[100],temp;
int i,j;
printf("Enter the string :");
gets(str);
for(i=0;i<strlen(str);i++)
{
for(j=i+1;j<strlen(str);j++)
{
if(str[j]<str[i])
{
temp=str[j];
str[j]=str[i];
str[i]=temp;
}
}
}
printf("\n------------------------------------\n");
printf("\nThe sorted string is:%s\n",str);
printf("\n------------------------------------\n");
return 0;
}
#include<conio.h>
///sort a string
int main()
{
char str[100],temp;
int i,j;
printf("Enter the string :");
gets(str);
for(i=0;i<strlen(str);i++)
{
for(j=i+1;j<strlen(str);j++)
{
if(str[j]<str[i])
{
temp=str[j];
str[j]=str[i];
str[i]=temp;
}
}
}
printf("\n------------------------------------\n");
printf("\nThe sorted string is:%s\n",str);
printf("\n------------------------------------\n");
return 0;
}
Upper case letter to lower case letter
#include<stdio.h>
/***
int main()
{
char a;
printf("enter a character:");
while(1){
scanf("%c",&a);
if(a==48)
break;
if(a>=65&&a<=90)
printf("%c ",a+32);
}
return 0;
}
***/
#include<stdio.h>
int main(){
char str[100];
int i;
printf("Enter any string:\n");
scanf("%s",str);
printf("\nThe string is:%s\n",str);
for(i=0;i<strlen(str);i++){
if(str[i]>=65&&str[i]<=90)
str[i]=str[i]+32;
}
printf("\nThe Lower case string is:%s\n",str);
return 0;
}
/***
int main()
{
char a;
printf("enter a character:");
while(1){
scanf("%c",&a);
if(a==48)
break;
if(a>=65&&a<=90)
printf("%c ",a+32);
}
return 0;
}
***/
#include<stdio.h>
int main(){
char str[100];
int i;
printf("Enter any string:\n");
scanf("%s",str);
printf("\nThe string is:%s\n",str);
for(i=0;i<strlen(str);i++){
if(str[i]>=65&&str[i]<=90)
str[i]=str[i]+32;
}
printf("\nThe Lower case string is:%s\n",str);
return 0;
}
Common number in a array
#include<stdio.h>
int main()
{
int i,j=5,a[4],n,count=0;
for(i=0; i<4; i++)
scanf("%d",&a[i]);
for(i=0; i<4; i++)
{
printf("%d ",a[i]);
if(a[i]==j)
{
count++;
}
}
printf("\nNo 5 exist in this array %d times",count);
return 0;
}
int main()
{
int i,j=5,a[4],n,count=0;
for(i=0; i<4; i++)
scanf("%d",&a[i]);
for(i=0; i<4; i++)
{
printf("%d ",a[i]);
if(a[i]==j)
{
count++;
}
}
printf("\nNo 5 exist in this array %d times",count);
return 0;
}
Saturday, June 27, 2015
Least common multiple & greatest common divisor
#include<stdio.h>
/*** l.c.m and g.c.d ***/
int main()
{
int num1,num2,x,y;
printf("\nEnter two numbers:");
scanf("%d %d",&num1,&num2);
x=num1,y=num2;
while(num1!=num2){
if(num1>num2)
num1=num1-num2;
else
num2=num2-num1;
}
printf("L.C.M=%d\nG.C.D=%d",x*y/num2,num1);
return 0;
}
/*** l.c.m and g.c.d ***/
int main()
{
int num1,num2,x,y;
printf("\nEnter two numbers:");
scanf("%d %d",&num1,&num2);
x=num1,y=num2;
while(num1!=num2){
if(num1>num2)
num1=num1-num2;
else
num2=num2-num1;
}
printf("L.C.M=%d\nG.C.D=%d",x*y/num2,num1);
return 0;
}
npr & ncr
#include<stdio.h>
///npr and ncr
int main()
{
int n,r,ncr,npr;
printf("Enter two numbers(n,r):");
scanf("%d %d",&n,&r);
ncr=fact(n)/(fact(r)*fact(n-r));
npr=fact(n)/(fact(n-r));
printf("\n---------------------------------------");
printf("\nThe ncr and npr is:%dC%d=%d %dP%d=%d",n,r,ncr,n,r,npr);
printf("\n---------------------------------------\n");
return 0;
}
int fact(int n)
{
int factorial=1,i;
for(i=1;i<=n;i++)
{
factorial=factorial*i;
}
return factorial;
}
///npr and ncr
int main()
{
int n,r,ncr,npr;
printf("Enter two numbers(n,r):");
scanf("%d %d",&n,&r);
ncr=fact(n)/(fact(r)*fact(n-r));
npr=fact(n)/(fact(n-r));
printf("\n---------------------------------------");
printf("\nThe ncr and npr is:%dC%d=%d %dP%d=%d",n,r,ncr,n,r,npr);
printf("\n---------------------------------------\n");
return 0;
}
int fact(int n)
{
int factorial=1,i;
for(i=1;i<=n;i++)
{
factorial=factorial*i;
}
return factorial;
}
output:
Enter two numbers(n,r):5 4
---------------------------------------
The ncr and npr is:5C4=5 5P4=120
---------------------------------------
Friday, June 26, 2015
We are in love
#include<stdio.h>
///simple loving program
///koushikahamed@yahoo.com
int main()
{
system("color 1C");
char a[100],b [100],approval[10],yes[10];
printf("Please enter the boy name:");
gets(a);
printf("\nPlease enter the girl name:");
gets(b);
printf("\n%s Do you love %s ??\n",b,a);
printf("\nplease don't be late!!!!! %s is waiting\n",a);
printf("\nexpress your feelings %s\n",b);
printf("\nif you interested with %s type y/no\n",a);
scanf("%s",approval);
printf("\nif you love %s type y/no\n",a);
scanf("%s",yes);
strcpy(approval,yes);
strrev(approval);
if(strcmp(approval,yes)==0)
{
printf("\n<<<%s + %s>>> is a great couple>>>\n",a,b);
printf("\n");
printf(" .*'''*'''*:*'''*'''*; \n");
printf(" * %s+%s ''' \n",a,b);
printf(" * * \n");
printf(" * * \n");
printf(" * * \n");
printf(" * \n");
}
else if(strcmp(approval,yes)!=0)
printf("\n%s and %s is not couple they are seems to be good friend>>>\n",a,b);
return 0;
}
///simple loving program
///koushikahamed@yahoo.com
int main()
{
system("color 1C");
char a[100],b [100],approval[10],yes[10];
printf("Please enter the boy name:");
gets(a);
printf("\nPlease enter the girl name:");
gets(b);
printf("\n%s Do you love %s ??\n",b,a);
printf("\nplease don't be late!!!!! %s is waiting\n",a);
printf("\nexpress your feelings %s\n",b);
printf("\nif you interested with %s type y/no\n",a);
scanf("%s",approval);
printf("\nif you love %s type y/no\n",a);
scanf("%s",yes);
strcpy(approval,yes);
strrev(approval);
if(strcmp(approval,yes)==0)
{
printf("\n<<<%s + %s>>> is a great couple>>>\n",a,b);
printf("\n");
printf(" .*'''*'''*:*'''*'''*; \n");
printf(" * %s+%s ''' \n",a,b);
printf(" * * \n");
printf(" * * \n");
printf(" * * \n");
printf(" * \n");
}
else if(strcmp(approval,yes)!=0)
printf("\n%s and %s is not couple they are seems to be good friend>>>\n",a,b);
return 0;
}
output:
Please enter the boy name:Romeo
Please enter the girl name:Juliet
Juliet Do you love Romeo ??
please don't be late!!!!! Romeo is waiting
express your feelings Juliet
if you interested with Romeo type y/no
y
if you love Romeo type y/no
y
<<<Romeo + Juliet>>> is a great couple>>>
.*'''*'''*:*'''*'''*;
* Romeo+Juliet '
* *
* *
* *
*
Array reverse,summation ,average
#include<stdio.h>
#include<conio.h>
int main()
{
int a[100],b[100],temp,i,j,n,sum=0;
float avg;
printf("How many numbers do you want in array:");
scanf("%d",&n);
puts("\nplease enter the number of array:");
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(i=1; i<=n; i++)
{
printf("%d",&a[i]);
sum=sum+a[i];
avg=(float)(sum)/n;
}
puts("----------------------");
printf("The sum of the array is:%d",sum);
puts("\n----------------------");
printf("The average of the array is:%.2f",avg);
puts("\n----------------------");
puts("The reversed array is:");
puts("----------------------");
for(i=n; i>=1; i--)
{
printf("%d ",a[i]);
}
return 0;
}
output:
How many numbers do you want in array:5
please enter the number of array:
4 7 9 3 8
----------------------
The sum of the array is:31
----------------------
The average of the array is:6.20
----------------------
The reversed array is:
----------------------
8 3 9 7 4
#include<conio.h>
int main()
{
int a[100],b[100],temp,i,j,n,sum=0;
float avg;
printf("How many numbers do you want in array:");
scanf("%d",&n);
puts("\nplease enter the number of array:");
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(i=1; i<=n; i++)
{
printf("%d",&a[i]);
sum=sum+a[i];
avg=(float)(sum)/n;
}
puts("----------------------");
printf("The sum of the array is:%d",sum);
puts("\n----------------------");
printf("The average of the array is:%.2f",avg);
puts("\n----------------------");
puts("The reversed array is:");
puts("----------------------");
for(i=n; i>=1; i--)
{
printf("%d ",a[i]);
}
return 0;
}
output:
How many numbers do you want in array:5
please enter the number of array:
4 7 9 3 8
----------------------
The sum of the array is:31
----------------------
The average of the array is:6.20
----------------------
The reversed array is:
----------------------
8 3 9 7 4
Wednesday, June 24, 2015
Pattern
#include<stdio.h>
///pattern
int main()
{
int i,rows,n;
char j;
printf("Enter the number of rows: ");
scanf("%d",&rows);
for(i=65;i<=65+rows;i++)
{
for(j=65;j<i;j++)
{
printf("%c ",j);
}
printf("\n");
}
return 0;
}
///pattern
int main()
{
int i,rows,n;
char j;
printf("Enter the number of rows: ");
scanf("%d",&rows);
for(i=65;i<=65+rows;i++)
{
for(j=65;j<i;j++)
{
printf("%c ",j);
}
printf("\n");
}
return 0;
}
output:
A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
ABCDEFGH
Friday, June 19, 2015
pattern-character
int main()
{
int i,rows,n;
char j;
printf("Enter the number of rows: ");
scanf("%d",&rows);
printf("Enter how much number or char you will print: ");
scanf("%d",&n);
for(i=1;i<=rows;i++)
{
for(j=65;j<=n-1;j++)
{
printf("%c ",j);
}
printf("\n");
n--;
}
return 0;
}
otuput:
A B C D E F G H I J
A B C D E F G H I
A B C D E F G H
A B C D E F G
A B C D E F
A B C D E
A B C D
A B C
A B
A
{
int i,rows,n;
char j;
printf("Enter the number of rows: ");
scanf("%d",&rows);
printf("Enter how much number or char you will print: ");
scanf("%d",&n);
for(i=1;i<=rows;i++)
{
for(j=65;j<=n-1;j++)
{
printf("%c ",j);
}
printf("\n");
n--;
}
return 0;
}
otuput:
A B C D E F G H I J
A B C D E F G H I
A B C D E F G H
A B C D E F G
A B C D E F
A B C D E
A B C D
A B C
A B
A
Sunday, June 14, 2015
series((1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n))
#include<stdio.h>
///(1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n)
int main()
{
int i,j,n,sum=0;
n=10;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
sum+=j;
}
}
printf("Sum: %d",sum);
return 0;
}
///(1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n)
int main()
{
int i,j,n,sum=0;
n=10;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
sum+=j;
}
}
printf("Sum: %d",sum);
return 0;
}
Saturday, June 13, 2015
series(1+3+5+7+9+...........+n)
#include<stdio.h>
///odd number series:
int main ()
{
int i,num,sum=0;
printf("Please enter any number:");
scanf("%d",&num);
for(i=1;i<=num;i=i+2)
{
printf("%d ",i);
sum=sum+i;
}
printf("\nThe sum of the odd number series is:%d",sum);
return 0;
}
///odd number series:
int main ()
{
int i,num,sum=0;
printf("Please enter any number:");
scanf("%d",&num);
for(i=1;i<=num;i=i+2)
{
printf("%d ",i);
sum=sum+i;
}
printf("\nThe sum of the odd number series is:%d",sum);
return 0;
}
series(2+4+6+8+............+n)
#include<stdio.h>
///Even number series:
int main ()
{
int i,num,sum=0;
printf("Please enter any number:");
scanf("%d",&num);
for(i=2;i<=num;i=i+2)
{
printf("%d ",i);
sum=sum+i;
}
printf("\nThe sum of the even number series is:%d",sum);
return 0;
}
///Even number series:
int main ()
{
int i,num,sum=0;
printf("Please enter any number:");
scanf("%d",&num);
for(i=2;i<=num;i=i+2)
{
printf("%d ",i);
sum=sum+i;
}
printf("\nThe sum of the even number series is:%d",sum);
return 0;
}
series(1/1 + 1/2 + 1/3 + 1/4 + . . . + 1/n----A.P)
#include<stdio.h>
///1/1 + 1/2 + 1/3 + 1/4 + . . . + 1/n
int main()
{
float num,i,sum=0;
printf("Please enter any number:\n");
scanf("%f", &num);
for (i=1;i<=num;i++)
{
sum=sum +(1/i);
if (i==1)
printf("\nThe series is: 1+");
else if (i==num)
printf("(1/%.0f)\n",i);
else
printf("(1/%.0f)+",i);
}
printf("\nThe sum of the series is:%.2f\n", sum);
return 0;
}
///1/1 + 1/2 + 1/3 + 1/4 + . . . + 1/n
int main()
{
float num,i,sum=0;
printf("Please enter any number:\n");
scanf("%f", &num);
for (i=1;i<=num;i++)
{
sum=sum +(1/i);
if (i==1)
printf("\nThe series is: 1+");
else if (i==num)
printf("(1/%.0f)\n",i);
else
printf("(1/%.0f)+",i);
}
printf("\nThe sum of the series is:%.2f\n", sum);
return 0;
}
series(1^3 + 2^3 + 3^3+ .....+n^3)
///1^3 + 2^3 + 3^3+ .....+n^3
int main(){
int n,i;
int sum=0;
printf("Enter any end number of this series: ");
scanf("%d",&n);
sum = (((n*(n + 1) ) / 2))*(((n*(n + 1) ) / 2));
printf("\nSum of the series:");
for(i =1;i<=n;i++){
if (i!= n)
printf("%d^3+",i);
else
printf("%d^3=%d\n ",i,sum);
}
return 0;
}
series(1^2 + 2^2 + …. + n^2)
#include<stdio.h>
///1^2 + 2^2 + …. + n^2
int main(){
int n,i;
int sum=0;
printf("Enter any end number of this series: ");
scanf("%d",&n);
sum = (n * (n + 1) * (2 * n + 1 )) / 6;
printf("Sum of the series : ");
for(i =1;i<=n;i++){
if (i != n)
printf("%d^2 + ",i);
else
printf("%d^2 = %d ",i,sum);
}
return 0;
}
///1^2 + 2^2 + …. + n^2
int main(){
int n,i;
int sum=0;
printf("Enter any end number of this series: ");
scanf("%d",&n);
sum = (n * (n + 1) * (2 * n + 1 )) / 6;
printf("Sum of the series : ");
for(i =1;i<=n;i++){
if (i != n)
printf("%d^2 + ",i);
else
printf("%d^2 = %d ",i,sum);
}
return 0;
}
series(1 + 2 + 3 + … + n)
#include<stdio.h>
///1 + 2 + 3 + … + n
int main(){
int n,i;
int sum=0;
printf("Enter any end number of this series: ");
scanf("%d",&n);
sum = (n * (n + 1)) / 2;
printf("Sum of the series: ");
for(i =1;i <= n;i++){
if (i!=n)
printf("%d + ",i);
else
printf("%d=%d ",i,sum);
}
return 0;
}
///1 + 2 + 3 + … + n
int main(){
int n,i;
int sum=0;
printf("Enter any end number of this series: ");
scanf("%d",&n);
sum = (n * (n + 1)) / 2;
printf("Sum of the series: ");
for(i =1;i <= n;i++){
if (i!=n)
printf("%d + ",i);
else
printf("%d=%d ",i,sum);
}
return 0;
}
Thursday, June 4, 2015
Array(3)
#include <stdio.h>
///search a number using an arary using linear search.
int main()
{
int ara[100],i,key,n,loc,ck;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&ara[i]);
scanf("%d",&key);
ck=0;
for(i=0;i<n;i++){
if (ara[i]==key){
ck=1;
loc=i+1;
break;
}
}
if (ck==1)
printf("%d",loc);
else
printf("No");
return 0;
}
///search a number using an arary using linear search.
int main()
{
int ara[100],i,key,n,loc,ck;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&ara[i]);
scanf("%d",&key);
ck=0;
for(i=0;i<n;i++){
if (ara[i]==key){
ck=1;
loc=i+1;
break;
}
}
if (ck==1)
printf("%d",loc);
else
printf("No");
return 0;
}
Array(2)
#include <stdio.h>
///array traversing/array searching
int main()
{
int ara[5]={1,44,67,56,46},i;
///for(i=0;i<5;i++){
/// printf("%d ",ara[i]);
///}
///for(i=4;i>=0;i--){
printf("%d ",ara[3]);
///}
return 0;
}
///array traversing/array searching
int main()
{
int ara[5]={1,44,67,56,46},i;
///for(i=0;i<5;i++){
/// printf("%d ",ara[i]);
///}
///for(i=4;i>=0;i--){
printf("%d ",ara[3]);
///}
return 0;
}
Array(1)
#include <stdio.h>
///array_declare
int main()
{
int ara[5]={1,2,4,6,99},i;
ara[0]=5;
ara[3]=66;
for(i=0;i<5;i++){
printf("%d\n",ara[i]);
}
return 0;
}
///array_declare
int main()
{
int ara[5]={1,2,4,6,99},i;
ara[0]=5;
ara[3]=66;
for(i=0;i<5;i++){
printf("%d\n",ara[i]);
}
return 0;
}
string(11)
#include <stdio.h>
///string function:
///***strspn ,strcspn****
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="kbcdef";
///int len;
///len=strspn(str1,str2);
///printf("%d\n",len);
///return 0;
///}
int main()
{
char str1[100]="koushik";
char str2[100]="abcdhf";
int len;
len=strcspn(str1,str2);
printf("%d\n",len);
return 0;
}
///string function:
///***strspn ,strcspn****
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="kbcdef";
///int len;
///len=strspn(str1,str2);
///printf("%d\n",len);
///return 0;
///}
int main()
{
char str1[100]="koushik";
char str2[100]="abcdhf";
int len;
len=strcspn(str1,str2);
printf("%d\n",len);
return 0;
}
string(10)
#include <stdio.h>
#include <string.h>
///string (function)
///int main()
///{
///char str[100]="koushik";
///strlen(str);
///printf("%d\n",strlen(str));
///return 0;
///}
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="Ahamed";
///strcpy(str1,str2);
///printf("%s\n",str1);
///return 0;
///}
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="Ahamed";
///strncpy(str1,str2,3);
///str1[3]='\0';
///printf("%s\n",str1);
///return 0;
///}
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="Ahamed";
///strcat(str1," ");
///strcat(str1,str2);
///printf("%s\n",str1);
///return 0;
///}
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="Ahamedkushal";
///strncat(str1,str2,6);
///printf("%s\n",str1);
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="AYZ";
///strcmp(str1,str2);
///printf("%d",strcmp(str1,str2));
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="XYZ";
///strcmp(str1,str2);
///printf("%d",strcmp(str1,str2));
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="BCD";
///strcmp(str1,str2);
///printf("%d",strcmp(str1,str2));
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="BCD";
///if(strcmp(str1,str2)==0);
///printf("They are same\n");
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="BCD";
///if(!strcmp(str1,str2));
///printf("They are same\n");
///return 0;
///}
///int main()
///{
///char str1[100]="BBD";
///char str2[100]="BDB";
///strncmp(str1,str2,2);
///printf("%d",strncmp(str1,str2,2));
///return 0;
///}
///int main()
///{
///char str1[100]="BBD";
///char str2[100]="BBB";
///if(!strncmp(str1,str2,2));
///printf("They are same\n");
///return 0;
///}
int main()
{
char str1[100]="BBB";
char str2[100]="BBB";
printf("%d",strcoll(str1,str2));
return 0;
}
///***strcmp and strcoll closely same ***///
#include <string.h>
///string (function)
///int main()
///{
///char str[100]="koushik";
///strlen(str);
///printf("%d\n",strlen(str));
///return 0;
///}
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="Ahamed";
///strcpy(str1,str2);
///printf("%s\n",str1);
///return 0;
///}
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="Ahamed";
///strncpy(str1,str2,3);
///str1[3]='\0';
///printf("%s\n",str1);
///return 0;
///}
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="Ahamed";
///strcat(str1," ");
///strcat(str1,str2);
///printf("%s\n",str1);
///return 0;
///}
///int main()
///{
///char str1[100]="koushik";
///char str2[100]="Ahamedkushal";
///strncat(str1,str2,6);
///printf("%s\n",str1);
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="AYZ";
///strcmp(str1,str2);
///printf("%d",strcmp(str1,str2));
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="XYZ";
///strcmp(str1,str2);
///printf("%d",strcmp(str1,str2));
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="BCD";
///strcmp(str1,str2);
///printf("%d",strcmp(str1,str2));
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="BCD";
///if(strcmp(str1,str2)==0);
///printf("They are same\n");
///return 0;
///}
///int main()
///{
///char str1[100]="BCD";
///char str2[100]="BCD";
///if(!strcmp(str1,str2));
///printf("They are same\n");
///return 0;
///}
///int main()
///{
///char str1[100]="BBD";
///char str2[100]="BDB";
///strncmp(str1,str2,2);
///printf("%d",strncmp(str1,str2,2));
///return 0;
///}
///int main()
///{
///char str1[100]="BBD";
///char str2[100]="BBB";
///if(!strncmp(str1,str2,2));
///printf("They are same\n");
///return 0;
///}
int main()
{
char str1[100]="BBB";
char str2[100]="BBB";
printf("%d",strcoll(str1,str2));
return 0;
}
///***strcmp and strcoll closely same ***///
string(9)
#include <stdio.h>
#include <string.h>
int main()
{
char n1[100],n2[100];
while(scanf("%s%s",n1,n2) !=EOF){
/// if(strchr(n1)>strchr(n2))
/// printf("a > b \n");
///else if(strchr(n1)<strchr(n2))
/// printf("a < b \n");
if(strlen(n1)>strlen(n2))
printf("a > b \n");
else if(strlen(n1)<strlen(n2))
printf("a < b\n");
else if(strcmp(n1,n2)==0)
printf("a = b\n");
else if(strcmp(n1,n2)>0)
printf("a > b\n");
else
printf("a < b\n");
}
return 0;
}
#include <string.h>
int main()
{
char n1[100],n2[100];
while(scanf("%s%s",n1,n2) !=EOF){
/// if(strchr(n1)>strchr(n2))
/// printf("a > b \n");
///else if(strchr(n1)<strchr(n2))
/// printf("a < b \n");
if(strlen(n1)>strlen(n2))
printf("a > b \n");
else if(strlen(n1)<strlen(n2))
printf("a < b\n");
else if(strcmp(n1,n2)==0)
printf("a = b\n");
else if(strcmp(n1,n2)>0)
printf("a > b\n");
else
printf("a < b\n");
}
return 0;
}
Subscribe to:
Posts (Atom)