0% found this document useful (0 votes)
2 views

Pic practical?

The document contains a series of C programming practicals that cover basic programming concepts such as reading input, performing calculations, and using control structures. Each practical includes code snippets for various tasks, including calculating areas and volumes, converting temperatures, and working with arrays and matrices. The examples demonstrate fundamental programming techniques and provide outputs for user interactions.

Uploaded by

thumbk123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Pic practical?

The document contains a series of C programming practicals that cover basic programming concepts such as reading input, performing calculations, and using control structures. Each practical includes code snippets for various tasks, including calculating areas and volumes, converting temperatures, and working with arrays and matrices. The examples demonstrate fundamental programming techniques and provide outputs for user interactions.

Uploaded by

thumbk123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

1 /*Practical No.

1*/

/* Implement C programs to read two numbers and display these two numbers*/

#include<stdio.h>

#include<conio.h>

void main()

int a,b;

clrscr();

printf("\n Please Enter the Two Numbers:");

scanf("%d%d", &a, &b);

printf("\n The First Number=%d",a);

printf("\n The Second Number=%d",b);

getch();

2 /*Practical No. 2.1*/

/* Implement C programs using Constants and Variables (Program to find area and volume of sphere) */

#include <stdio.h>

#include <conio.h>

void main()

float r,area,vol;

clrscr();

printf("Enter radius ofsphere: ");

scanf("%f",&r);

area=4*3.14*r*r;

vol=(4*3.14*r*r*r)/3;

printf("Area of sphere = %f",area);


printf("/nVolume of sphere = %f",vol);

getch();

3 /*Practical No. 2.2*/

/* Implement C programs using Constants and Variables (Program for Gross Salary) */

#include<stdio.h>

#include<conio.h>

void main()

int basic;

float da,hra,gs;

clrscr();

printf("\n\tEnter the BASIC SALARY:");

scanf("%d",&basic);

da=0.4*basic;//DA is 40% of Basic Salary

printf("Dearness Allonce=%f",da);

hra=0.2*basic;// HRA is 20% of Basic Salary

printf("House Rent Allounce=%f",hra);

gs=basic+da+hra;

printf("\n Gross Salary is==%f",gs);

getch();

4 /*Practical No. 2.3*/

/* Implement C programs using Constants and Variables (Program for Percentage Marks) */
#include<stdio.h>

#include<conio.h>

void main()

int m1,m2,m3,m4,m5;

float sum,per;

clrscr();

printf("\n Please Enter the Marks of five subjects:");

scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);

sum=m1+m2+m3+m4+m5;

printf("\n The Sum of Marks =%d",sum);

per=(sum/500)*100;

printf("\n The Percentage of Marks=%f",per);

getch();

5 /*Practical No. 3.1 */

Title: Program to convert temperature in Celsius to Fahrenheit */

#include <stdio.h>

#include <conio.h>

void main()

int C;

float F;

clrscr();

printf("Enter Temperature in Celsius: ");


scanf("%d",&C);

F=(1.8*C)+32 /*Celsius to Fahrenheit*/

printf("Temperature in Fahrenheit= %f",F);

getch();

6 /*Practical No. 3.2 */

Title: Program to convert temperature in Fahrenheit degree to Centigrade degree*/

#include <stdio.h>

#include <conio.h>

void main()

int F;

float C;

clrscr();

printf("Enter Temperature in Fahrenheit: ");

scanf("%d",&F);

C=(F-32)/1.8; /*Fahrenheit to Centigrade*/

printf("Temperature in Centigrade= %f",C);

getch();

/*Output:

Enter Temperature in Fahrenheit: 90

Temperature in Centigrade= 32.222221

Enter Temperature in Fahrenheit: 120

Temperature in Centigrade= 48.888889

*/
7 /*Practical No. 3.3 */

Title: Program to find area and perimeter of rectangle */

#include <stdio.h>

#include <conio.h>

void main()

float l,b,area,perimeter;

clrscr();

printf("Enter length of Rectangle: ");

scanf("%f",&l);

printf("Enter breadth of Rectangle: ");

scanf("%f",&b);

area=l*b; /*Calculate Area*/

perimeter=2*(l+b); /*Calculate Perimeter*/

