Showing posts with label c plus plus. Show all posts
Showing posts with label c plus plus. Show all posts

Tuesday, 2 April 2013

Convert the string into lowercase


Convert the string into lowercase:-

Q)Write a program to enter string and convert string(Character Array) into lowercase.

Note:-You can also create this program in c++(c plus plus),java,perl,c#(c sharp) languages etc. with the same logic.

P:void main()
{
char string[40];
int i;
printf("Enter String");
gets(string);
for(i=0;string[i]!='\o';i++)
{
if(string[i]>65 && string[i]<=90)
string[i]=string[i]+32;
}
puts(string);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Convert a string into uppercase


Convert string into uppercase:-

Q)Write a program to enter string(character array) and convert string into uppercase.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic.

P:void main()
{
char string[40];
int i;
printf("Enter String");
gets(string);
for(i=0;string[i]!='\o';i++)
{
if(string[i]>97 && string[i]<=122)
string[i]=string[i]-32;
}
puts(string);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Sunday, 31 March 2013

Copy String into the another String


Copy String into the another String:-

Function used-strcpy.This function is used to copy string(Character Array) into another string.

Q)Write a program to enter string and copy string into another string.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).

P:void main()
{
char string1[40],string2[40];
printf("Enter String");
gets(string1);
strcpy(string2,string1);
puts(string2);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Count the length of String with the help of program


Count length of String:-

Function used-strlen.This function is used to count the length of string.

Q)Write a program to enter string(character array) and count the length of string(without function).


Note:-You can also create this program in c++(c plus plus),java,perl,c#(c sharp) languages etc. with the same logic(Functions may be differ).

P:void main()
{
char string[40];
int i,l;
clrscr();
printf("Enter String");
gets(string);
l=0;
for(i=0;string[i]!='\o';i++)
{
l=l+1;
}
printf("Length of string");
getch();
}
If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Tuesday, 26 March 2013

Reverse of String


Reverse of String:-


Q)Write a program to enter string(Character Array) and print the reverse of string.

Function used-strrev.This function is used to reverse a string.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).


P:void main()
{
char string[40],reverse[40];
printf("Enter String");
gets(string);
strrev(string);
strcpy(reverse,string);
puts(reverse);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Compare two Strings(Character Array)


Compare two Strings(Character Array):-

Function used-strcmp.This function is used to compare two string.

Q)Write a program to enter two string and compare two strings.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).


P:void main()
{
char string1[40],string2[40];
printf("Enter first String");
gets(string1);
printf("Enter second String");
gets(string2);
if(strcmp(string1,string2)==0)
printf("String is equal");
else
printf("String is not equal");
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Concatenate of String or Character Array


Concatenate of Strings:-

Function used-strcat.strcat function is used to connect two string together.

Q)Write a program to enter two string and join the strings.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).

P:void main()
{
char string1[40],string2[40];
printf("Enter first String");
gets(string1);
printf("Enter second String");
gets(string2);
strcat(string1,string2);
puts(string1);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Character Array Or a String


Character Array Or a String is the sequence of characters which are used to create meaningful programs.String is terminated by null character(\o).

input=gets()

output=puts()

String(Formatting)=%s

Declaration and Initialisation of String:-

Syntax:-

data type string name[size];

Example:-

char string[40];

Some important operation performed in a string:-

1)Read and Write string

2)Add string

3)Copy string

4)Concatenate string

5)Compare string etc.

Simple/Basic program of Character Array Or a String:-

Q)Write a program to enter string and display the string.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages etc. with the same logic(Functions may be differ).


P:void main()
{
char string[40];
printf("Enter String");
gets(string);
printf("String are as follows");
puts(string);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Friday, 15 March 2013

Multiplication of Array Matrix with the help of program


Multiply two Array matrix with the help of Program:-

Q)Write a program to enter matrix(2) and print the multiplication of matrices.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.



void main()
{
int matrix1[10][20],matrix2[10][20],mul[20][30],i,j,row1,col1,row2,col2,s;
clrscr();
printf("Enter row and column");
scanf("%d%d",&row,&col);
printf("Enter first Matrix");
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
scanf("%d",&matrix1[i][j]);
}
}
printf("Enter second Matrix");
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
scanf("%d",&matrix2[i][j]);
}}
if(col1==row2)
{
for(i=0;i<row1;i++)
{
for(j=0;j<col2;j++)
{
s=0;
for(k=0;k<col1;k++)
{
s=s+matrix1[i][j]+matrix2[i][j];
mul[i][j]=s;
}}
printf("Matrix is");
for(i=0;i<row1;i++)
{
for(j=0;j<col2;j++)
{
printf("%d",mul[i][j]);
}
printf("\n");
}}
else
printf(No Result");
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Saturday, 9 March 2013

Sum of Array Matrix with the help of Program


Sum of Array Matrix:-

Q)Write a program to enter matrix(2) and print the sum of matrices.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


void main()
{
int matrix1[10][20],matrix2[10][20],sum[20][30],i,j,row,col;
clrscr();
printf("Enter row and column");
scanf("%d%d",&row,&col);
printf("Enter first Matrix");
for(i=0;i<row;i++)
{

for(j=0;j<col;j++)
{
scanf("%d",&matrix1[i][j]);
}
}
printf("Enter second Matrix");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&matrix2[i][j]);
}}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
sum[i][j]=matrix1[i][j]+matrix2[i][j];
}}
printf("Sum is");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d",&sum[i][j]);
}
printf("\n");
}
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Transpose of Array Matrix with the help of Program


