0% found this document useful (0 votes)
25 views13 pages

CPF Practicals

The document provides a series of practical programming exercises using Scratch and C programming. It covers learning Scratch step-by-step, advantages and disadvantages of Scratch, and various C programming tasks including using constants, variables, data types, operators, loops, arrays, pointers, and string functions. Each practical includes code snippets and aims to help users understand programming concepts through hands-on practice.

Uploaded by

skitsokli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views13 pages

CPF Practicals

The document provides a series of practical programming exercises using Scratch and C programming. It covers learning Scratch step-by-step, advantages and disadvantages of Scratch, and various C programming tasks including using constants, variables, data types, operators, loops, arrays, pointers, and string functions. Each practical includes code snippets and aims to help users understand programming concepts through hands-on practice.

Uploaded by

skitsokli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PRACTICAL:1

AIM: PRACTICE USING SCRATCH PROGRAMMING.


Scratch is a visual programming language and an online community where children can
program and share interactive media such as stories, games, and animations with people from
all over the world. Scratch is a simple, block-based programming language designed for beginners.
It uses colorful, drag-and-drop blocks to create games, animations, and stories, making coding visual
and fun.

How to learn Scratch step by step?


Here’s a step-by-step approach to learning Scratch:
1. Explore Scratch: Head to Scratch’s website and check out the interface. You can browse
existing projects for inspiration.
2. Get Coding: Start a new project and familiarize yourself with the layout. The coding blocks are
on the left, the stage is in the center, and the sprite list is on the right.
3. Build Your Characters: Add sprites (characters) from the library or create your own. You can
customize their appearance with costumes.
4. Code with Blocks: Scratch uses drag-and-drop coding blocks. Explore the different categories
(motion, looks, sound, etc.) and start with simple commands like moving your sprite.
5. Make it Interactive: Add events like “when green flag clicked” to trigger your code. Use loops
and conditional statements to make your program more interactive.
6. Experiment and Share: Don’t be afraid to experiment and try new things

.
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

1. Does not offer a progression to text-based programming languages:


2. Scratch programmers suffer from code smells, dead code, and duplication.
3. Lack of advanced coding features
4. No 3D projects
5. Others can take credit for your work
PRACTICAL:2.1

AIM: DESGIN AND TEST THE C PROGRAM USING CONSTANT,VARIBLE AND


DATATYPE.

#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

AIM: DESGIN AND TEST THE C PROGRAM USING OPERATOR.

#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

AIM: DESGIN AND TEST THE C PROGRAM USING IF-ELSE STATEMENT


LOOP.

#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

AIM: WRITE A C PROGRAM TO FIND GREATEST FROM THEE NUMBER


GIVEN BY USER TO EXPLAIN OF IF-ELSE IF LADDER STATEMENT .

#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

AIM: DESIGN THE CALUCULATOR USING SWITCH AND BREAK


STATEMENT.

#include <stdio.h>

int main() {
int num1, num2;
float result;
char ch; //to store operator choice

printf("Enter first number: ");


scanf("%d", & num1);
printf("Enter second number: ");
scanf("%d", & num2);
printf("Choose operation to perform (+,-,*,/,%): ");
scanf(" %c", & ch);

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");
}

printf("Result: %d %c %d = %f\n", num1, ch, num2, result);


return 0;
}
PRACTICAL:4

AIM: DESIGN THE PATTERN USING FOR LOOP

#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

AIM: WRITE A PROGRAM TO PRINT MARKS USING ONE DEMENSIONAL


ARRAY.

#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

AIM: WRITE A PROGRAM TO READ 3X3 MATRIX AND PRINT IT.

#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

AIM: DESIGN AND TEST C PROGRAM USING POINTER.

#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

AIM: DESIGN AND TEST C PROGRAM TO TEST VARIOUS INBUILT STRING


FUNCTION

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;
}

You might also like