Monday, March 27, 2017
Write a program that will take a string and count ' a '
#include<stdio.h>
#include<string.h>
main()
{
int i,j,count=0;
char str1[100],str2[100];
printf("Enter first string ");
write a program that will take 2 string from user and concatenate the 2nd string after first string
#include<stdio.h>
#include<string.h>
main()
{
int i,j;
char str1[100],str2[100];
printf("Enter first string ");
gets(str1);/// str1 = "We"
#include<string.h>
main()
{
int i,j;
char str1[100],str2[100];
printf("Enter first string ");
gets(str1);/// str1 = "We"
write a program that will take 2 string from user and copy the string into first string
#include<stdio.h>
main()
{
int i;
char str1[100],str2[100];
printf("Enter first string ");
gets(str1);/// str1 = "We"
main()
{
int i;
char str1[100],str2[100];
printf("Enter first string ");
gets(str1);/// str1 = "We"
write a program that will show the max value in an array using function
#include<stdio.h>
void maximum(int array[],int i)
{
int max = array[0];///3
int min = array[0];///3
void maximum(int array[],int i)
{
int max = array[0];///3
int min = array[0];///3
Sunday, March 26, 2017
Array input and out and sum using function in c
///Array display using function
///write a program that will print their value and sum
#include<stdio.h>
int arrayDisplay(int b[],int i)
{
int sum =0;
for(i=0;i<5;i++)
{
printf("%d ",b[i]);
sum =sum + b[i];
}
// printf("\nsum = %d\n",sum);
return sum ;
}
void main()
{
int a[]={3,4,5,6,7},i;
printf("sum =%d",arrayDisplay(a,i));
}
Function in c with return example
/// write a program that will take two
///integers and find out their summation
///in add() function and also the subtraction in sub() function
#include<stdio.h>
int add(int a, int b )
{
return a + b ;
}
int sub(int a,int b)
{
return a-b;
}
void main()
{
scanf("%d%d",&a,&b);
printf("Summation = %d \n",add(a,b));
printf("subtraction = %d \n",sub(a,b));
}
///integers and find out their summation
///in add() function and also the subtraction in sub() function
#include<stdio.h>
int add(int a, int b )
{
return a + b ;
}
int sub(int a,int b)
{
return a-b;
}
void main()
{
scanf("%d%d",&a,&b);
printf("Summation = %d \n",add(a,b));
printf("subtraction = %d \n",sub(a,b));
}
Add sub and multiplication example in c with function 3
#include<stdio.h>
void add(int x ,int b,char letter)
{
printf("summation=%d \n",x+b);
}
void sub(int x,int y)
{
printf("subtraction=%d \n",x-y);
}
multi(int p,int q,float r)
{
printf("multiplication=%f \n",p*q*r);
}
void main()
{
printf("We R in main function \n");
int a,b;
printf("Enter 2 value \n");
scanf("%d%d",&a,&b);
add(a,b,'A'); ///parameter = pass by value
sub(a,b);
multi(a,b,8.5);
}
void add(int x ,int b,char letter)
{
printf("summation=%d \n",x+b);
}
void sub(int x,int y)
{
printf("subtraction=%d \n",x-y);
}
multi(int p,int q,float r)
{
printf("multiplication=%f \n",p*q*r);
}
void main()
{
printf("We R in main function \n");
int a,b;
printf("Enter 2 value \n");
scanf("%d%d",&a,&b);
add(a,b,'A'); ///parameter = pass by value
sub(a,b);
multi(a,b,8.5);
}
Add sub and multiplication in c with function 2
#include<stdio.h>
int a,b;
void add()
{
//int a=6,b=3; // local var
// a=6;
// b=1;
printf("Enter two values for addition \n");
scanf("%d%d",&a,&b);
printf("summation=%d \n",a+b);
}
void sub()
{
printf("Enter two values for subtraction \n");
scanf("%d%d",&a,&b);
printf("subtraction=%d \n",a-b);
}
void multi()
{
printf("Enter two values for multiplication \n");
scanf("%d%d",&a,&b);
printf("multiplication=%d \n",a*b);
}
main()
{
printf("We R in main function \n");
add();
sub();
multi();
}
int a,b;
void add()
{
//int a=6,b=3; // local var
// a=6;
// b=1;
printf("Enter two values for addition \n");
scanf("%d%d",&a,&b);
printf("summation=%d \n",a+b);
}
void sub()
{
printf("Enter two values for subtraction \n");
scanf("%d%d",&a,&b);
printf("subtraction=%d \n",a-b);
}
void multi()
{
printf("Enter two values for multiplication \n");
scanf("%d%d",&a,&b);
printf("multiplication=%d \n",a*b);
}
main()
{
printf("We R in main function \n");
add();
sub();
multi();
}
Add sub and multiplication in c with function 1
#include<stdio.h>
void add()
{
int a=6,b=3;
printf("summation=%d \n",a+b);
}
void sub()
{
int a=10,b=3;
printf("subtraction=%d \n",a-b);
}
void multi()
{
int a=10,b=3;
printf("multiplication=%d \n",a*b);
}
main()
{
printf("We R in main function \n");
add();
sub();
multi();
}
void add()
{
int a=6,b=3;
printf("summation=%d \n",a+b);
}
void sub()
{
int a=10,b=3;
printf("subtraction=%d \n",a-b);
}
void multi()
{
int a=10,b=3;
printf("multiplication=%d \n",a*b);
}
main()
{
printf("We R in main function \n");
add();
sub();
multi();
}
Function example 1 in c
#include<stdio.h>
void shukrabad()
{
printf("We R in Shukrabad\n ");
}
main()
{
shukrabad();
printf("We R in main function \n");
shukrabad();
}
void shukrabad()
{
printf("We R in Shukrabad\n ");
}
main()
{
shukrabad();
printf("We R in main function \n");
shukrabad();
}
Thursday, March 23, 2017
String reverse in briefly
#include<stdio.h>
main()
{
int i;
char st[15];
gets(st);///st="we are"
// puts(st);///st="we"
// for(i=0;i<st[i]!=NULL;i++)
// {
// //printf("%c",st[i]);
// count++;
// }
// printf("Length=%d",count);
//int length=strlen(st);
//printf("Length=%d",length);
for(i=strlen(st)-1;i>=0;i--)
{
printf("%c",st[i]);
}
}
String reverse using strrev()
#include<stdio.h>
main()
{
char st[15];
gets(st);///st="we"
puts(st);///st="we"
strrev(st);///st="ew"
puts(st);///st="ew"
}
Monday, March 20, 2017
Sum of 2 matrix
#include<stdio.h>
main()
{
int row,col;
int A[2][2]={3,4,2,6};
printf("Matrix A :\n");
main()
{
int row,col;
int A[2][2]={3,4,2,6};
printf("Matrix A :\n");
Input a matrix and output(2D Array practice)
#include<stdio.h>
main()
{
int row,col,i,j;
printf("Row number = ");
scanf("%d",&row);///row = 3
printf("Col number = ");
scanf("%d",&col);///col = 2
int A[row][col];
main()
{
int row,col,i,j;
printf("Row number = ");
scanf("%d",&row);///row = 3
printf("Col number = ");
scanf("%d",&col);///col = 2
int A[row][col];
Declaration and print of 2 D Array
#include<stdio.h>
main()
{
int row,col;
int A[2][2]={3,4,2,6};
printf("Matrix A :\n");
for(row=0;row<2;row++)
{
for(col=0;col<2;col++)
{
printf("\tA[%d][%d]=%d ",row,col,A[row][col]);
}
printf("\n\n");
}
///B mat
int B[2][3]={3,2,6,4,7,8};
printf("Matrix B :\n");
for(row=0;row<2;row++)
{
for(col=0;col<3;col++)
{
printf("\t%d ",A[row][col]);
}
printf("\n");
}
}
main()
{
int row,col;
int A[2][2]={3,4,2,6};
printf("Matrix A :\n");
for(row=0;row<2;row++)
{
for(col=0;col<2;col++)
{
printf("\tA[%d][%d]=%d ",row,col,A[row][col]);
}
printf("\n\n");
}
///B mat
int B[2][3]={3,2,6,4,7,8};
printf("Matrix B :\n");
for(row=0;row<2;row++)
{
for(col=0;col<3;col++)
{
printf("\t%d ",A[row][col]);
}
printf("\n");
}
}
Subscribe to:
Posts (Atom)