printf("Area= %f",area);

printf("\nPerimeter= %f",perimeter);

getch();

/*Output:

Enter length of Rectangle: 12

Enter breadth of Rectangle: 10

Area= 120.000000

Perimeter= 44.000000
*/

8 /*Practical No. 4

Title: Program to demonstrate Implicit and Explicit data type conversion */

#include <stdio.h>

#include <conio.h>

void main()

int no1,no2;

float div;

char ch;

clrscr();

printf("Implicit Data Type Conversion:");

printf("\nEnter any character: ");

scanf("%c",&ch);

printf("Character= %c Character= %d",ch,ch);

printf("\n\nExplicit Data Type Conversion:");

printf("\nEnter Two integers: ");

scanf("%d %d",&no1,&no2);

div=no1 / (float) no2; /*Explicit Data type conversion*/

printf("Division= %f",div);

getch();

/*Output:

Implicit Data Type Conversion:

Enter any character: e

Character= e Character= 101

Explicit Data Type Conversion:

Enetr Two integers: 12 5


Division= 2.400000

*/

9 /* Practical No-5

Title :- Implement a C program for formatted Input Output Statement.*/

#include<stdio.h>

#include<conio.h>

void main()

int roll;

float p;

clrscr();

/*printf("Enter the Roll No:-");

scanf("%d", &roll);

printf("Enter the Percentage:");

scanf("%f", &p);

//printf("Enter the First Name :-");

//scanf("%s",&fn); */

printf("\n*******************************");

printf("\n_______________________________");

printf("\n|Roll No | Name | Class | Percentage |");


printf("\n_______________________________");

printf("\n| 1 | Rahul | FYCM | 67 |" );

printf("\n| 2 | Sachin | SYCM | 98 |" );

printf("\n| 3 | Saurav | SYCM | 98 |" );

printf("\n| 4 | Sachin | SYCM | 98 |" );

printf("\n| 5 | Sachin | SYCM | 98 |" );

printf("\n| 6 | Sachin | SYCM | 98 |" );

printf("\n*******************************");

getchar();

10 /* Practical No.6.1

Title:-Program to check numbers are equal or not */

#include <stdio.h> // Include the standard input/output header file.

void main()

int n1,n2; // Declare two integer variables 'n1' and 'n2'.

printf("Input the values for Number1 and Number2 : "); // Prompt the user to input values for
Number1 and Number2.

scanf("%d %d", &n1, &n2); // Read and store the user's input in 'n1' and 'n2'.

if (n1 == n2) // Check if Number1 is equal to Number2.

printf("Number1 and Number2 are equal\n"); // Print a message if Number1 and Number2 are
equal.

else

printf("Number1 and Number2 are not equal\n"); // Print a message if Number1 and Number2 are
not equal.

getch();

/*Output */

Input the values for Number1 and Number2 : 15 15

Number1 and Number2 are equal


11 /* Practical No.6.2

Title:-Program to find largest of 2 numbers using conditional operators*/

#include<stdio.h>

#include<conio.h>

void main()

int no1, no2 ;

clrscr();

printf("Enter 2 intergers: ");

scanf("%d %d ",&no1, &no2);

if(no1 > no2)

{ Printf(“ Largest number is %d”,no1); }

Else

