0% found this document useful (0 votes)
11 views33 pages

Jayesh More

The document contains a series of programming experiments conducted by a student named Anandrao More, focusing on various C programming concepts. Each experiment includes code snippets for calculating areas of geometric shapes, mathematical functions, simple calculators, conditional statements, loops, arrays, string operations, and recursion. The document serves as a practical guide for learning programming through hands-on coding exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views33 pages

Jayesh More

The document contains a series of programming experiments conducted by a student named Anandrao More, focusing on various C programming concepts. Each experiment includes code snippets for calculating areas of geometric shapes, mathematical functions, simple calculators, conditional statements, loops, arrays, string operations, and recursion. The document serves as a practical guide for learning programming through hands-on coding exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

EXPERIMENT NO: 1

Student Name:
anandrao more

Div: C
Roll No: 31 Batch:C2

Que 1: Write a program to find area of different geometric


shapes.
Program Code:
#include<stdio.h> int
main (){

//area of square int


a;
printf("Enter length of side of square:\n");
scanf("%d",&a);
printf("%d is the area of square.\n",a*a);

//area of rectangle int


l,w;
printf("Enter length and width of rectangle:\n");
scanf("%d%d",&l,&w);
printf("%d is the area of rectangle.\n",l*w);

//area of circle int


r;
printf("Enter radius of circle:\n"); scanf("%d",&r);
printf("%f is the area of circle.\n",3.1415926*r*r);

//area of triangle int


b,h;
printf("Enter base and height of triangle:\n");
scanf("%d%d",&b,&h);
printf("%.2f is the area of triangle.\n",0.5*b*h);

return 0;
}

Output:
EXPERIMENT NO: 2

Student Name:
anandrao more

Div: C
Roll No: 31 Batch:C2

Que 1: Write a program for mathematical function in C


language.
Program Code:
#include<stdio.h>
#include<math.h>
#include<stdlib.h> void
main()
{
int a; float
result;
printf("enter a number=");
scanf("%d",&a); //square root
result=sqrt(a);
printf("square root of %d=%f",a,result);

//square
result=pow(a,2);
printf("\nPower of %d=%f",a,result);

//sine
result=sin(a);
printf("\nsine of %d=%f",a,result);

//cosine result=cos(a);
printf("\ncosine of %d=%f",a,result);

//log
result=log(a);
printf("\nlog of %d=%f",a,result);

//exp
result=exp(a);
printf("\nexp of %d=%f",a,result);

//absolute
int b;
printf("\nenter a number for absolute value=");
scanf("%d",&b); result=abs(b);
printf("absolute of %d=%f",b,result);

//round decimal point float c;


printf("\nenter a number=");
scanf("%f",&c); result=round(c);
printf("\nround of %f=%f",c,result);
//ceil
result=ceil(c);
printf("\nceil of %f=%f",c,result);

//floor
result=floor(c);
printf("\nfloor of %f=%f",c,result);
getc;
}

Output:
EXPERIMENT NO: 3

Student Name:
anandrao more

Div: C
Roll No: 31 Batch:C2

Que 1: Write a program to make a simple calculator using


arithmetic operators.
Program Code:
#include <stdio.h>

