Anda di halaman 1dari 72

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
void main( )
{
int a;
float b,c,e,f,u;
clrscr( );
printf("Select your shape:\n1.Rectangle\n2.Triangle");
scanf("%d",&a);
if (a==1)
{
printf("Enter the length and breadht of the rectangle");
scanf("%f%f",&b,&c);
}
else
{
if (a==2)
{
rintf("Enter the base and height of the triangle");
scanf("%f%f",&e,&f);
}
else
printf("Invalid input");
}
u=(e*f)/2;
switch(a)
{
case 1:
printf("The area of the rectangle is %f",b*c);
break;
case 2:
printf("The area of the triangle is %f",u);
break;
}
getch( );
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int c;
float b,a;
printf("Enter the first number");
scanf("%f",&a);
printf("Enter the second number");
scanf("%f",&b);
printf("Select the operation to be performed: \n1.Addition \n2.Subtraction
x
x
\n3.Multiplication \n4.Division");
scanf("%d",&c);
switch (c)
{
case 1:
printf("Their sum is %f",a+b);
break;
case 2:
printf("Their difference is %f",a-b) ;
break;
case 3:
printf("Their product is %f",a*b);
break;
case 4:
printf("Dividing them we get %f",a/b);
break;
default:
printf("Invalid input");
}
getch( );
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<math.h>
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
float a,b,c,d,e,u;
printf("Enter the coefficient of x^2\n");
scanf("%f",&a);
printf("Enter the coefficient of x\n");
scanf("%f",&b);
printf("Enter the constant term\n");
scanf("%f",&c);
if(((b*b)-4*a*c)>=0)
{
d=(-b+pow(((b*b)-4*a*c),0.5))/(2*a);
e=(-b-pow(((b*b)-4*a*c),0.5))/(2*a);
printf("\nRoots are %f & %f\n",d,e);
}
if(((b*b)-4*a*c)<0)
{
d=-b/(2*a);
u=pow((-(b*b)+4*a*c),0.5)/(2*a);
printf("\nRoots are %f+i%f & %f-i%f\n",d,u,d,u);
}
getch();
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
void main( )
{
int num, sum=0,r;
clrscr( );
printf("Enter the number");
scanf("%d",&num);
while(num)
{
r=num%10;
num=num/10;
sum=sum+r;
}
printf("Sum of the digits of the number entered is %d",sum);
getch();
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr();
int i=1,f=1,num;
printf("\nEnter the number whose Factorial is to be determined");
scanf("%d",&num);
for(i=1;i<=num;i++)
f*=i;
printf("\n\nfactorial of number is %d",f);
getch();
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int a,b,c;
printf("\n\nEnter three numbers whose greatest is to be determined\n\n");
scanf("%d%d%d",&a,&b,&c);
if((a>=b)&&(a>=c))
printf("\n\nGreatest Number is %d",a);
if((b>=a)&&(b>=c))
printf("\n\nGreatest Number is %d",b);
if((c>=a)&&(c>=b))
printf("\n\nGreatest Number is %d",c);
getch();
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
#include <conio.h>
void main( )
{
int number ,a , b=1;
printf("Enter the number to multiply the digit of number\n");
scanf( "%d", &number );
while(number > 0 )
{
a = number % 10;
b=b*a;
number = number / 10 ;
}
printf("Multiply of digits = %d", b );
getch( );
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
void predigit(char num1, char num2);
void postdigit(char c, int n);
char romanval[1000];
int i = 0;
int main( )
{
int j;
long number;
printf("Enter the number: ");
scanf("%d", &number);
if (number <= 0)
{
printf("Invalid number");
return 0;
}
while (number != 0)
{
if (number >= 1000)
{
postdigit('M', number / 1000);
number = number - (number / 1000) * 1000;
}
else if (number >= 500)
{
if (number < (500 + 4 * 100))
{
postdigit('D', number / 500);
number = number - (number / 500) * 500;
}

Question 11- (d) To count the number of characters in a string

else
{
git('C','M');
number = number - (1000-100);
}
}
else if (number >= 100)
{
if (number < (100 + 3 * 100))
{
postdigit('C', number / 100);
number = number - (number / 100) * 100;
}
else
{
predigit('L', 'D');
number = number - (500 - 100);
}
}
else if (number >= 50 )
{
if (number < (50 + 4 * 10))
{
postdigit('L', number / 50);
number = number - (number / 50) * 50;
}
else
{
digit('X','C');
number = number - (100-10);
}
}

predi

pre

Question 11- (d) To count the number of characters in a string

else if (number >= 10)


{
if (number < (10 + 3 * 10))
{
postdigit('X', number / 10);
number = number - (number / 10) * 10;
}
else
{
digit('X','L');
number = number - (50 - 10);
}
}
else if (number >= 5)
{
if (number < (5 + 4 * 1))
{
postdigit('V', number / 5);
number = number - (number / 5) * 5;
}
else
{
predigit('I', 'X');
number = number - (10 - 1);
}
}
else if (number >= 1)
{
if (number < 4)
{
postdigit('I', number / 1);
number = number - (number / 1) * 1;
}

pre

Question 11- (d) To count the number of characters in a string

else
{
predigit('I', 'V');
number = number - (5 - 1);
}
}
}
printf("Roman number is: \n\n\n\n");
for(j = 0; j < i; j++)
printf("%c", romanval[j]);
return 0;
}
void predigit(char num1, char num2)
{
romanval[i++] = num1;
romanval[i++] = num2;
}
void postdigit(char c, int n)
{
int j;
for (j = 0; j < n; j++)
romanval[i++] = c;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
int main( )
{
int a, b, x, y, t, gcd, lcm;
clrscr( );
printf("Enter two integers\n");
scanf("%d%d", &x, &y);
a = x;
b = y;
while(b!=0)
{
t = b;
b = a%b;
a = t;
}
gcd = a;
lcm = (x*y)/gcd;
printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
printf("Least common multiple of %d and %d = %d\n", x, y, lcm);
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string


#include<stdio.h>
#include<conio.h>
void main( )
{
cr( );
int ar[100],j,n,i,tmp;
printf(" Enter the size of the array \t");
scanf("%d",&n);
printf("Now enter the elements in the array \t");
for(i=0;i<n;i++)
{
]);
printf("\n Array is - ");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}
for(i=0;i<n;i++)
{
j=0;j<n-i;j++)
{
if(ar[j]<ar[j+1])
{
+1];
ar[j]=tmp;
}
}
}
printf("\n\n Array in the Descending order is - \n");
for(i=1;i<=n;i++)
{
printf("\t %d",ar[i]);
}
getch( );
}

clrs

scanf("%d",&ar[i
}

for(

tmp=ar[j
ar[j+1]=ar[j];

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
#include<conio.h>
int main( )
{
int n, sum = 0, c, array[100];
clrscr( );
printf("Enter the number of terms in the array");
scanf("%d", &n);
printf("Enter the numbers");
for (c = 0; c < n; c++)
{
scanf("%d", &array[c]);
sum = sum + array[c];
}
printf("Sum = %d\n",sum);
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
loat x,s=0;
int fact(int x);
int n,i,t=1;
clrscr( );
printf("\n\n\nEnter the value of x(in degrees) & n :
scanf("%f %d\n\n\n",&x,&n);
x=(3.14*x)/180;
for(i=1; i<=n; i++)
{
s=s+pow(-1,(i+1))*(pow(x,t))/((float)fact(t));
printf("x^%d/%d!",t,t);
if(i%2==0)
printf("+");
else
printf("-");
t=t+2;
}
printf("\n\n\n\nSum of series = %.2f",s);
getch( );
}
int fact(int x)
{
int i,f=1;
for(i=1; i<=x; i++)
f=f*i;
return(f);
}

");

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
int main( )
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];
clrscr( );
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
scanf("%d", &first[c][d]);
printf("Enter the elements of second matrix\n");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
scanf("%d", &second[c][d]);
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
sum[c][d] = first[c][d] + second[c][d];
printf("Sum of entered matrices:-\n");
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
printf("%d\t", sum[c][d]);
printf("\n");
}
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
#include <stdlib.h>
struct complex
{
int real, img;
};
int main( )
{
int choice, temp1, temp2, temp3;
struct complex a, b, c;
while(1)
{
printf("Press 1 to add two complex numbers.\n");
printf("Press 2 to subtract two complex numbers.\n");
printf("Press 3 to multiply two complex numbers.\n");
printf("Press 4 to divide two complex numbers.\n");
printf("Press 5 to exit.\n");
printf("Enter your choice\n");
scanf("%d",&choice);
if( choice == 5)
exit(0);
if(choice >= 1 && choice <= 4)
{
printf("Enter a and b where a + ib is the first complex number.");
printf("\na = ");
scanf("%d", &a.real);
printf("b = ");
scanf("%d", &a.img);
printf("Enter c and d where c + id is the second complex number.");
printf("\nc = ");
scanf("%d", &b.real);
printf("d = ");
scanf("%d", &b.img);
}

Question 11- (d) To count the number of characters in a string

if ( choice == 1 )
{
c.real = a.real + b.real;
c.img = a.img + b.img;
if ( c.img >= 0 )
printf("Sum of two complex numbers = %d + %di",c.real,c.img);
else
printf("Sum of two complex numbers = %d %di",c.real,c.img);
}
else if ( choice == 2 )
{
c.real = a.real - b.real;
c.img = a.img - b.img;
if ( c.img >= 0 )
printf("Difference of two complex numbers = %d + %di",c.real,c.img);
else
printf("Difference of two complex numbers = %d %di",c.real,c.img);
}
else if ( choice == 3 )
{
c.real = a.real*b.real - a.img*b.img;
c.img = a.img*b.real + a.real*b.img;
if ( c.img >= 0 )
printf("Multiplication of two complex numbers = %d + %di",c.real,c.img);
else
printf("Multiplication of two complex numbers = %d %di",c.real,c.img);
}
else if ( choice == 4 )
{
if ( b.real == 0 && b.img == 0 )
printf("Division by 0 + 0i is not allowed.");
else
{
temp1 = a.real*b.real + a.img*b.img;

Question 11- (d) To count the number of characters in a string

temp2 = a.img*b.real - a.real*b.img;


temp3 = b.real*b.real + b.img*b.img;
if ( temp1%temp3 == 0 && temp2%temp3 == 0 )
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d
+
%di",temp1/temp3,temp2/temp3);
else
printf("Division of two complex numbers = %d %di",temp1/temp3,temp2/temp3);
}
else if ( temp1%temp3 == 0 && temp2%temp3 != 0 )
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d + %d/
%di",temp1/temp3,temp2,temp3);
else
printf("Division of two complex numbers = %d %d/
%di",temp1/temp3,temp2,temp3);
}
else if ( temp1%temp3 != 0 && temp2%temp3 == 0 )
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d/%d +
%di",temp1,temp3,temp2/temp3);
else
printf("Division of two complex numbers = %d %d/
%di",temp1,temp3,temp2/temp3);
}
else
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d/%d + %d/
%di",temp1,temp3,temp2,temp3);

Question 11- (d) To count the number of characters in a string

else
printf("Division of two complex numbers = %d/%d %d/
%di",temp1,temp3,temp2,temp3);
}
}
}
else
printf("Invalid choice.");
printf("\nPress any key to enter choice again...\n");
}
}

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
int main( )
{
int a[3][3],i,j;
clrscr( );
long determinant;
printf("Enter the 9 elements of matrix: ");
for(i=0;i<3;i++)
{
for(j
=0;j<3;j++)
{
printf("\nEnter the element a%d%d\t:",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("\nThe matrix is\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
}
determinant = a[0][0]*((a[1][1]*a[2][2]) - (a[2][1]*a[1][2])) -a[0][1]*(a[1][0]*a[2]
[2] - a[2][0]*a[1][2]) + a[0][2]*(a[1][0]*a[2][1] - a[2][0]*a[1][1]);
printf("\nDeterminant of 3X3 matrix: %ld",determinant);
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
#include<conio.h>
int fibo(int);
int main( )
{
int num;
int result;
clrscr( );
printf("Enter the nth number in fibonacci series: ");
scanf("%d", &num);
if (num < 0)
{
printf("Fibonacci of negative number is not possible.\n");
}
else
{
result = fibo(num);
printf("The %d number in fibonacci series is %d\n", num, result);
}
return 0;
}
int fibo(int num)
{
if (num == 0)
{
return 0;
}
else if (num == 1)
{
return 1;
}

Question 11- (d) To count the number of characters in a string

else
{
urn(fibo(num - 1) + fibo(num - 2));
}
}

ret

Question 11- (d) To count the number of characters in a string


#include<stdio.h>
#include<conio.h>
int main( )
{
clrs
cr( );
int a[3][3],i,j;
float determinant=0;
printf("Enter the 9 elements of matrix:\n");
for(i=0;i<3;i++)
{
for(j=0;j<
3;j++)
{
printf("Enter the element a%d%d\t:",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("\nThe matrix is\n");
for(i=0;i<3;i++)
{
printf("
\n");
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
}
for(i=0;i<3;i++)
determinant = determinant + (a[0][i]*(a[1][(i+1)%3]*a[2][(i+2)%3] -a[1][(i+2)%3]*a[2]
[(i+1)%3]));
printf("\nInverse
of matrix is: \n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;
j++)
printf("%.2f\t",((a[(i+1)%3]
[(j+1)%3] * a[(i+2)%3][(j+2)%3]) - (a[(i+1)%3][(j+2)%3]*a[(i+2)%3][(j+1)%3]))/
determinant);
printf("\n");
}
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
#include<conio.h>
void towers(int,char,char,char);
void towers(int n,char frompeg,char topeg,char auxpeg)
/* If only 1 disk, make the move and return */
{
if(n==1)
{
intf("\nMove disk 1 from peg %c to peg %c",frompeg,topeg);
return;
}
/* Move top n-1 disks from A to B, using C as auxiliary */
towers(n-1,frompeg,auxpeg,topeg);
/* Move remaining disks from A to C */
printf("\nMove disk %d from peg %c to peg %c",n,frompeg,topeg);
/* Move n-1 disks from B to C using A as auxiliary */
towers(n-1,auxpeg,topeg,frompeg);
}
main( )
{
int n;
clrscr( );
printf("Enter the number of disks : ");
scanf("%d",&n);
printf("The Tower of Hanoi involves the moves :\n\n");
towers(n,'A','C','B');
return 0;
}

pr

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
int main( )
{
int x,y;
for(x=1;x<=10;x++)
{
=10;y++)
{
%d\n",x,y,x*y);
printf("\n\n");
}
getch( );
}

for(y=1;y<
printf("%d*%d=
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main(void)
{
int a[10][10],b[10][10],c[10][10],n=0,m=0,i=0,j=0,p=0,q=0,k=0;
clrscr( );
int *pt,*pt1,*pt2;
printf("Enter the number of rows and columns for 1st matrix : ");
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
;j<m;j++)
{
printf("Enter the element a%d%d :",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("Enter the number of rows and columns for 2nd matrix : ");
scanf("%d %d",&p,&q);
for(i=0;i<p;i++)
{
(j=0;j<q;j++)
{
printf("Enter the element a%d%d :",i+1,j+1);
scanf("%d",&b[i][j]);
}
}
if(m!=p)
{
intf("Multiplication cannot be done\n");
exit (0);
}

for(j=0

for

pr

Question 11- (d) To count the number of characters in a string

pt=&a[0][0];
pt1=&b[0][0];
pt2=&c[0][0];
for(i=0;i<n;i++)
{
for(k=0
;k<q;k++)
{
*(pt2+
(i*10+k))=0;
for(j=0;j<m;j++)
{
*(pt2+(i*10+k))+=*(pt+
(i*10+j))**(pt1+(j*10+k));
}
}
}
printf("The product of the matrices entered is:\n");
for(i=0;i<n;i++)
{
for(j
=0;j<q;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int i,j,n,a[10][10],b[10][10],c[10][10];
printf("Enter the order of 1st matrix ");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++)
{
=0;j<n;j++)
{
printf("Enter the element a%d%d :",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("\n");
printf("Enter the order of 2nd matrix ");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++)
{
=0;j<n;j++)
{
printf("Enter the element a%d%d :",i+1,j+1);
scanf("%d",&b[i][j]);
}
}
printf("\n");
printf("Subtracting the 2nd matrix from 1st matrix we get :\n");

for(j

for(j

Question 11- (d) To count the number of characters in a string

for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]-b[i][j];
printf("%d",c[i][j]);
printf("\t");
}
printf("\n");
}
getch( );
}

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
#include <conio.h>
int sum (int a);
int main( )
{
int num, result;
clrscr( );
printf("Enter the number: ");
scanf("%d", &num);
result = sum(num);
printf("Sum of digits in %d is %d\n", num, result);
return 0;
}
int sum (int num)
{
if (num != 0)
{
return (num % 10 + sum (num / 10));
}
else
{
return 0;
}
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
#include <conio.h>
#include <math.h>
#define MAXSIZE 10
void main( )
{
float x[MAXSIZE];
int i, n;
clrscr( );
float average, variance, std_deviation, sum = 0, sum1 = 0;
printf("Enter the value of N \n");
scanf("%d", &n);
printf("Enter %d real numbers \n", n);
for (i = 0; i < n; i++)
{
scanf("%f", &x[i]);
}
/* Compute the sum of all elements */
for (i = 0; i < n; i++)
{
sum = sum + x[i];
}
average = sum / (float)n;
/* Compute variance and standard deviation */
for (i = 0; i < n; i++)
{
sum1 = sum1 + pow((x[i] - average), 2);
}
variance = sum1 / (float)n;
std_deviation = sqrt(variance);
printf("Average of all elements = %.2f\n", average);

Question 11- (d) To count the number of characters in a string

printf("variance of all elements = %.2f\n", variance);


printf("Standard deviation = %.2f\n", std_deviation);
}

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<conio.h>
int main( )
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
clrscr( );
printf("Enter the number of rows and columns of first matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
{ printf("Enter the element a%d%d :",c+1,d+1);
scanf("%d", &first[c][d]);
}
printf("Enter the number of rows and columns of second matrix\n");
scanf("%d%d", &p, &q);
if ( n != p )
printf("Matrices with entered orders can't be multiplied with each other.\n");
else
{
printf("Enter the elements of second matrix\n");
for ( c = 0 ; c < p ; c++ )
for ( d = 0 ; d < q ; d++ )
{
printf("Enter the element a%d%d :",c+1,d+1);
scanf("%d", &second[c][d]);
}
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
{
for ( k = 0 ; k < p ; k++ )

Question 11- (d) To count the number of characters in a string

{
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
printf("Product of entered matrices:-\n");
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
printf("%d\t", multiply[c][d]);
printf("\n");
}
}
return 0;
}

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
int factorial(int n);
int main( )
{
int n;
printf("Enter an positive integer: ");
scanf("%d",&n);
printf("Factorial of %d = %ld", n, factorial(n));
return 0;
}
int factorial(int n)
{
if(n!=1)
return n*factorial(n-1);
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <math.h>
#include <stdio.h>
#include<conio.h>
// Function taking a function pointer as an argument
double compute_sum(double (*funcp)(double), double lo, double hi)
{
double sum = 0.0;
// Add values returned by the pointed-to function '*funcp'
for (int i = 0; i <= 100; i++)
{
double x, y;
// Use the function pointer 'funcp' to invoke the function
x = i/100.0 * (hi - lo) + lo;
y = (*funcp)(x);
sum += y;
}
return (sum/100.0);
}
int main(void)
{ clrscr();
double (*fp)(double);
// Function pointer
double sum;
// Use 'sin()' as the pointed-to function
fp = sin;
sum = compute_sum(fp, 0.0, 1.0);
printf("sum(sin): %f\n", sum);
// Use 'cos()' as the pointed-to function
fp = cos;
sum = compute_sum(fp, 0.0, 1.0);
printf("sum(cos): %f\n", sum);
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
void main( )
{
int count = 0, i, times = 0, t, h, e, space;
char string[100];
puts("Enter a string:");
gets(string);
/* Traverse the string to count the number of characters */
while (string[count] != '\0')
{
count++;
}
/* Finding the frequency of the word 'the' */
for (i = 0; i <= count - 3; i++)
{
t =(string[i] == 't' || string[i] == 'T');
h =(string[i + 1] == 'h' || string[i + 1] == 'H');
e =(string[i + 2] == 'e'|| string[i + 2] == 'E');
space =(string[i + 3] == ' ' || string[i + 3] == '\0');
if ((t && h && e && space) == 1)
times++;
}
printf("Frequency of the word 'the' is %d\n", times);
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
#include<conio.h>
int main (void)
{
int player = 0;
int winner = 0;
int choice = 0;
int row = 0;
int column = 0;
int line = 0;
clrscr();
char board [3][3] = {{'1','2','3'},{'4','5','6'},{'7','8','9'}};
for (int i = 0; i<9 && winner==0; i++)
{
prin
tf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
player = i%2 + 1;
do
{
printf("\nPlayer %d, please enter the number of the square ");
printf("where you want to place your %c: ",X);
player,
(player==1)?'X':'O');
scanf("%d", &choice);
row = --choice/3;
column = choice
%3;
}while(choice<0
|| choice>9 || board [row][column]>'9');
board[row][column] =
(player == 1) ? 'X' : 'O';
if((board[0][0]==board[1][1] &&
board[0][0]==board[2][2]) || (board[0][2]==board[1][1] && board[0]
[2]==board[2][0]))
winner = player;
else

Question 11- (d) To count the number of characters in a string

for(line = 0; line <=2; line++)


if((board[line]
[0]==board[line][1] && board[line][0]==board[line][2])||
(board[0]
[line]==board[1][line] && board[0][line]==board[2][line]))
winner = player;
}
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
if(winner==0)
printf("The game is a draw\n");
else
printf("Player %d has won\n", winner);
return 0
}

Question 11- (d) To count the number of characters in a string

#include <stdio.h>
#include<conio.h>
main (int argc, char *argv[])
{
int i;
clrscr();
printf("The value received by argc is %d.\n", argc);
printf("There are %d command-line arguments passed to main().\n",argc);
printf("The first command-line argument is: %s\n", argv[0]);
printf("The rest of the command-line arguments are:\n");
for (i=1; i<argc; i++)
printf("%s\n", argv[i]);
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
#include<process.h>
void main()
{
FILE *fp1,*fp2;
char a;
clrscr();
fp1=fopen("test.txt","r");
if(fp1==NULL)
{
puts("cannot open this file");
exit(1);
}
fp2=fopen("test1.txt","w");
if(fp2==NULL)
{
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do
{
getc(fp1);
fputc(a,fp2);
while(a!=EOF);
fcloseall();
getch();
}

a=f
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include <stdio.h>;
char lower_to_upper(char ch1)
{
char ch2;
if(ch1 >= 'a' && ch1 <= 'z')
{
ch2 = ('A' + ch1 - 'a');
return ch2;
}
else
{
ch2 = ch1;
return ch2;
}
}
int main()
{
char lower, upper;
printf("Enter a word : ");
scanf("%c", &lower);
upper = lower_to_upper(lower);
printf("/nThe wor in upper cse is: %c\n", upper);
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include<stdio.h>
main()
{
int status;
char file_name[25];
printf("Enter the directory to be deleted\n");
gets(file_name);
status = remove(file_name);
if( status == 0 )
printf("the file %s successfully deleted.\n",file_name);
else
{
printf("Unable to delete the file\n");
perror("Error");
}
return 0;
}

Question 11- (d) To count the number of characters in a string

Question 11- (d) To count the number of characters in a string

#include < stdio.h>


#include <conio.h>
#include <string.h>
void main()
{
clrscr();
char str[100];
int len;
printf( "Enter your string : ");
scanf("%s", &str);
len = strlen(str);
printf("\n The number of characters in this string is %d " , len );
getch();
}

Question 11- (d) To count the number of characters in a string

Anda mungkin juga menyukai