Transpose of Array Matrix in C language:-

Q)Write a program to enter matrix and print the transpose of matrix.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.

void main()
{
int matrix[10][20],i,j,row,col;
clrscr();
printf("Enter row and column");
scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&matrix[i][j]);
}
}
printf("Transpose of Matrix is");
for(j=0;j<col;j++)
{
for(i=0;i<row;i++)
{
printf("%d",&matrix[i][j]);
}
printf("/n");
}
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Friday, 8 March 2013

2-D Array(2-Dimensional Array)


2-D Array or 2-Dimensional Array are the arrays which are the collection of rows and columns.

Syntax of 2-D array:-


name-of-matrix[Row size][Column size];


Example:-


int add-matrix[20][30]; 


Programming example of 2-d matrix in C language:-


Q)Write a program to create matrix and print the matrix.



Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.

void main()
{

int matrix[10][20],i,j,row,col;
clrscr();
printf("Enter row and column");
scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&matrix[i][j]);
}
}
printf("Matrix is");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d",&matrix[i][j]);
}
getch();
}}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Wednesday, 6 March 2013

Program to split array into another array


Split Program in C language:-

Q)Write a program to create array and split the array into two parts i.e. even and odd.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.



void main() 
{
int a[20],e[20],o[20],i,j,k,n;
clrscr();
printf("Enter array limit");
scanf("%d",&n);
printf("Enter array element");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
j=k=0;
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
e[j]=a[i];
j++;
}
else
{
o[k]=a[i];
k++;
}
}
printf("Even Array");
for(i=0;i<j;i++)
printf("%d",e[i]);
printf("Odd Array");
for(i=0;i<k;i++)
printf("%d",o[i]);
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Tuesday, 5 March 2013

Program to detect duplicacy and remove duplicate value


Program to detect duplicacy and remove duplicate value:-


Q)Write a program to create array and print the array without duplicacy.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
Void main()
{
int i,lim,a[50],p,q;
printf("enter limit");
scanf("%d",&l);
printf("Enter Array");
for(i=0;i<lim;i++)
scanf("%d",&a[i]);
for(i=0;i<lim-1;i++)
{
for(p=i+1;p<lim;p++)
{
if(a[i]==a[p])
{
for(q=p;q<lim-1;q++)
a[q]=a[q+1];
lim--;
p--;
}
}
}
printf("Array as follows");
for(i=0;i<lim;i++)
printf("%d",a[i]);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Program to print Reverse of Array


Reversing of Array in c programming:


Q)Write a program to create array and print the array in reverse format.

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
Void main()
{
int i,lim,a[50];
printf("enter limit");
scanf("%d",&l);
printf("Enter Array");
for(i=0;i<lim;i++)
scanf("%d",&a[i]);
for(i=lim-1;i>=0;i--)
printf("%d",a[i]);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Friday, 1 March 2013

Program to find minimum element of Array


Q)Write a program to create array and find the minimum or smallest element of array with its location?

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) etc. with the same logic.


P:void main()
{
int arr[30],i,limit,min,l;
printf("Enter limit");
scanf("%d"&l);
l=0;
printf("Enter Array");
for(i=0;i<limit;i++)
scanf("%d",&arr[i]);
min=arr[0];
l=0;
for(i=0;i<limit;i++)
{
if(arr[i]<min)
{
min=a[i];
l=i;
}
}
printf("%d",l=%d,min,l);
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Program to find maximum element of Array


Q)Write a program to create array and find the maximum or largest element of array with its location?

Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) etc. with the same logic.



P:void main()
{
int arr[30],i,limit,max,l;
printf("Enter limit");
scanf("%d"&l);
l=0;
printf("Enter Array");
for(i=0;i<limit;i++)
scanf("%d",&arr[i]);
max=arr[0];
l=0;
for(i=0;i<limit;i++)
{
if(arr[i]>max)
{
max=a[i];
l=i;
}
}
printf("%d",l=%d,max,l);
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Array in C Language


Arrays in C Language:-Array is the collection of similar type of element.
Declaration of Array in C Programming:-

data type ARRAY NAME[Size of Array]

Example:-char arr[30];

Array index always start from 0 to n-1.Array can be access randomly.Size is always numeric.

Sample program of Array:-


Q)Write a program to create array and print it.



P:void main()

{
int arr[30];
printf("Enter array");
for(i=0;i<20;i++)
scanf("%d",&arr[i]);
printf("Array is-");
for(i=0;i<20;i++)
printf("%d",arr[i]);
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Wednesday, 27 February 2013

Factor Program


Factor Program in C language:-

Q)Write a program in c language to enter a value and print factor of this number/value.


Note:-You can also create this program in java,c#,c++(c plus plus) etc. with the same logic.



P:#include<stdio.h>
void main()
{
int i,x;
printf("enter no.");
scanf("%d",&x);
for(i=0;i<=x;i++)
{
if(n%i==0)
printf("%d",i);
}
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Armstrong Program


Program of Armstrong Number:

Armstrong no. like 153 = (1*1*1)+(5*5*5)+(3*3*3).

Q)Write a program in c language to enter a value and check the number is Armstrong or not.

Note:-You can also create this program in java,c#,c++(c plus plus) etc. with the same logic.


P:#include<stdio.h>
void main()
{
int s,n,d;
printf("enter no.");
scanf("%d",&n);
s=0,a=n;
while(n!=0)
{
d=n%10;
s=s*d*d*d;
n=n/10;
}
if(a==s)
printf("Number is Armstrong");
else
printf("Number is not Armstrong");
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.