{ Printf(“Largest Number is %d”, no2);

getch();

/*Output:

Enter 2 integers: 12 56

Largest number is 56

12 /* Practical No.7.1

Title: Program to check the number is ODD or EVEN */

#include <stdio.h>

int main()

int num;

printf("Enter an integer: ");


scanf("%d", &num);

// true if num is perfectly divisible by 2

if(num % 2 == 0)

printf("%d is even.", num);

else

printf("%d is odd.", num);

return 0;

/*Output */

Enter an integer: -7

-7 is odd.

13 /* Practical No.7.2

Title: Program to find greatest of 3 numbers*/

#include<stdio.h>void main()

{ int a,b,c; int big; printf("Enter any there numbers:"); scanf("%d%d%d",&a,&b,&c); if(a>b && a>c)
big = a; else if(b>c) big = b; else big = c;

printf("Largest number is: %d",big); return 0;}Sample output:Enter any there numbers: 13 25 6Largest
number is: 25

14 /* Practical No.10

Title: - Program using if..else if ladder statement.

#include<stdio.h>

main( )

int a, b, c, d, e, per;

printf(“Enter marks of four subjects : “);

scanf(“%d %d %d %d”, &a, &b, &c, &d);

if(a < 40 || b < 40 || c < 40 || d < 40)

printf(“\n You have failed in one subject”);

per = (a + b + c + d) / 4;

if(per>=75)
printf(“\n Distinction”);

else if(per<=74 && per> = 60)

printf(“\ n First class”);

else

if (per <=59 && per >=55)

printf(“\n Higher second class”);

else

if(per <=54 && per >=40)

printf(“Second class);

else

printf(“\n Fail”);

15 /*Practical No.11

Title: Program to print English Calendar months as per given number (eg: If input is 4 then print “April”)
using Switch statement

#include<stdio.h>

#include<conio.h>

void main()

int no;

clrscr();

printf("Enter month number: ");

scanf("%d", &no);

switch(no)

case 1: printf("JANUARY");

break;

case 2: printf("FEBRUARY");
break;

case 3: printf("MARCH");

break;

case 4: printf("APRIL");

break;

case 5: printf("MAY");

break;

case 6: printf("JUNE");

break;

case 7: printf("JULY");

break;

case 8: printf("AUGUST");

break;

case 9: printf("SEPTEMBER");

break;

case 10: printf("OCTOBER");

break;

case 11: printf("NOVEMBER");

break;

case 12: printf("DECEMBER");

break;

default: printf("Incorrect month Number...!");

getch();

/*Output:

Enter month number: 3

Reason: MARCH

Enter month number: 11


Reason: NOVEMBER

Enter month number: 14

Incorrect month Number...!

*/

16 /* Practical No.12

Title:-Program to to print day of week by taking bunber 1 to 7*/

#include<stdio.h>

#include<conio.h>

void main()

{ int no;

clrscr();

printf("Enter day number: ");

scanf("%d",&no);

switch(no)

{ case 1: printf("Day: Monday");

break;

case 2: printf("Day: Tuesday");

break;

case 3: printf("Day: Wednesday");

break;

case 4: printf("Day: Thursday");

break;

case 5: printf("Day: Friday");

break;

case 6: printf("Day: Saturday");

break;

case 7: printf("Day: Sunday");

break;

default: printf("Incorrect Day Number...!");


}

/* Output:

Enter day number: 3

Day: Wednesday

Enter day number: 9

Incorrect Day Number...! */

17 /*Practical No.13.1 do….while loop

Title: Program to find sum of digits */

#include <stdio.h>

#include <conio.h>

void main()

int no,digit,sum;

clrscr();

printf("Enter a number: ");

scanf("%d",&no);

sum=0;

while(no!=0)

digit=no%10; /*Extract last digit*/

sum=sum+digit; /*Add digit*/

no=no/10; /*Remove last digit-3*/

printf("Sum of digits=%d",sum);

getch();

/*Output:

Enter a number: 3784


Sum of digits=22

*/

18 /*Practical No.13.2 do…while

Title: Program to generate multiplication tables of 1 to 5 */

#include <stdio.h>

#include <conio.h>

void main()

int no,i,mult;

clrscr();

printf("Multiplication Tables: \n");

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

printf("Multiplication Table of %d\n",no);

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

mult=no*i; /*Generate Multiplication table number*/

printf("%2d ",mult);

printf("\n\n");

getch();

/*Output:

Multiplication Tables:

Multiplication Table of 1

1 2 3 4 5 6 7 8 9 10

Multiplication Table of 2
2 4 6 8 10 12 14 16 18 20

Multiplication Table of 3

3 6 9 12 15 18 21 24 27 30

Multiplication Table of 4

4 8 12 16 20 24 28 32 36 40

Multiplication Table of 5

5 10 15 20 25 30 35 40 45 50

*/

19 /*Practical No.15 for loop

Title: Program to generate pattern of pyramid of ‘*’ */

#include <stdio.h>

#include <conio.h>

void main()

{ int i, j, rows;

printf("Enter the number of rows: ");

scanf("%d", &rows);

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

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

printf("* ");

} printf("\n");

}getch(); }