int main()
{ int a, b;
float c;
printf("Enter two integers to add: ");
scanf("%d%d",&a,&b); printf("Addition:
%d\n", a + b);
printf("Enter two integers to subtract: ");
scanf("%d%d",&a,&b); printf("Subtraction:
%d\n", a - b);

printf("Enter two integers to multiply: ");


scanf("%d%d",&a,&b); printf("Multiplication:
%d\n", a*b);

printf("Enter two integers to divide: "); scanf("%d


%f",&a,&c);
printf("Division: %.2f\n", a / c);// Integer division

printf("Enter two integers to find modulus: ");


scanf("%d%d",&a,&b); printf("Modulus: %d\
n", a % b); return 0;
}

Output:
Que 2: Write a program on relational operators.
Program Code:
#include <stdio.h>
int main() { int a = 10, b = 3;
printf("a == b: %d\n", a == b);
printf("a != b: %d\n", a != b);
printf("a > b: %d\n", a > b);
printf("a < b: %d\n", a < b);
return 0;
}

Output:

Que 3: Write a program on logical operator.


Program Code:
#include <stdio.h>

int main() {
int a = 1, b = 0; // 1 is true, 0 is false
printf("a && b: %d\n", a && b);
printf("a || b: %d\n", a || b);
printf("!a: %d\n", !a); return 0;
}
Output:
4: Write a program to voting eligibility criteria using
conditional operator.
Program Code:

#include <stdio.h>

int main()
{ int
age;
printf("Enter your age:");
scanf("%d",&age);

(age>=18)?printf("You are eligible for voting"):printf("You are not eligible for


voting");

return 0;

Output:

EXPERIMENT NO: 4
Que

Student Name:
anandrao more

Div: C
Roll No: 31 Batch:C2

Que 1: Write a program to show the numbers are equal using


if statement.
Program Code:
#include<stdio.h> int
main ()
{
int n1=10,n2=10;
if("n1==n2")
{
printf("Number1 equals to Number2\n");
}
return 0;
}

Output:
2: Write a program to show the numbers are equal or
not using if else statement.
Program Code:
#include<stdio.h> int
main()
{
int num1=10,num2=20;
if(num1==num2)
{
printf("Number1 equals to Number2");
}
else
{
printf("Number1 not equal to Number2");
}
return 0;
}

Output:
Que

3: Write a program to compare two numbers using


else if ladder.
Program Code:
#include<stdio.h> int
main()
{
int num1=10,num2=20;
if(num1==num2)
{
printf("Number1 equals to Number2");
}
else if (num1>num2)
{
printf("Number1 is greater than Number2");
}
else
{
printf("Number1 is smaller than Number2");
}
return 0;
}

Output:
4: Write a program for student grade using the nested if
else .
Program Code:
#include<stdio.h> int
main()
{
int score ;
printf("Enter your score:");
scanf("%d",&score); printf("You
got "); if(score>=90)
{
printf("Grade A");
}
else
{
if(score>=80)
{
if(score>=70)
{
printf("Grade C");
}
else
{
printf("Grade B");

}
}
Que

else
{

if(score>=60)
{
printf("Grade D");
}
else
{
printf("Grade F");
}
}
}
return 0;

Output:
5: Write a program to make a simple calculator using
switch statement.
Program Code:
#include<stdio.h> int
main()
{
int num1, num2;
float result; char
ch;

printf ("Enter first number = ");


scanf ("%d", &num1); printf
("Enter second number = "); scanf
("%d", &num2);

// printf("enter two number:");


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

printf ("Choose operator to perform operations = ");


scanf (" %c", &ch);

result = 0;
switch (ch)
{
case '+':
result = num1 + num2;
Que

break;
case '-':
result = num1 - num2;
break; case '*':
result = num1 * num2;
break; case '/':
if(num2 !=0){ result =
(float)num1 / num2;
}else{
printf("\n Error: Division by zero");
return 1;
}
break; default: printf ("\n
Invalid operation"); return 1;
}
printf ("\n Result: %d %c %d = %.2f", num1, ch, num2, result);
return 0;

Output:
EXPE
RIME
NT
NO:
5

Student Name:
anandrao more

Div: C
Roll No: 31 Batch:C2

Que 1: Write a program to print star using nested for loop.


Program Code:
#include<stdio.h> int
main (){
int i,j,k;
for(i=0;i<5;i++)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=0;k<i+1;k++)
{
printf("* ");
}
printf("\n");
}
return 0;
}

Output:
Que 2: Write a program for finding the even and odd
numbers using while loop.
Program Code:
#include<stdio.h> int
main()
{
int i = 0, n, even = 0, odd = 0;

// Input the range limit printf("\


nEnter a number: "); scanf("%d", &n);

// Loop to print even numbers


printf("\nEven numbers:");
while (i < n) { if (i % 2 == 0) {
printf(" %d", i); even++;
}
i++;
}
printf("\nTotal even numbers: %d", even);
// Reset `i` to 0 for odd number calculation
i = 0;

// Loop to print odd numbers


printf("\nOdd numbers:"); while
(i < n) { if (i % 2 == 1)
{ printf(" %d", i);
odd++;
}
i++;
}
printf("\nTotal odd numbers: %d", odd);

return 0;
}

Output:
Que 3: Write a program for check password is correct or not
using do while loop.
Program Code:
#include<stdio.h>
#include<string.h> int
main()
{
char correctPassword[] = "user123"; // Correctly define the password string
char enteredPassword[20];

do {
printf("\nEnter the password: ");
scanf("%s", enteredPassword);

if (strcmp(enteredPassword, correctPassword) == 0) {
printf("\nCorrect password!"); break;
} else {
printf("\nIncorrect password, try again.");
}
} while (1);

return 0;

}
Output:
EXPERIMENT NO: 6

Student Name:
anandrao more

Div: C
Roll No: 31 Batch:C2

Que 1: Write a program for printing the number using


onedimensional array.
Program Code:
#include <stdio.h> int
main() {
int i;
// Declare an array of size 5 int
numbers[5] = {10, 20, 30, 40, 50};

// Access and display elements


for ( i = 0; i < 5; i++) {
printf("numbers[%d]: %d\n", i, numbers[i]);
}
return 0;
}

Output:
EXPERIMENT NO: 7
Student Name:
anandrao more

Div: c
Roll No: 31 Batch:C2

Que 1: Write a program for printing the number in matrix format


using two-dimensional array.
Program Code:
#include <stdio.h> int
main()
{
int i=0,j=0;
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
//traversing 2d array
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
return 0;
}

Output:
EXPERIMENT NO: 8

Student Name:
anandrao more

Div: C
Roll No: 31 Batch:C2

Que 1: Write a program performing string operations.


Program Code:
#include<stdio.h>
#include<string.h>

int main()
{
char a[10],b[20];

printf("Enter first string:");


gets(a);
printf("Enter second string:");
gets(b);

printf("\n string in uppercase: %s",strupr(a));


printf("\n string in lowercase : %s",strlwr(b));
printf("\n string in concat : %s",strcat(a,b));
printf("\n string in reverse : %s",strrev(a));

return 0;
}

Output:
EXPERIMENT NO: 9

Student Name:
anandrao more

Div: C
Roll No: 31 Batch:C2

Que 1: Write a program to find given number is even or odd using


function.
Program Code:
#include<stdio.h>

void evenodd(int i)
{
if(i%2==0)
{
printf("Number %d is even.",i);

}
else
{
printf("Number %d is odd. ",i);
}
}

int main()
{
int num;
printf("enter number:"); scanf("%d",&num);
evenodd(num); return 0;
}

Output:
EXPERIMENT NO: 10

Student Name:
anandrao more

Div:C
Roll No: 31 Batch:C2

Que 1: write a program to calculate factorial number using


recursion function.
Program Code:
#include<stdio.h>
int fact(int); int
main()
{
int n,result;

printf("enter any number:"); scanf("%d",&n);

result=fact(n);
printf("factorial is %d",result);

return 0;
}

int fact(int num)


{
int f;
if(num==1)
{
return 1;
}
else
{
f=num*fact(num-1);
return f;
}
}

Output:

You might also like