0% found this document useful (0 votes)
4 views25 pages

C File

The document contains a series of programming exercises in C, including tasks such as computing the sum and average of three numbers, finding the largest number, implementing a simple calculator, checking for palindromes, and performing string operations. Each exercise includes a brief description followed by the corresponding C code. The document serves as a practical guide for learning basic programming concepts in C.

Uploaded by

advik3928
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)
4 views25 pages

C File

The document contains a series of programming exercises in C, including tasks such as computing the sum and average of three numbers, finding the largest number, implementing a simple calculator, checking for palindromes, and performing string operations. Each exercise includes a brief description followed by the corresponding C code. The document serves as a practical guide for learning basic programming concepts in C.

Uploaded by

advik3928
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/ 25

INTERNATIONAL INSTITUTE OF TECHNOLOGY & MANAGEMENT

MURTHAL

PROGRAMMING IN C

Submitted by: Submitted To:


Name- Ms
Roll. No. -
INDEX
S.NO LIST OF PROGRAM DATE SIGNATURE
1. Program to compute sum and average of
three numbers

2. Program to find the largest number out of


three numbers

3. Program to implement a simple calculator


using switch case

4. Program to check whether the given


number is palindrome or not

5. Program to print half pyramid of *

6. Program to traverse the elements of array


in reverse.

7. Program to calculate the length of a string

8. Program to concatenate two strings

Program to swap two integers using


9. pointers. You have to write a swap
function that will accept the address of two
integers and swap their values.

10. Program to implement linear search


Practical -1

Program to compute sum and average of three numbers.

#include<stdio.h>

#include<conio.h>

int main()

int a,b,c,sum;

float avg;

clrscr();

printf("enter three numbers:");

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

sum=a+b+c;

avg=(a+b+c)/3.0;

printf("sum=%d \n",sum);

printf("average=%.2f",avg);

getch();

return 0;

}
Output:-
Practical -2

Program to find the largest number out of three numbers.

#include<stdio.h>

int main()

int a,b,c;

clrscr();

printf("Enter the three numbers");

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

if(a>b && a>c)

printf("%d is larger",a);

else if(b>a && b>c)

printf("%d is larger",b);

else

printf("%d is larger",c);

getch();

return 0;

}
Output:-
Practical -3

Program to implement a simple calculator.

# include<stdio.h>

int main()

float a,b,result;

char op;

printf("enter <number1> <operator(+,-,*,/)> <number 2> \n");

scanf("%f %c %f",&a,&op,&b);

switch(op)

case '+':

result=a+b;

break;

case '-':

result=a-b;

break;

case '*':

result=a*b;

break;

case '/':
result=a/b;

break;

default:

break;

printf("% .2f %c %.2f=%.2f",a,op,b,result);

getch();

return 0;

}
Output:
Practical -4

Program to check whether the given number is palindrome or not.

# include<stdio.h>
# include<conio.h>
int main()
{
int n,rev=0,rem,temp;
clrscr();
printf("enter the number");
scanf("%d",&n);
temp=n;
while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(rev==temp)
{
printf("%d is palindrome",temp);
}
else
{
printf("%d is not palindrome",temp);
}
getch();
return 0;}

Output:
Practical -5

Print half pyramid of *

*
**
***
****
*****

# include<stdio.h>
int main()
{
int i,j,rows;
clrscr();
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();
return 0;
}
Output:
Practical -6

To traverse the elements of array in reverse.

#include<stdio.h>

#include<conio.h>

int main()

int a[10],n,i;

clrscr();

printf("enter the size of the aaray");

scanf("%d",&n);

printf("enter the array elements:");

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

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

printf("elements of array in reverse are:\n");

for(i=n-1;i>=0;--i)

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

getch();

return 0;

}
Output:
Practical -7

To calculate the length of a string

#include<stdio.h>

#include<conio.h>

int main()

char str[20];

int len;

clrscr();

printf("enter the string:");

gets(str);

len=strlen(str);

printf("The length ofthe string=%d",len);

getch();

return 0;

}
Output:
Practical -8

To concatenate two strings

#include<stdio.h>

#include<conio.h>

int main()

char str1[20];

char str2[20];

clrscr();

printf("enter the first string:");

gets(str1);

printf("enter the second string:");

gets(str2);

strcat(str1,str2);

printf("The string after concatenation=%s",str1);

getch();

return 0;

}
Output:
Practical -9

To swap two integers using pointers. You have to write a swap function that
will accept the address of two integers and swap their values.

#include<stdio.h>

#include<conio.h>

void swap (int *a,int *b);

int main()

int a,b;

clrscr();

printf("Enter the values of a and b");

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

printf("Before swapping=%d %d\n",a,b);

swap(&a,&b);

getch();

return 0;

void swap(int *a,int *b)

int temp;

temp=*a;

*a=*b;

*b=temp;
printf("After swapping=%d %d \n",*a,*b);

}
Output:
Practical -10

To implement linear search

#include<stdio.h>

int main()

int a[10],i,item,n,found=0;

clrscr();

printf("\n Enter number of elements of an array :");

scanf("%d",&n);

printf("\n Enter elements :");

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

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

printf("\n Enter item to search:");

scanf("%d",&item);

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

if(item==a[i])

found=1;

break;

if(found==1)

printf("\nitem found at location %d",i+1);


}

else

printf("item not found");

getch();

return 0;

}
Output:

You might also like