Exp1 2
Exp1 2
AIM: To write a C program to compute find the Area of the circle. ALGORITHM:
Step 1: Start the program.
Step 2: Declare the variables of respective data type. Area->integer
Radius->integer
Step 3: Get the radius.
Step 4: Calculate area=3.14*radius*radius Step 5:
Step 5: Print the area of the circle.
Step 6: Stop the Program.
OUTPUT:
Enter the Radius of the circle: 5
Radius=5
Area=78.500000
RESULT:
ALGORITHM:
Step 1: Start the program.
Step 2: Declare the variables of respective data type.
Step 3: Get the variable value with different Input functions.
Step 4: Print the value with different Output functions.
Step 5: Stop the program.
PROGRAM-1:
#include <stdio.h>
void main()
{
char ch;
printf(“\nEnter any character : “);
ch = getchar();
printf(“\nYou have entered : %c”,ch);
}
PROGRAM-2:
#include<stdio.h>
void main()
{
char ch;
printf("\nEnter any character : ");
ch = getch();
putchar(ch);
}
OUTPUT:
Enter any character : A
You have entered : A
PROGRAM-3:
#include <stdio.h>
void main()
{
char name[30];
printf("\nEnter your website: ");
gets(name);
puts(name);
}
OUTPUT:
Enter your website: www.saec.ac.in
www.saec.ac.in
PROGRAM-4:
#include <stdio.h>
int main()
{
int num;
printf("C Programming"); //displays the content inside
quotation scanf(“%d”,&num);
printf(%d”,num);
return 0;
}
OUTPUT:
C Programming
5
5
RESULT:
Thus, the program was compiled and executed successfully.
AIM: To write a C program to find the size of variables using sizeof function.
ALGORITHM:
Step 1: Start the program.
Step 2: Declare the variables of respective data type.
Step 3: Get the variable value with different Input
functions. Step 4: Print the variable size using sizeof
function.
Step 5: Stop the program.
C PROGRAM
#include<stdio.h>
int main()
{
int intType;
float floatType;
double doubleType;
char charType;
OUTPUT:
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte
RESULT:
ALGORITHM:
C PROGRAM
//Program to Print ASCII Value
#include <stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c", &c);
// %d displays the integer value of a
character // %c displays the actual character
printf("ASCII value of %c = %d", c,);
return 0;
}
OUTPUT:
Enter a character: G
ASCII value of G = 71
ALGORITHM:
OUTPUT:
Please enter any number
10
RESULT:
else
{ ncr=ncr*(n-r+1)/r;
printf("%d ",ncr);
}
} printf("\n");
}
return 0;
}
OUTPUT:
enter the row value: 5
1
11
121
1331
14641
ALGORITHM:-
Step 4: Read the choice to perform the operation using switch case.
Step 6: Stop.
PROGRAM:-
#include<stdio.h>
#include<conio.h>
void main()
int a,b,choice;
printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n");
scanf("%d",&choice);
switch(choice)
{
case 1 :
printf("Multiplication of %d and %d is :
%d",a,b,a*b); break;
case 4 :
break;
getch();
clrscr();
OUTPUT:
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter the values of a & b: 7
2
Enter your Choice : 1
Sum of 7 and 2 is : 9
RESULT:
Thus a C program to design a calculator to perform the operations
namely, addition, subtraction, multiplication, division of number is executed.
AIM:-
To write a program to find sum of digits
ALGORITHM:-
Step 1: Start the program.
Step 2: Declare the variables of respective data type.
n,r,sum->integer.
Step 3: Set sum=0
Step 4: If n>0 then
Step 5: Calculate r=n%10
Sum=sum+r
n=n/10
Step 6: Print sum
Step 7: Stop
PROGRAM:-
#include<stdio.h>
#include<conio.h>
void main()
{
int number, r, sum=0;
printf("Enter the number:\n");
scanf("%d",&number);
while(number>0)
{
r=number%10;
sum=sum+r;
number=number/10;
}
printf("\nSum of digits =%d",sum);
getch();
clrscr();
}
OUTPUT :-
Enter the number: 92
Sum of digits=11
RESULT:-
Thus the sum of digits using C program has been executed and verified successfully
AIM:
To write a c program to compute Fibonacci series.
Algorithm:
Step 1: Start
Step 2: Declare variable n, first, second, next, c;
Step 3: Initialize variable first = 0, second = 1
Step 4: Read n from user
Step 5: Print fib series
Step 6: Repeat until c < n : next = first + second; first = second; second = next;
Step 7: Stop
Program:
#include<stdio.h>
main()
{
int n, first = 0, second = 1, next, c;
printf("Enter the number of terms\n");
scanf("%d",&n);
printf("First %d terms of Fibonacci series are :-\n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d\n",next);
}
return 0;
}
Output:
Enter the number of terms
5
First 5 terms of Fibonacci series are :-
01123
Result:
Thus a c program to compute fibonacci series is executed successfully.
Aim:
Write a c program to find Prime Numbers between
1 to N.
Algorithm:
Step 1:START the program
step2:Declare the variablenum,i,count,n;
Step 3perform num%i==0 and track the count.
Step 4:exactly find the factors, if(count==0 &&
num!= Step 5 print num
Step 6:stop
program:
#include<stdio.h>
void main(){
int i, num, n, count;
printf("Enter the range: \n");
scanf("%d", &n);
printf("The prime numbers in between the range 1 to %d:",n);
for(num = 1;num<=n;num++){
count = 0;
for(i=2;i<=num/2;i++){
if(num%i==0){
count++;
break;
}
}
if(count==0 && num!= 1)
printf("%d ",num);
}
}
Output:
Enter max range: 30
2 3 5 7 11 13 17 19 23 29
Result:
Thus a C program to find Prime Numbers between 1 to N is executed Successfully.