Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

Lab Report

On
Lab Evaluation -03
Course Title:structured Programming Language

Submitted To:
Name: Md. Mohsin Kabir
Lecturer,
Department of CSE, BUBT

Submitted By:
Name:MST. SHARMIN AKTER SUCHI
Id: 21225103258
Intake:49,Section:06.
Department of CSE, BUBT

Date: 14-05-2022
1. Problem Statement:Hello World!
Source code:
#include <stdio.h>

int main()

printf("Hello World!\n");

return 0;

Input –Output:
Hello World!
2. Problem Statement:summation
Source code:
#include <stdio.h>

int main() {

int x = 11,y = 12;

printf("%d", x + y);

return 0;

}
Input –Output:
23
3. Problem Statement:Subtraction

Source code:

#include<stdio.h>

int main() {
int x = 10, y = 3;
printf("%d", x - y);
return 0;
}
Input –Output:
7
4. Problem Statement:Multiplication

Source code:
#include <stdio.h>

int main() {
int x = 8,y=3;
printf("%d", x * y);
return 0;
}
Input –Output:
24
5. Problem Statement:Division
Source code:
#include <stdio.h>

int main() {
int x = 14,y = 7;
printf("%d", x / y);
return 0;
}
Input –Output:
2
6. Problem Statement: Area of a triangle.

Source code:

#include <stdio.h>
#include <math.h>
int main()
{
float radius, area;

printf("Enter the radius of a circle\n");

scanf("%f", &radius);

area = 3.14159*radius*radius;

printf("Area of the circle = %.2f\n", area);

return 0;
}
Input –Output:
Enter the radius of a circle
3
Area of the circle = 28.27

7. Problem Statement: Circumference of circle.

Source code:
#include<stdio.h>
float PI = 3.1416;

int main(){
float radius, circumference;

printf("Enter the radius of Circle : ");


scanf("%f", &radius);

circumference = 2 * PI * radius;

printf("Circumference of Circle : %f", circumference);

return (0);
}
Input-Output:

Enter the radius of Circle : 3

Circumference of Circle : 18.849600

8. Problem Statement: Area of

Rectangle. Source code:

#include<stdio.h>

int main()

double length,breadth, area;

