CPF Practicals
CPF Practicals
.
Advantages of Scratch
1. Easy-to-understand interface:
2. Promotes logical thinking:
3. There is no need for a compiler:
4. Free programming language:
5. Encourages Problem-Solving:
Disadvantages of Scratch
#include<stdio.h>
#include<conio.h>
Void main() {
int area,r;
Clrscr();
Printf(“ENTER THE RADIUS OF THE CIRCLE”);
Scnaf(“%d”,&r);
Area=3.14*r*r;
Printf(“AREA OF THE CIRCLE %d”,area);
Getch();
}
PRACTICAL:2.2
#include<stdio.h>
#include<conio.h>
Void main() {
Int a,b;
Clrscr();
Printf(“ENTER THE VALUE OF A”);
Scnaf(“%d”,&a);
Printf(“ENTER THE VALUE OF B”);
Scnaf(“%d”,&b);
Printf(“AND OUTPUT OF A AND B %d \n”(a<b)&&(a>b));
Printf(“OR OUTPUT OF A AND B %d \n”(a<b)||(a>b));
Printf(“NOT OUTPUT OF A AND B %d \n”!(a<b));
Getch();
}
PRACTICAL:3.1
#include<stdio.h>
#include<conio.h>
Void main() {
Int a,b;
Clrscr();
Printf(“ENTER THE VALUE OF a”);
Scnaf(“%d”,&a);
Printf(“ENTER THE VALUE OF b”);
Scnaf(“%d”,&b);
If(a>b)
{
Printf(“a is greater than b \n”);
}
Else
{
Printf(“b is greater than a \n”);
}
Printf (***** A AND B ARE COMPARED *****”);
}
Getch();
}
PRACTICAL:3.2
#include<stdio.h>
#include<conio.h>
Void main() {
Int a,b.c;
Clrscr();
Printf(“ENTER THE VALUE OF a”);
Scnaf(“%d”,&a);
Printf(“ENTER THE VALUE OF b”);
Scnaf(“%d”,&b);
Printf(“ENTER THE VALUE OF c”);
Scnaf(“%d”,&c);
If(a>b && b<c)
{
Printf(“a is greater than b&C \n”);
}
Else if (b<a&&b<c)
{
Printf(“b is greater than a&C \n”);
}
Printf(“c is greater than a&b \n”);
}
Printf(“*****A,B AND C ARE COMPARED*****”);
}
Getch();
}
PRACTICAL:3.3
#include <stdio.h>
int main() {
int num1, num2;
float result;
char ch; //to store operator choice
result = 0;
switch (ch) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = (float) num1 / (float) num2;
break;
case '%':
result = num1 % num2;
break;
default:
printf("Invalid operation.\n");
}
#include<stdio.h>
#include<conio.h>
Void main() {
Int i,J,m,n;
Clrscr();
For(i=70; i>=65 ; i--)
{
For( m=n ; m>=65 ; m--)
{
Printf (“%c”, n);
}
Printf (“\n”);
}
For(i=65 ; i<=70 ; i++)
{
For( j=65 ; j<=I ; j++)
{
Printf (“%c”, j);
}
Printf (“\n”);
}
Getch();
}
PRACTICAL:5
#include<stdio.h>
#include<conio.h>
Void main() {
Int Marks[10];
Clrscr();
For(i=0;i<=10;i++)
{
Printf(“ENTER MARKS”);
Scanf(“%d”,&Marks[i])
}
Getch();
}
PRACTICAL:6
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[3][3];
printf("Enter elements of 3X3 matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The elements of 3X3 matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
printf(“\n”);
}
PRACTICAL:7
#include <stdio.h>
#include <string.h>
int main() {
int x=10;
int*y=&a;
printf(“%d”,x);
printf(“%u”,&x);
printf(“%u”,y);
printf(“%d”,*y);
printf(“%u”,&y);
return 0;
}
PRACTICAL:8
1 STRLEN():
#include <stdio.h>
#include <string.h>
int main() {
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
printf("%d", strlen(alphabet));
return 0;
}
2.STRCAT():
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "Hello ";
char str2[] = "World!";
strcat(str1, str2);
printf("%s", str1);
return 0;
}
2.STRCMP():
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Hello";
char str2[] = "Hello";
char str3[] = "Hi";
printf("%d\n", strcmp(str1, str2));
printf("%d\n", strcmp(str1, str3));
return 0;
}
4.STRREV():
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello World";
printf("Reversed String: %s", strrev(str));
return 0;
}