C Programming Practical: Lokanthalli, Bhaktapur
C Programming Practical: Lokanthalli, Bhaktapur
C Programming Practical
Flow chart
Start
Get integer a
Area=pi*r*r
Print area
End
// Write a C program to find area of circle.
//area of circle//
#include<stdio.h>
#include<conio.h>
int main(){
float r,PI,Area;
printf("Enter the radius :");
scanf("%f",&r);
PI=3.14;
Area= PI*r*r;
printf("Area of circle : %f",Area);
getch();
return 0;
}
Output result
Write a C program to find simple interest.
Algorithm
Step 1: Start
Step 2: Declare integer 'x', 'y' and 'z'
Step 3: Define value of 'x', 'y' and 'z' & float 'interest'
Step 4: Simple interest values if 'x', 'y', and 'z'
Step 5: Store the O/P value of step 4 to simple interest
Step 6: Print simple interest
Step 7: Stop
Flow chart
Start
Get integer x, y, z
End
//Write a C program to find simple interest.
return 0;
}
Output result
Check the difference between signed int and unsigned int using a
program
Algorithm
Step 1: Start
Step 2: Declare signed int 'a' and unsigned int 'b'
Step 3: Define the values of 'a' and 'b'
Step 4: Store O/P of step 3 to 'a' and 'b'
Step 5: Add the values of 'a' and 'b'
Step 6: Store O/P of step 5 to 'sum'
Step 7: Print 'sum'
Step 8: Stop
Flow chart
Start
Get a and b
Sum= a + b
Print sum
End
// Check the difference between signed int and unsigned int using a
program
//check the differenc between signed and unsigned int//
#include<stdio.h>
#include<conio.h>
int main()
{
int a;
printf("Enter the signed number :");
scanf("%d",&a);
unsigned int b;
printf("Enter the unsigned number :");
scanf("%u",&b);
printf("\nEnter singned number:%d",a);
printf("\nEnter unsigned number:%a\n",b);
int sum=a+b;
printf("sum = %d",sum);
getch();
return 0;
}
Output result
Implement integer input formatting in c
Algorithm
Step 1: Start
Step 2: Declare integer 'a'
Step 3: Define the value and use at least 3 spaces of 'a'
Step 4: Store O/P of step 3
Step 5: Print the integer
Step 6: End
Get integer a
Print remaining of a
End
Implement integer input formatting in c
// implement integer input formatting in c //
#include <stdio.h>
#include <conio.h>
main()
{
int a;
printf("Enter the integer :");
scanf("%5d",&a);
printf("Your value = %d",a);
getch();
Output result
Write a C program to swap two value.
Algorithm
Step 1: Start
Step 2: Declare three integer 'x', 'y' and 'a
Step 3: Define integer 'x' and 'y'
Step 4: Swapping the value of 'x' and 'y'
Step 5: Store O/P of step 4
Step 6: Print the swapped value
Step 7: Stop
Flow chart
Start
get x ,y, a
End
//Write a C program to swap two value.
//write a program to swap two values//
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter two number : \n");
scanf("%d%d",&a,&b);
printf("\nBefore swapping\nfirst number : %d \nsecond number : %d",a,b);
c=a;
a=b;
b=c;
printf("\n\nAfter swapping\nfirst number : %d\nsecond number : %d",a,b);
getch();
Output result
Implement the single character input and string input
Algorithm
Step 1: Start
Step 2: Declare single character input 'a' and string character 'b'
Step 3: Define string character 'b'
Step 4: Take input 'b'
Step 5: Store O/P of step 4
Step 6: Print the string
Step 7: Define single character 'a'
Step 8: Read input 'a'
Step 9: Store O/P of step 4 of 'a'
Step 10:Print the single character
Step 11:Stop
Flow chart
Start
End
//Implement the single character input and string input
//implement the single character input and string input//
#include<stdio.h>
#include<conio.h>
int main()
{
char a,b[10];
printf("Enter any single character : ");
scanf("%c",&a);
printf("Enter your name : ");
scanf("%s",&b);
printf("You entered any single character:%c\nyour Name: %s",a,b);
getch();
return 0;
}
Output restult
Write a C program to find largest number among three conditional
operator.
Algorithm
Step 1: Start
Step 2: Declare four integer 'a', 'b', 'c' and 'x'
Step 3: Define the value of 'a', 'b' and 'c'
Step 4: Provide expression for larger number among 'a', 'b' and 'c'
Step 5: Store O/P of step 4 of 'x'
Step 6: Print 'x'
Step 7: Stop
Flow chart
Start
int a, b, c
a>b
b>c
a>c Print c is greater d Print c is greater
Print a is greater
Print b is greater
End
//Write a C program to find largest number among three
conditional operator.
//gretest among three using conditional operator//
#include<stdio.h>
#include<conio.h>
int main(){
int a,b,c,x;
printf("Enter the first number : ");
scanf("%d",&a);
printf("Enter the second number : ");
scanf("%d",&b);
printf("Enter the third number : ");
scanf("%d",&c);
x=(a>b>c)?a:(b>c)?b:c;
printf("The gretest number is %d ",x);
getch();
return 0;
}
Output restult