printf("Enter length and breadth of

rectangle:"); scanf("%lf

%lf",&length,&breadth);

area=length * breadth;

printf("\nArea of Rectangle:

%0.2lf",area); return 0;

Input-Output:
Enter length and breadth of rectangle:2 3

Area of Rectangle: 6.00

9. Problem Statement: Calculate volume of sphere.

Source Code:
#include<stdio.h>
int main()
{
double sphere,r;
printf("Enter Radius : ");
scanf("%lf",&r);
sphere = (4/3.0)*3.14*r*r*r;
printf("Volume of Sphere = %0.2lf",sphere);
return 0;
}
Input-Output:

Enter Radius : 4
Volume of Sphere = 267.95

10. Problem Statement: Find surface area of


sphere. Source Code:
#include <stdio.h>
#include <math.h>

int main()
{

double radius,area;
printf("Enter radius of the sphere : ");
scanf("%lf", &radius);
area = 4 * 3.1416 * radius * radius;
printf("Surface area of sphere is: %0.2lf", area);

return 0;
}
Input-Output:
Enter radius of the sphere : 6
Surface area of sphere is: 452.39

11. Problem Statement: Find area of square.

Source Code:
#include<stdio.h>

int main() {
int side, area;
printf("Enter the Length of Side : ");
scanf("%d", &side);
area = side * side;
printf("Area of Square : %d", area);
return (0);
}
Input-Output:
Enter the Length of Side : 7
Area of Square : 49
12. Problem Statement: Find area of right angle
triangle. Source Code:
#include <stdio.h>

int main()
{
double height, width;
double area;

printf("Enter height and width of the given


triangle: "); scanf("%lf%lf", &height, &width);
area = 0.5 * height * width;
printf("Area of right angled triangle is: %.3lf\n",
area); return 0;
}
Input-Output:
Enter height and width of the given triangle: 5 5
Area of right angled triangle is: 12.500

13. Problem Statement: Find area of equilateral


triangle. Source Code:
#include <stdio.h>
#include <math.h>

int main()
{
double side, area;
printf("Enter side of an equilateral triangle: ");
scanf("%lf", &side);
area = (sqrt(3) / 4) * (side * side);
printf("Area of equilateral triangle = %.2lf sq. units",
area); return 0;
}
Input-Output:
Enter side of an equilateral triangle: 34
Area of equilateral triangle = 500.56 sq. units
14. Problem Statement: Find perimeter of rectangle.
Source Code:
#include <stdio.h>

int main()
{
double length, width, perimeter;
printf("Enter length of the rectangle: ");
scanf("%lf", & length);
printf("Enter width of the rectangle: ");
scanf("%lf", &width);
perimeter = 2 * (length + width);
printf("Perimeter of rectangle = %0.2lf units ",
perimeter); return 0;
}
Input-Output:
Enter length of the rectangle: 4
Enter width of the rectangle: 5
Perimeter of rectangle = 18.00 units

15. Problem Statement: Find area of triangle.


Source Code:

#include <stdio.h>

int main()
{
double base, height, area;
printf("Enter base of the triangle: ");
scanf("%lf", &base);
printf("Enter height of the triangle: ");
scanf("%lf", &height);
area = (base * height) / 2;
printf("Area of the triangle = %.2lf sq. units", area);

return 0;
}
Input-Output:
Enter base of the triangle: 4
Enter height of the triangle: 3
Area of the triangle = 6.00 sq. units
16. Problem Statement: Find simple
interest. Source Code:
#include <stdio.h>

int main()
{
double principle, time, rate, SI;
printf("Enter principle (amount): ");
scanf("%lf", principle);
printf("Enter time: ");
scanf("%lf", &time);
printf("Enter rate: ");
scanf("%lf", & rate);
SI = (principle * time * rate) / 100;
printf("Simple Interest = %0.2lf", SI);

return 0;
}
Input-Output:
Enter principle (amount): 1500
Enter time: 5
Enter rate: 7.8
Simple Interest = 585.00

17. Problem Statement: Find compound


interest. Source Code:
#include <stdio.h>
#include <math.h>

int main()
{
double principle, rate, time, CI;
printf("Enter principle (amount): ");
scanf("%lf", principle);
printf("Enter time: ");
scanf("%lf", &time);
printf("Enter rate: ");
scanf("%lf", & rate);
CI = principle* (pow((1 + rate / 100),
time)); printf("Compound Interest =
%0.2lf", CI);

return 0;
}
Input-Output:
Enter principle (amount): 2300
Enter time: 12
Enter rate: 10.5
Compound Interest = 7622.11

18. Problem Statement: Convert days into


years. Source Code:
#include <stdio.h>
int main()
{
int days, years, weeks;

printf("Enter days: ");


scanf("%d", &days);
years = (days / 365);
days = (days % 365) %7;
printf("YEARS: %d\n", years);
printf("DAYS: %d", days);
return 0;
}
Input-Output:
Enter days: 373
YEARS: 1
DAYS: 1

19. Problem Statement: Fahrenheit to Celsius


conversion.

Source Code:
#include<stdio.h>

void main()
{
double celsius,fahrenheit;
printf("Enter temperature in Fahrenheit:");
scanf("%lf",fahrenheit);
celsius=(fahrenheit - 32)*5/9;
printf("Celsius = %.3lf",celsius);
}
Input-Output:
Enter temperature in Fahrenheit:205
Celsius = 96.111

20. Problem Statement:Interest Calculation

Source Code:

#include<stdio.h>

void main()

int p,r,t;

float si;

printf(" Simple Interest Calculation : ");

printf("\n\n Enter Principle Amount : ");


scanf("%d", &p);

printf("\n\n Enter Rate of Interest : ");

scanf("%d", &r);

printf("\n\n Enter Time : ");

scanf("%d", &t);

si = (p*r*t)/100;

printf("\n\nSimple Interest : %lf \n", si);

21 .Problem Statement: Write a program in C to display the first 10 natural


numbers. Source Code:
#include<stdio.h>
int main()
{
int i;
for(int i=1; i<=10; i++)
{
printf("%d ",i);
}
printf("\n");
return 0;
}

Input-Output:
1 2 3 4 5 6 7 8 9 10

22.Problem Statement: Write a program in C to display n terms of natural number


and their sum.
Source Code:
#include <stdio.h>
void main()
{
int i,n,sum=0;
printf("Input Value of terms : ");
scanf("%d",&n);
printf("\nThe first %d natural numbers are:\n",n);
for(i=1;i<=n;i++)
{
printf("%d ",i);
sum+=i;
}
printf("\nThe Sum of natural numbers upto %d terms : %d \n",n,sum);

}
Input-Output:
Input Value of terms : 8

The first 8 natural numbers are:


12345678
The Sum of natural numbers upto 8 terms : 36

23.Problem Statement: Write a program in C to read 10 numbers from


keyboard and find their sum and average.
Source Code:

#include <stdio.h>
void main()
{
int i,n,sum=0;
float avg;
printf("Input the 10 numbers : \n");
for (i=1;i<=10;i++)
{
printf("Number-%d :",i);

scanf("%d",&n);
sum +=n;
}
avg=sum/10.0;
printf("The sum of 10 no is : %d\nThe Average is : %f\n",sum,avg);

}
Input-Output:

Input the 10 numbers :


Number-1 :1
Number-2 :2
Number-3 :3
Number-4 :4
Number-5 :5
Number-6 :6
Number-7 :7
Number-8 :8
Number-9 :9
Number-10 :10
The sum of 10 no is : 55
The Average is : 5.500000
.
24.Problem Statement: Write a program in C to display the cube of the
number upto given an integer.
Source Code:

#include <stdio.h>
void main()
{
int i,ctr;
printf("Input number of terms : ");
scanf("%d", &ctr);
for(i=1;i<=ctr;i++)
{
printf("Number is : %d and cube of the %d is :%d \n",i,i, (i*i*i));
}
}
Input-Output:

Input number of terms : 4


Number is : 1 and cube of the 1 is :1
Number is : 2 and cube of the 2 is :8
Number is : 3 and cube of the 3 is :27
Number is : 4 and cube of the 4 is :64
.
25.Problem Statement: Write a program in C to display the
multiplication table of a given integer.
Source Code:

#include <stdio.h>
void main()
{
int j,n;
printf("Input the number (Table to be calculated) : ");
scanf("%d",&n);
printf("\n");
for(j=1;j<=10;j++)
{
printf("%d X %d = %d \n",n,j,n*j);
}
}
Input-Output:

Input the number (Table to be calculated) : 6

6X1=6
6 X 2 = 12
6 X 3 = 18
6 X 4 = 24
6 X 5 = 30
6 X 6 = 36
6 X 7 = 42
6 X 8 = 48
6 X 9 = 54
6 X 10 = 60
.
26.Problem Statement: Write a program in C to display the n terms of odd
natural numbers and their sum.
Source Code:

#include <stdio.h>
void main()
{
int i,n,sum=0;

printf("Input number of terms : ");


scanf("%d",&n);
printf("\nThe odd numbers are :");
for(i=1;i<=n;i++)
{
printf("%d ",2*i-1);
sum+=2*i-1;
}
printf("\nThe Sum of odd Natural Number upto %d terms :
%d \n",n,sum); }
Input-Output:

Input number of terms : 9

The odd numbers are :1 3 5 7 9 11 13 15 17


The Sum of odd Natural Number upto 9 terms : 81

27.Problem Statement: Write a program in C to display the n terms of


harmonic series and their sum.
1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n terms
Source Code:

#include <stdio.h>
void main()
{
int i,n;
float s=0.0;
printf("Input the number of terms : ");
scanf("%d",&n);
printf("\n\n");
for(i=1;i<=n;i++)
{
if(i<n)
{
printf("1/%d + ",i);
s+=1/(float)i;
}
if(i==n)
{
printf("1/%d ",i);
s+=1/(float)i;
}
}
printf("\nSum of Series upto %d terms : %f \n",n,s);
}
Input-Output:

Input the number of terms : 8

1/1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + 1/8


Sum of Series upto 8 terms : 2.717857

28.Problem Statement: Write a program in C to display the sum of the


series [9 + 99 + 999 + 9999 ...].
Source Code:

#include <stdio.h>

void main()
{ long int n,i,t=9;
int sum =0;
printf("Input the number or terms :");
scanf("%ld",&n);
for (i=1;i<=n;i++)
{ sum +=t;
printf("%ld ",t);
t=t*10+9;
}
printf("\nThe sum of the series = %d \n",sum);
}
Input-Output:

Input the number or terms :6


9 99 999 9999 99999 999999
The sum of the series = 1111104

29.Problem Statement: Write a program in C to display the n terms of


square natural number and their sum.
1 4 9 16 ... n Terms
Source Code:

#include <stdio.h>

void main()
{
int i,n,sum=0;
printf("Input the number of terms : ");
scanf("%d",&n);
printf("\nThe square natural upto %d terms are :",n);
for(i=1;i<=n;i++)
{
printf("%d ",i*i);
sum+=i*i;
}
printf("\nThe Sum of Square Natural Number upto %d terms =
%d \n",n,sum); }
Input-Output:

Input the number of terms : 4

The square natural upto 4 terms are :1 4 9 16


The Sum of Square Natural Number upto 4 terms = 30

30.Problem Statement: Write a program in C to display the first n


terms of Fibonacci series.
Fibonacci series 0 1 2 3 5 8 13 .....
Source Code:

#include <stdio.h>

void main()
{
int prv=0,pre=1,trm,i,n;
printf("Input number of terms to display : ");
scanf("%d",&n);
printf("Here is the Fibonacci series upto to %d
terms : \n",n); printf("% 5d % 5d", prv,pre);

for(i=3;i<=n;i++)
{
trm=prv+pre;
printf("% 5d",trm);
prv=pre;
pre=trm;
}
printf("\n");
}
Input-Output:

Input number of terms to display : 13


Here is the Fibonacci series upto to 13 terms :
0 1 1 2 3 5 8 13 21 34 55 89 144

31.Problem Statement: write a program to calculate the factorial of


a given number.
Source Code:
#include <stdio.h>
void main(){
int i,f=1,num;

printf("Input the number : ");


scanf("%d",&num);

for(i=1;i<=num;i++)
f=f*i;

printf("The Factorial of %d is: %d\n",num,f);


}

Input-Output:

Input the number : 5


The Factorial of 5 is: 120
.
32.Problem Statement: write a program in c to find the number and sum of all
integer between 100 and 200 which are divisiable by 9.
Source Code:
#include <stdio.h>

void main()
{
int i, sum=0;
printf("Numbers between 100 and 200, divisible by 9 : \n");
for(i=101;i<200;i++)
{
if(i%9==0)
{
printf("% 5d",i);
sum+=i;
}
}
printf("\n\nThe sum : %d \n",sum);
}
Input-Output:

Numbers between 100 and 200, divisible by 9 :


108 117 126 135 144 153 162 171 180 189 198

The sum : 1683

33.Problem Statement: write a program in c to find lcm of


any two numbers
Source Code:
#include <stdio.h>

void main()
{
int i, n1, n2, max, lcm=1;

printf("Input 1st number for LCM: ");


scanf("%d", &n1);
printf("Input 2nd number for LCM: ");
scanf("%d", &n2);

max = (n1>n2) ? n1 : n2;

for(i=max; ; i+=max)
{

if(i%n1==0 && i%n2==0)


{
lcm = i;
break;
}
}
printf("\nLCM of %d and %d = %d\n\n", n1, n2, lcm);

Input-Output:

Input 1st number for LCM: 22


Input 2nd number for LCM: 55

LCM of 22 and 55 = 110

35.Problem Statement: write a c program to calculate sum of


digits of a number.
Source Code:
#include<stdio.h>
int main()
{
int num,sum=0,r;
printf("Enter a Number: ");
scanf("%d",&num);
while(num)
{
r=num%10;
num=num/10;
sum=sum+r;
}
printf("Sum of Digits of Number: %d",sum);
return 0;
}
Input-Output:

Enter a Number: 245


Sum of Digits of Number: 11

36.
.#include<stdio.h>

void main()

char ch;

printf("C Program to Find Entered Character is a Vowel or

Consonant."); printf("\n\n Enter character : ");

scanf("%c", &ch);

if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch ==

'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' ||

ch == 'U' ) {

printf("\n\n %c is a Vowel!! ",ch);

else

printf("\n\n %c is a Consonant!! ",ch);

}
37.

#include<stdio.h>

void main()

int year;

printf("C Program to Find Entered Year is a leap year or

not."); printf("\n\n Enter Number : ");

scanf("%i", &year);

if ((year % 400 == 0) || ( ( year % 100 != 0) && (year % 4

== 0 ))) {

printf("\n\n %i is a leap year!",year);

else
{

printf("\n\n %i is not a leap year!!",year);

}
38..
#include<stdio.h>

void main()

int num;

printf("C Program Check Entered Number is Positive or

Negative"); printf("\n\n Enter a number : ");

scanf("%i", &num);

if(num > 0)

printf("\n\n Entered number %d is a positive number

",num); else if(num < 0)

printf("\n\n Entered number %d is a negative number

",num); else

printf("\n\n Entered number %d is neither positive nor negative

",num); }

39.
#include<stdio.h>

void main()

int i,sum=0;

printf("C Program to Display 1st 10 natural numbers and their

sum : "); printf("\n\n 1st 10 natural numbers : ");

for(i = 1 ; i <= 10 ; i++)

sum = sum + i;

printf("%d ",i);
}

printf("\n\n Sum of 1st 10 natural numbers : %d

",sum); }

40.
#include<stdio.h>

void main()

int i=0,j=0;

for(i = 0; i <=

10 ; i++) {

for(j = 0; j <= i;

j++) {

printf("* ");

printf("\n");

41.
#include<stdio.h>

void main()

int i=0,j=0,k=0;

for(i = 0; i <=

10 ; i++){ for(j =

10; j >= i; j--) {

printf(" ");

for(k=1; k<=1;

k++) {

printf("*");
}

printf("\n");

}
42.
#include<stdio.h>

void main()

int i=0,j=0,k=0;

for(i = 0; i <=

11 ; i++) {

for(j = 11; j >=

i; j--) {

printf(" ");

for(k=1; k<=i*(2-1);

k++) {

printf(" *");

printf("\n")

43.
#include<stdio.h>

void main()

int i=0,j=0,k=0,l;

for(i = 10; i >=1 ; --i)

{
for(j = 0; j < 10-i ;

++j) {

printf(" ");

for(k = i; k <= (2*i-1) ;

++k) {

printf("* ");

for(l =0; l < (i-1) ;

++l) {

printf("* ");

printf("\n");

44.
#include<stdio.h>

void main()

int i=0,j=0;

for(i=1;i<10;++i)

for(j=1;j<=i;

++j) {

printf("%d

",i); }

printf("\n");

}
}

45.
#include<stdio.h>

void main()

int i,j,k,m=1;

for(i=0;i<8;i++)

for(j=1;j<=8-i;j++) {
printf(" ")

for(k=0; k<=i;

k++) {

if (k==0 ||

i==0) { m=1;

else {

m=

m*(i-k+1)/k; }

printf("%4d",m

); }

printf("\n");

46.
#include<stdio.h>

void main()

int i,j,k,rows=5;
for (i = 1; i <=

rows; i++) {

for (j = 1; j <=

rows-i; j++)

printf(" ");

for (k = 1; k <=

2*i-1; k++)

printf("*");

printf("\n");

for (i = 1; i <= rows

- 1; i++) {

for (j = 1; j <= i; j++)


printf(" ");

for (k = 1 ; k <= 2*(rows-i)-1; k++)

printf("*")

printf("\n");

47.
#include<stdio.h>

void main()

int i,j;

int count = 1;

for (i = 1; i <= 5; i++)

for (j = 1; j <= i; j++) {

printf(" %d ",count);

count++;
}

printf("\n");

48.
#include<stdio.h>

void main()

int i,a=0,b=1,f;

printf("C program prints 1st 1-10 Fibonacci

series : "); for ( i = 0 ; i < 10; i++ )

if ( i <= 1 )

f = i;
else

f = a+b;

a = b;

b = f;

if(f > 10) {

break;

printf("%d ",f);

49.
#include<stdio.h>

void main()

{
int fibo(int);

int i,no;

printf("C program to print Fibonacci series between 1-10 using

recursion : "); for ( i = 0 ; i < 10 ; i++ )

if(fibo(i) > 10) {

break;

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

int fibo(int no)

if ( no == 0 ) {

return 0;
}

else if ( no == 1 ) {

return 1;

else {

return ( fibo(no - 1) + fibo(no

- 2) ); }

50.

#include<stdio.h>

void main()

int i;

for ( i = 1 ; i < 20 ; i++ )

{
i = i+1;

printf("%d ", i);

51.

#include<stdio.h>

void main()

int i;

for ( i = 0 ; i < 20 ; i++ )

i = i+1;

printf("%d ", i);

}
52.

#include<stdio.h>

void main()

int i,n,sum;

printf("\n C Program to print sum of series 1 + 3 + 5 + 7 + .... + n :

\n\n "); printf("Enter an odd number n : ");

scanf("%d",&n);

for ( i = 1 ; i <= n ; i=i+2 )

if((n-1)!=i)

printf(" %d +",i);

else

printf(" %d ",i);

sum = sum + i;
}

printf(" = %d",sum);

53.

#include<stdio.h>

void main()

int i,sum=0,arr[10];

printf("\nC Program to add 10 numbers using arrays :

\n\n"); for(i = 0; i<10; i++)

printf("Enter no. %d : \n",i+1);

scanf("%d",&arr[i]);

for(i = 0; i<10; i++)

{
sum = sum + arr[i];

printf("Sum : %d",sum);

54.

#include<stdio.h>

void main()

int i,max=0,arr[10];

printf("\n Enter 10 numbers :

\n\n"); for(i = 0; i<10; i++)

printf("Enter no. %d :

\n",i+1);
scanf("%d",&arr[i])

for(i = 0; i<10; i++)

if(arr[i]>=max)

max = arr[i];

printf("Max number :

%d",max); }

55.

#include<stdio.h>

void main()

int i,sum=0,arr[10];

float avg=0;

printf("\n Enter 10 numbers : \n\n");


for(i = 0; i<10; i++)

printf("Enter no. %d : \n",i+1);

scanf("%d",&arr[i]);

for(i = 0; i<10; i++)

sum = sum + arr[i];

printf("summation : %d\n",sum);

avg = sum/10.0;

printf("Average : %f",avg);
}

56.

#include<stdio.h>

void main()

int i;

printf("\n Print 1 to 10 in reverse

order : "); for(i=10 ; i >=1 ; i--)

printf(" %d ", i);

58..

#include<stdio.h>

void main()

char n;

printf("Enter a char/Alphabet in Upper

Case : "); scanf("%c",&n);

printf("\n Lower case value of %c is :

%c",n,n+32); }

59.

#include<stdio.h>

void main()

int arr[2][2];

int i,j;

printf("two diamentinal Matrix : ");

for(i=0; i<=1; i++)

{
for(j=0; j<=1; j++)

printf("\nEnter element at location %d,%d :

",i+1,j+1); scanf("%d",&arr[i][j]);

printf("\n\n Entered two diamentinal matrix :

\n\n"); for(i=0; i<=1; i++)

for(j=0; j<=1; j++)

printf("%d ",arr[i][j]);

printf("\n");

60.

#include<stdio.h>
void main()

int arr[3][3];

int i,j;

printf("three dimensional Matrix : ");

for(i=0;i<=2;i++) {

for(j=0;j<=2;j++) {

printf("\nEnter element at location %d,%d :

",i+1,j+1); scanf("%d",&arr[i][j]);

}
}

printf("\n three dimensional matrix :

\n\n"); for(i=0;i<=2;i++) {

for(j=0;j<=2;j++) {

printf("%d ",arr[i][j]);

printf("\n");

61.

#include<stdio.h>

void main()

int i = 1, j = 2;

for (i = 1; i <= 100; i++) {

j = 2;

while (j <= i - 1) {

if (i % j == 0) {

break;

j++;

if (i == j) {

printf("\n%d is a Prime

number.", i); }

return 0;

62.

#include<stdio.h>
void main()

int add(int, int);

int a, b, sum = 0;

printf("Enter no. A : ");

scanf("%d", &a);

printf("\nEnter no. B : ");

scanf("%d", &b);
printf("\nSum of %d + %d = %d ", a, b,

add(a, b)); return 0;

int add(int a, int b) {

return a + b;

63.

#include<stdio.h>

void main()

int sub(int, int);

int a, b;

printf("Enter no. A : ");

scanf("%d", &a);

printf("\nEnter no. B : ");

scanf("%d", &b);

printf("\nSum of %d - %d = %d ", a, b,

sub(a, b)); return 0;

int sub(int a, int b) {

return a - b;

}
64.

#include<stdio.h>

void main()

char *str, ch;

int i = 0;

printf("Enter a string : ");

while ((ch = getchar()) != '\n') {

str[i] = ch;
i++;

printf("Length of string

: %d ",i); return 0;

65.

#include<stdio.h>

void main()

char str1[100], str2[100];

int i = 0;

printf("Enter a string A : ");

scanf("%s", str1);

printf("Enter a string B : ");

scanf("%s", str2);

if (strcmp(str1, str2) == 0)

printf("\nBoth strings are

same"); }

else

{
printf("Both strings are NOT

same"); }

return 0;

66.

#include <stdio.h>

#include <stdlib.h>
int main()

char str[100];

int i=0;

int sp=0;

printf("Enter a string\n");

gets(str);

while(i<=str[i])

if(str[i]==' ')

sp++;

i++;

printf("Total white space :%d ",sp);

getch();

return 0;

67.

#include <stdio.h>

void main()

{
int i, j, a, n, x[30];

printf("Enter the value of N \n");

scanf("%d", &n);

printf("Enter the numbers \n");

for (i = 0; i < n; ++i)

scanf("%d", &x[i]);

for (i = 0; i < n; ++i)

for (j = i + 1; j < n; ++j)

if (x[i] > x[j])

a = x[i];

x[i] = x[j];

x[j] = a;

printf("The numbers rearranged in ascending order are

: \n"); for (i = 0; i < n; ++i)

printf("%d\n", x[i]);

68..

#include <stdio.h>
void main()

int x[50], y[50], z[100], m, n, i, j, k = 0;

printf("\n Enter size of first Array : ");

scanf("%d", &m);
printf("\n Enter sorted elements of first array :

\n"); for (i = 0; i < m; i++)

scanf("%d", &x[i]);

printf("\n Enter size of second array : ");

scanf("%d", &n);

printf("\n Enter sorted elements of second array :

\n"); for (i = 0; i < n; i++)

scanf("%d", &y[i]);

i = 0;

j = 0;

while (i < m && j < n)

if (x[i] < y[j])

z[k] = x[i];

i++;

else

z[k] = y[j];

j++;

}
k++;

if (i >= m)

{
while (j < n)

z[k] = y[j];

j++;

k++;

if (j >= n)

while (i < m)

z[k] = x[i];

i++;

k++;

printf("\n After merging:

\n"); for (i = 0; i < m + n;

i++) {

printf("\n%d",

z[i]); }

69.

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

void main()

{
char str[100];

int i=0, w=0;

printf("\n\nCount the total number of words in a string

:\n"); printf("Input the string : ");

fgets(str, sizeof str, stdin);

while(str[i]!='\0')

if(str[i]==' ' || str[i]=='\n' || str[i]=='\t')

w++;

i++;

printf("Total number of words in the string is :

%d\n", w); }

70.

#include <stdio.h>

#include <string.h>

void main()

char str[100];

int i, n, v=0, c=0;

printf("\n\nCount total number of vowel or

consonant :\n"); printf("Input the string : ");

fgets(str, sizeof str, stdin);

n = strlen(str);

for(i=0; i<n; i++)

{
if(str[i] =='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i]=='A' ||
str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U')
{

v++;

else if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))

c++;

printf("\nThe total number of vowel in the string is : %d\n", v);

printf("The total number of consonant in the string is : %d\n\n", c);

72.

#include<stdio.h>

int main()

int x=10,y;

int *p;

p=&x;

printf("%d\n",x);

*p=20;

printf("%d\n",x);

printf("%d\n",*p);

return 0;

73.

#include<stdio.h>

int main()

int x=10,y;

int *p;
p=&x;

y=*p;

*p=20;

printf("%d\n",x);

printf("%d\n",y);

printf("%d\n",*p);

return 0;

74.

#include<stdio.h>

int main()

int x=10,y;

int *p,*q;

p=&x;

q=&y;

y=*p;

*p=15;

*q=20;

printf("%d\n",x);

printf("%d\n",y);

printf("%d\n",*p);

printf("%d\n",*q);

return 0;

75.

#include<stdio.h>

int main()

int num1,num2,sum=0;
scanf("%d",&num1);

scanf("%d",&num2);

sum=num1+num2;

FILE*ptr;

ptr=fopen("My File.txt",sum);

fclose(ptr);

return 0;

You might also like