C Lab Programs
C Lab Programs
AIM:
ALGORITHM:
Step 1: start
Step 3: Define PI value as 3.14 using #define and consider float data type for radius
Step 7: stop
PROGRAM:
#include <stdio.h>
#define PI 3.14
int main() {
float radius;
printf("radius : ");
scanf("%f", &radius);
return 0;
OUTPUT:
radius:2.67
area=22.384747
circumference=16.767601
RESULT:
Thus the C program to find area and circumference of circle has been executed successfully and the
output has been verified.
AIM:
ALGORITHM:
Step 1: Start
Step 6: End
PROGRAM:
#include<stdio.h>
void main()
float a,b;
scanf("%f",&a);
scanf("%f",&b);
OUTPUT:
enter number1:2
RESULT:
Thus the basic calculator program has been executed successfully and output has been verified
AIM:
ALGORITHM:
Step 1. Start
Step 6. End
PROGRAM:
#include<stdio.h>
void main()
int a,b,c,d,temp;
scanf(" %d %d %d %d",&a,&b,&c,&d);
temp=a;
a=b;
b=c;
c=d;
d=temp;
OUTPUT:
After swapping
a=2
b=3
c=4
RESULT:
Thus the C program for exchanging the values of variables has been executed successfully and the
output has been verified.
Ex.No.1.d. Program to convert int to float and float to int
AIM:
ALGORITHM:
Step 1. Start
PROGRAM:
#include <stdio.h>
int main() {
double input;
scanf("%lf", &input);
return 0;
}
OUTPUT:
RESULT:
Thus the C Program for conversion of int to float and float has been executed successfully and the output
has been verified.
AIM:
ALGORITHM:
Step 1: start
Step 5: The printf statement is used to display the result of the expression.
Step 6: End
PROGRAM:
#include <stdio.h>
int main()
double result;
result = 3*2/3+5;
printf("Result: %.2lf\n",result );
return 0;
OUTPUT:
Result :7.00
RESULT:
Thus the C Program for solving the expression as 3*2/3+5 has been executed successfully and the
output has been verified.
AIM:
ALGORITHM:
Step 1:Start
Step 8: End
PROGRAM:
#include<stdio.h>
int main()
int n;
scanf("%d",&n);
switch(n)
case 1:
printf("January\n");
break;
case 2:
printf("February\n");
break;
case 3:
printf("March\n");
break;
case 4:
printf("April\n");
break;
case 5:
printf("May\n");
break;
case 6:
printf("June\n");
break;
case 7:
printf("July\n");
break;
case 8:
printf("August\n");
break;
case 9:
printf("September\n");
break;
case 10:
printf("October\n");
break;
case 11:
printf("November\n");
break;
case 12:
printf("December\n");
break;
default:
OUTPUT:
November
RESULT:
Thus the C Program to print month name based on user choice has been executed successfully and the
output has been verified.
AIM:
ALGORITHM:
Step1: Start
Step 3: Repeat the following steps until the user enters a negative number:
Step 5: End
PROGRAM:
#include<stdio.h>
int main()
int n,i,num,sum=0;
i=0;
scanf("%d",&n);
while(i<n)
scanf("%d",&num);
if(num>=0)
sum=sum+num;
i++;
printf("Sum = %d\n",sum);
OUTPUT:
Enter 5 Numbers : -1 2 3 4 -7
Sum = 9
RESULT:
Thus the C Program to find the sum of non negative numbers has been executed successfully and the
output has been verified.
AIM:
Step 1: Start
Step 2: Read a number from the user and store it in the variable 'originalNumber'
Step 9: End
PROGRAM:
#include <stdio.h>
int main() {
scanf("%d", &num);
originalnum = num;
while (num != 0)
num=num/10;
if(originalnum == reversednum)
{
printf("%d is a palindrome\n", originalnum);
else
return 0;
OUTPUT:
RESULT:
Thus the C Program to check whether a given number is palindrome or not has been executed
successfully and the output has been verified.
AIM:
ALGORITHM:
Step 1: Start
Step 2: Read the number of terms 'n' for the Fibonacci series from the user
Step 6: End
PROGRAM:
#include <stdio.h>
int main()
scanf("%d",&n);
next=first+second;
for(int i =3;next<=n;++i)
printf(" %d",next);
first=second;
second=next;
next=first+second;
OUTPUT:
RESULT:
Thus the C program to print Fibonacci series has been executed successfully and the output has been
verified.
AIM:
Step 1: Start
Step 2: Read the range of numbers (start and end) from the user
Step 3: For each number 'num' in the range from start to end (inclusive), repeat steps 4-8:
PROGRAM:
#include<stdio.h>
int main()
scanf("%d", &n);
oNumber = n;
while (oNumber != 0)
oNumber/= 10;
++a;
oNumber = n;
while (oNumber != 0)
{
R= oNumber % 10;
oNumber /= 10;
if (result== n)
else
return 0;
OUTPUT:
RESULT:
Thus the C program to find whether a given number is Armstrong or not has been executed
successfully and the output has been verified.
AIM:
ALGORITHM:
Step 1:Start
Step 5: Repeat the following steps from 'i' equals 1 to 'n': a. Multiply 'factorial' by 'i'
Step 7:End
PROGRAM:
#include<stdio.h>
int main()
int n,i,fact=1;
printf("Num: ");
scanf("%d",&n);
if(n<0)
printf("Invalid\n");
else{
for(i=1;i<=n;i++)
fact=fact*i;
printf("Factorial: %d\n",fact);
OUTPUT:
Num : 9
Factorial : 362880
RESULT:
Thus the C program to find factorial of a given number has been executed successfully and the output has been
verified.