/*Output:

**

***

****

*****
20 /*Practical No: 16.1

Program to input 5 numbers using array and display sum of it */

#include<stdio.h>

int main()

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

printf("Enter Five numbers :");

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

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

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

sum=sum+arr[i];

printf("\nThe sum of the given 5 numbers is : %d\n", sum);

return 0;

}
21 /*Practical No: 16.2

Program to print array in ascending order

#include <stdio.h>

void main()

int i, j, a, n, number[30];

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

scanf("%d", &n);

printf("Enter the numbers \n");

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

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

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

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

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

a = number[i];

number[i] = number[j];

number[j] = a;

printf("The numbers arranged in ascending order are given below \n");

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

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

}
22 /*Practical No: 17

Program to perform 3*3 matrix addition */

#include<stdio.h>

#include<conio.h>

void main()

int A[3][3],B[3][3],C[3][3], i, j;

clrscr();

/*Accept 9 elements of Matrix-A*/

printf("Enter 9-elements of matrix A:\n");

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

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

{ scanf("%d",&A[i][j]);

}}

printf("\nEnter 9-elements of matrix B:\n");

for(i=0;i<3;++i)
{ for(j=0;j<3;++j)

{ scanf("%d",&B[i][j]);

}}

/*Matrix Addition*/

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

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

C[i][j]=A[i][j]+B[i][j];

}}

/*Display resultant matrix*/

printf("\nResultant matrix:\n");

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

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

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

} printf("\n");

} getch();

/*Output:

Enter 9-elements of matrix A:

123456789

Enter 9-elements of matrix B:

14 31 21 51 61 71 13 3 4

Resultant matrix:

15 33 24

55 66 77

20 11 13 */
23 /*Practical No.18.1

Title: Program to Calculate Length of given string */

#include <stdio.h>

int main() {

char s[] = "Programming is fun";

int i;

for (i = 0; s[i] != '\0'; ++i);

printf("Length of the string: %d", i);

return 0;

/* Output: */

Length of the string: 18

24 /*Practical No.18.2 Title: Program to Calculate Reverse of given string */

#include <stdio.h>

#include <conio.h>

void main()

char str[60];

int leng, g;

// Printing the program name and what the program will do

printf("Program in C for reversing a given string n ");

printf("Please insert the string you want to reverse: ");

// fetch the input string from the user

scanf( "%s", str );

// This will find the length of your string with the help of strlen() function of the string.h header file
leng = strlen(mystrg);

// iterate through each and every character of the string for printing it backward or reverse direction

for(g = leng - 1; g >= 0; g--)

printf("Reverse of String : %c", str[g]);

return 0;

Output

Program in C for reversing a given string

Please insert the string you want to reverse: kkwp

Reverse of String: pwkk

25 /* Practical No.20

Accept and Display 10 Employee information using Structure */

#include<stdio.h>

#include<conio.h>

struct Employee

char name[30];

int id;

int salary;

};

int main()

//number of employees

int i;
//array to store structure values of all employees

struct Employee emp[5];

clrscr();

//Taking each employee detail as input

printf("Enter 5 Employee Details \n \n");

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

printf("Employee %d:- \n",i+1);

//Name

printf("Name: ");

scanf("%s",emp[i].name);

//ID

printf("Id: ");

scanf("%d",&emp[i].id);

//Salary

printf("Salary: ");

scanf("%d",&emp[i].salary);

printf("\n");

//Displaying Employee details

printf("-------------- All Employees Details ---------------\n");

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

printf("Name \t: ");

printf("%s \n",emp[i].name);

printf("Id \t: ");

printf("%d \n",emp[i].id);

printf("Salary \t: ");


printf("%d \n",emp[i].salary);

printf("\n");

getch();

return 0;

26 Practical No. 21

Title: Program to determine whether a string is a palindrome */

#include <stdio.h>

#include <conio.h>

#include <string.h>

void main()

int ch;

char str1[15], str2[15];

clrscr();

printf("Enter a string: ");

gets (str1);

strcpy(str2,str1); /* copy a original string*/

strrev(str2); /* Reverse a string */

ch = strcmp (str1, str2);

if ( ch == 0) /*check if palindrome */

printf("%s is a palindrome string,str1);

else

printf("%s is not a palindrome string,str2);

}
getch();

/* Output:-

Enter a string: ICICI

ICICI is a Palinidrome String

Enter a string: Pyramid

Pyramid is not a Palinidrome String

*/

27 /*Practical No.22.1

/*Program to find factorial of given number using Recursion*/

#include <stdio.h>

#include <conio.h>

/*Recursive Function definition to find factorial of number*/

long factorial(int no)

{ long fact;

if(no == 1)

{ return(1); }

else

fact=no*factorial(no-1);

return(fact);

}}

/*Main program*/
void main()

{ int num;

long f;

clrscr();

printf("Enter an integer: ");

scanf("%d",&num);

f=factorial(num);

printf("Factorial of %d = %ld ",num,f);

getch();

28 /*Practical No.22.2

Program to find GCD of two numbers using function*/

#include <stdio.h>

#include <conio.h>

/*Function definition to find GCD of two numbers*/

int gcd(int no1, int no2)

int R, N, D;

if(no1 > no2)

N=no1;

D=no2;

if(no2 > no1)

N=no2;

D=no1;

R=N % D;
while(R != 0)

N=D;

D=R;

R=N % D;

return (D);

/*Main program*/

void main()

int num1,num2,g;

clrscr();

printf("Enter two integers: ");

scanf("%d %d",&num1,&num2);

g=gcd(num1,num2);

printf("GCD of %d and %d = %d",num1,num2,g);

getch();

/*Output

Enter two integers: 75 25

GCD of 75 and 25 = 25

Enter two integers: 75 25

GCD of 75 and 25 = 25

Enter two integers: 50 8

GCD of 50 and 8 = 2 */

29/*Practical No.24 Title: Program to print values of variables and their addresses */

#include <stdio.h>

#include <conio.h>
void main()

int x,y;

int *px, *py; /*Pointer variables*/

clrscr();

printf("Enter value of x and x variables: ");

scanf("%d %d",&x,&y);

/*Print values and addresses of variable*/

printf("\nValues of variables: x=%d y=%d\n",x,y);

printf("Address of varibales: &x=%X &y=%X\n",&x,&y);

px=&x; /*Initialize pointer to x*/

py=&y; /*Initialize pointer to x*/

/*Print values and addresses of variable in terms of pointers*/

printf("\nValues and addresses of variable in terms of pointers:\n");

printf("\nValues of variables: *px=%d *py=%d\n",*px,*py);

printf("Address of varibales: px=%X py=%X\n",px,py);

getch();

return(0);

/*Output

Enter value of x and x variables: 43 56

Values of variables: x=43 y=56

Address of varibales: &x=FFF4 &y=FFF2

Values and addresses of variable in terms of pointers:

Values of variables: *px=43 *py=56

Address of varibales: px=FFF4 py=FFF2

*/

30/*Practical No.25
Title: Implement a ‘C’ Program to perform arithmetic operations using pointer. */

#include<stdio.h>

int main()

int number;

//pointer to int

int *p,*p1,*p2;

clrscr();

//stores the address of number variable

p=&number;

printf("Address of p variable is %u \n",p);

//adding 3 to pointer variable

p1=p+3;

printf("After adding 3 The address of p variable is %u \n",p1);

//subtracting 3 from pointer variable

p2=p-3;

printf("After subtracting 3 The Address of p variable is %u \n",p2);

getch();

Output

Address of p variable is

65524

After adding 3 The Address of p variable is After 65530

After subtracting 3 The Address of p variable is 65518


31

Title: Program to perform basic arithmetic operations*/

#include <stdio.h>

#include <conio.h>

void main()

int no1,no2,result;

clrscr();
printf("Enter two integers: ");

scanf("%d %d",&no1,&no2);

result = no1 + no2;

printf("Sum = %d”,result);

result = no1 - no2;

printf("\nDifference = %d”,result);

result = no1 * no2;

printf("\nProduct = %d”,result);

result = no1 / no2;

printf("\nDivision = %d”,result);

getch();

32

Title: Program to check the number is ODD or EVEN */

#include <stdio.h>

int main()

int num;

printf("Enter an integer: ");

scanf("%d", &num);

// true if num is perfectly divisible by 2

if(num % 2 == 0)

printf("%d is even.", num);

else

printf("%d is odd.", num);

return 0;
}

/*Output */

Enter an integer: -7

-7 is odd.

33

/* Using Logical Operator

Title: Program to check whether a triangle is Equilateral, Isosceles or Scalene */

#include <stdio.h>

#include <conio.h>

int main()

int side1, side2, side3;

clrscr();

/* Accept 3 sides of a triangle */

printf("Enter 3 sides of triangle: ");

scanf("%d %d %d", &side1, &side2, &side3);

/*If 3 sides are equal*/

if(side1==side2 && side2==side3)

printf("Equilateral triangle.");

/* If any two sides are equal */

else if(side1==side2 || side1==side3 || side2==side3)

printf("Isosceles triangle.");

else
{

/* If none sides are equal */

printf("Scalene triangle.");

getch();

return 0;

/*Output:

Enter 3 sides of triangle: 12 24 17

Scalene triangle.

Enter 3 sides of triangle: 33 33 60

Isosceles triangle.

Enter 3 sides of triangle: 52 52 52

Equilateral triangle.

*/

34

/* Logical Operator

Title:-Program to find if given character is vowel or not.*/

#include<stdio.h>

#include<conio.h>

#include <ctype.h>

void main()

char ch1,ch2;

clrscr();

printf("Enter a letter: ");

scanf("%c",&ch1);

ch2=tolower(ch1); /*convert letter to lower case*/


/* Check if character is a vowel */

if(ch2=='a' || ch2=='e' || ch2=='i' || ch2=='o' || ch2=='u')

printf("%c is a vowel",ch1);

else

printf("%c is not a vowel",ch1);

getch();

/*

Output:-

Enter a letter: K

K is not a vowel

Enter a letter: u

u is a vowel

35

/*

Title :- Program using simple if statement. */

#include<stdio.h>

main( )

int num;

printf(“Enter a number:”);

scanf(“%d”, &num);

if(num < = 10)

printf(“The number is less than 10”);


}

/*Output*/

Sample output of this program will be:

Enter a number: 7

The number is less than 10

Enter a number: 15

36

/*

Title :- Program using if..else statement.*/

#include<stdio.h>

main( )

{ int y;

printf(“Enter year : “); scanf(“%d”, &y);

if(y > 2000)

{ printf(“\n Number is greater than 2000”);

if(y % 4 == 0)

{ printf(“\n This is leap year”);

else

printf(“\n This is not leap year”);

else

{printf(“\n Number is less than 2000);

if(y % 4 ==0)

printf(“\n This is leap year”);

}
else

printf(“\n This is not leap year”);

/* Output: */

Enter year: 1988

Number is less than 2000

This is leap year

37

Title: Program to print Grade of students by accepting percentage marks*/

#include<stdio.h>

#include <conio.h>

void main()

int score;

clrscr();

printf("Enter percentage marks( 0-100 ): ");

scanf("%d",&score);

switch( score / 10 )

case 10:

case 9:

printf("Grade: A+\n");

break;

case 8:

printf("Grade: A\n");

break;

case 7: printf("Grade: B+\n");

break;

case 6:
printf("Grade: B\n");

break;

case 5:

printf("Grade: C+\n");

break;

case 4:

printf("Grade: C\n");

break;

default:

printf("Grade: Fail\n");

break;

getch();

/*Output:

Enter percentage marks( 0-100 ): 67

Grade: B

Enter percentage marks( 0-100 ): 95

Grade: A+ */

38

/*for loop

Title: Program to print numbers 1 to 100 */

#include <stdio.h>

#include <conio.h>

void main()

int i;

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

printf(“%d\t”,i);
getch();

39

/*Program to add two distances in kilometer and meter using structure*/

#include <stdio.h>

#include <conio.h>

void main()

{ /*Define a structure Type*/

struct distance{

int km;

int m;

} d1,d2,total; /*structure variables */

int kilometer, meters ; /* Normal variables */

clrscr();

printf("Enter Distance-1 in km & m: ");

scanf("%d %d",&d1.km,&d1.m); /*Accept Distance-1*/

printf("\nEnter Distance-2 in km & m: ");

scanf("%d %d",&d2.km,&d2.m); /*Accept Distance-2*/

meters = d1.m + d2.m ; /*Add meters */

total.m = meters % 1000; /*Extract total meters from two distance*/

kilometer = meters / 1000; /*Extract kilometers from two distances*/

total.km=d1.km+d2.km + kilometer; /*find Total kilometers*/

printf("\nTotal Distance = %d km %d m",total.km,total.m);

getch();

/*Output

Enter Distance-1 in km & m: 2 800


Enter Distance-2 in km & m: 3 400

Total Distance=6 km 200 m

40

/* Title:-Program to demonstrate use of string functions*/

#include<stdio.h>

#include<conio.h>

#include <string.h>

void main()

char str1[25],str2[25],str3[50];

int len, ch;

clrscr();

printf("Enter String-1: ");

gets(str1);

len=strlen(str1); //find string length of string-1*/

printf("String length of string-1 = %d", len);

printf("\n\nEnter String-2: ");

gets(str2);

len=strlen(str2); /*find string length of string-2*/

printf("String length of string-2 = %d", len);

ch=strcmp(str1,str2); /*compare two strings*/

if(ch==0) /*check if two strings are same or different*/

printf("\n\nString-1 & String-2 are same...");

else

printf("\n\n String-1 & String-2 are different...");

printf("\n\nCopy string-1 to string-3....");

strcpy(str3,str1); /*copy string-1 to string-3*/

printf("\nString-1 : %s String-3 : %s",str1,str3);


printf("\n\nConcatenate string-1 & string-2.....");

strcat(str3,str2); /*concatenate two strings*/

printf("\nString-1: %s String-2: %s Concatenated string-3: %s", str1, str2,

str3);

printf("\n\nString-3: %s", str3);

strrev(str3); /*Revrse string-3*/

printf("\nReverse String-3: %s", str3);

getch();

/*Output:

Enter String-1: Nashik

String length of string-1 = 6

Enter String-2: road

String length of string-2 = 4

String-1 & String-2 are same...

Copy string-1 to string-3....

String-1 : Nashik String-3 : Nashik

Concatenate string-1 & string-2.....

String-1: Nashik String-2: road Concatenated string-3: Nashikroad

String-3: Nashikroad

Reverse String-3: daorkihsaN */

41

/* Title:-Program to demonstrate use of mathematical functions*/

#include<stdio.h>

#include<conio.h>

#include <math.h>

void main()
{

float no, result;

int num;

clrscr();

printf("Enter float number: ");

scanf("%f",&no);

result=sqrt(no); /*find square root of no */

printf("\nSquare Root of %.2f = %.2f",no,result);

result=pow(no,3); /*find cube of no */

printf("\n\nCube of %.2f = %.2f",no,result);

num=floor(no); /*Round to previous integer*/

printf("\n\nFloor value of %.2f = %d", no, num);

num=ceil(no); /*Round to next integer*/

printf("\n\nCeil value of %.2f = %d", no, num);

result=sin(no); /*find sine of angle no */

printf("\n\nSine of %.2f = %.2f",no,result);

getch();

/*Output:

Enter float number: 25.34

Square Root of 25.34 = 5.03

Cube of 25.34 = 16271.21

Floor value of 25.34 = 25

Ceil value of 25.34 = 26

Sine of 25.34 = 0.21

*/
42

/*Program to find factorial of given number using Recursion*/

#include <stdio.h>

#include <conio.h>

/*Recursive Function definition to find factorial of number*/

long factorial(int no)

{ long fact;

if(no == 1)

{ return(1); }

else

fact=no*factorial(no-1);

return(fact);

}}

/*Main program*/

void main()

{ int num;

long f;

clrscr();

printf("Enter an integer: ");

scanf("%d",&num);

f=factorial(num);

printf("Factorial of %d = %ld ",num,f);

getch();

/* Output

Enter an integer: 6

Factorial of 6 = 720

Enter an integer: 9
Factorial of 6 = 362880 */

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy