OBJECTIVE
OBJECTIVE
OBJECTIVE
words.
PROGRAM:
#include<stdio.h>
void main()
{
int no;
switch(no)
{
case 1:
printf("You entered ONE");
break;
case 2:
printf("You entered TWO");
break;
case 3:
printf("You entered THREE");
break;
case 4:
printf("You entered FOUR");
break;
case 5:
printf("You entered FIVE");
break;
case 6:
printf("You entered SIX");
break;
case 7:
printf("You entered SEVEN");
break;
case 8:
printf("You entered EIGHT");
break;
case 9:
printf("You entered NINE");
break;
case 10:
printf("You entered TEN");
break;
default:
printf("Invalid number");
}
}
Output :
PRACTICAL -9
OBJECTIVE: To use while statement to reverse the digits of a given number.
PROGRAM:
#include<stdio.h>
#include<conio.h>
int main()
{
int n, reverse=0, rem;
printf("Enter a number: ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf("Reversed Number: %d",reverse);
getch();
return 0;
}
Output :
Enter a number : 123
Reversed number : 321
PRACTICAL -10
OBJECTIVE: To use for statement to print the multiplication table of a given number.
PROGRAM:
#include <stdio.h>
int main() {
int n;
printf("Enter an integer: ");
scanf("%d", &n);
Output :
Enter an integer:
2*1= 2
2*2= 4
2*3= 6
2*4= 8
2*5= 10
2*6= 12
2*7= 14
2*8= 16
2*9= 18
2*10= 20
PRACTICAL -11
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, i;
printf("Enter Number 1 :--> ");
scanf("%d", &a);
printf("\nEnter Number 2 :--> ");
scanf("%d", &b);
do
{
printf("\nEnter 1 for '+' ");
printf("\nEnter 2 for '-' ");
printf("\nEnter 3 for '*' ");
printf("\nEnter 4 for '/' \n");
printf("Enter 0 for Exit ");
printf("\nEnter your choice :--> ");
scanf("%d", &i);
switch(i)
{
case 0: break;
case 1:
printf("\na + b = %d\n", a + b);
break;
case 2:
printf("\na - b = %d\n", a - b);
break;
case 3:
printf("\na * b = %d\n", a * b);
break;
case 4:
printf("\na / b = %f\n", a / b);
break;
default:
printf("\nEnter valid option\n");
}
} while(i != 0);
}
Output :
Enter Number 1 :--> 8
a + b = 11
a-b=5
a * b = 24
a / b = 0.000000
PRACTICAL -12
OBJECTIVE: To read the marks of 10 students in an array and calculate their average
PROGRAM:
#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);
Output:
PRACTICAL -13
OBJECTIVE: To read two matrices and compute their sum using 2-Dimensional arrays.
PROGRAM:
#include <stdio.h>
int main() {
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
printf("Enter the number of rows (between 1 and 100): ");
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);
return 0;
}
Output :
10 8 6
PRACTICAL -14
PROGRAM:
#include <stdio.h>
#include <string.h>
int main()
{
char str[40]; // declare the size of character string
printf (" \n Enter a string to be reversed: ");
scanf ("%s", str);
Output
PROGRAM:
#include<stdio.h>
#include<strings.h>
#include<conio.h>
main()
{
int n;
gets (name);
puts("Enter verified user Age: ");
gets (age);
strlen(name);
printf("\nName Length is %d character.\n",n);
strcpy(temp, name);
puts(temp);
else
{
puts(name);
puts("This user is not verified.");
Output:
PRACTICAL -16
PROGRAM:
#include<stdio.h>
void swap(int *,int *);
int main()
{
int n1,n2;
printf("\n\n Function : swap two numbers using function :\
n");
printf("------------------------------------------------\n");
int tmp;
tmp = *p;
*p=*q;
*q=tmp;
}
Output: