C Programs STD 10 1
C Programs STD 10 1
C Programs STD 10 1
Chapter 10 & 11
/* Program - use of variable*/
#include<stdio.h>
int main()
{
int a=10;
float b=20.1;
char c='a';
printf("\n the value of a:=%d",a);
printf("\n the value of b:=%f",b);
printf("\n the value of c:=%c \n",c);
return 0;
}
/* Program - Average of 3 numbers*/
#include<stdio.h>
int main( )
{
float first,second,third,avg;
printf("\n Enter the value of first no.");
scanf("%f",&first);
printf("\n Enter the value of second no.");
scanf("%f",&second);
printf("\n Enter the value of third no.");
scanf("%f",&third);
avg=(first+second+third)/3;
printf("Average:=%f",avg);
return 0;
}
/* Program to calculate circumference of circle */
#include<stdio.h>
#define PI 3.14
int main()
{
float r,cf;
printf("\n Enter the value of radius.");
scanf("%f",&r);
cf=2*PI*r;
printf("Circumference of circle with radius %f:=%f",r,cf);
return 0;
}
1 RSCD
Std 10th C Programs :- Practical Notes
#include<stdio.h>
#define P printf
#define S scanf
#define PI 3.14
int main()
{
float r,sarea;
P("\n Enter the value of radius.");
S("%f",&r);
sarea= 4*PI*r*r;
P(" Surface area of circle with radius %f=%f \n",r,sarea);
return 0;
}
/* Program of swapping. */
#include<stdio.h>
int main()
{ int g1,g2,g3;
printf("\n c.");
scanf("%d%d",&g1,&g2);
printf("\nBefore swapping value of g1=%d",g1);
printf("\nBefore swapping value of g2=%d",g2);
g3=g1;
g1=g2;
g2=g3;
printf("\n After swapping value of g1=%d",g1);
printf("\n After swapping value of g2=%d\n",g2);
return 0;
}
/* Program of Pattern print (textbook ch- 10 Lab q.1)
#include<stdio.h>
#define P printf
int main()
{ P(“**************************\n”);
P(“*Name \t : \t\t\t*\n”);
P(“*School Name \t : \t\t*\n”);
P(“*Standard \t : \t\t*\n”);
P(“*Address \t : \t\t*\n”);
P(“* \t\t\t\t*\n”);
P(“**************************\n”);
return 0; }
2 RSCD
Std 10th C Programs :- Practical Notes
/* Program to calculate the square root of a given no. */
#include<stdio.h>
#include<math.h>
int main()
{
float num,ans;
printf("\n Enter the value of any number.");
scanf("%f",&num);
ans= sqrt(num);
printf(" The Square root of %f =%f \n",num,ans);
return 0;
}
for compilation: $ gcc sqrt.c -o sqrt -lm
for execution $./sqrt
#include<stdio.h>
int main()
{
int cost,qty;
float ans;
printf("\n Enter the cost and quantity-");
scanf("%d%dd",&cost,&qty);
ans=cost/(float)qty;
printf("Cost of one item after type casting is %f\n",ans);
return 0;
}
3 RSCD
Std 10th C Programs :- Practical Notes
/* Program to use of conditional operator ( ? :) */
#include<stdio.h>
int main()
{
int n1,n2,min;
printf("\n Enter two values-");
scanf("%d%d",&n1,&n2);
min=(n1<=n2)?(n1):(n2);
printf("\n The minimum value =%d\n",min);
return 0;
}
Chapter 12
/*Program to use getchar and putchar function */
#include<stdio.h>
int main()
{
char grade;
printf(“Enter your grade-“);
grade=getchar();
printf(“Your grade is “);
putchar(grade);
return 0;
}
/* Program to use of a gets and puts function */
#include<stdio.h>
int main()
{
char name[85];
printf("\n Enter your state name:");
gets(name);
printf("You state name is:");
puts(name);
return 0;
}
/*Program to use of %[characters] specification */
#include<stdio.h>
int main()
{
char n[25];
printf(“Enter your name containing only alphabets and spaces-“);
scanf(“%[a-z A-Z]”,n);
printf(“Your name is %s \n”,n);
return 0;
}
/*Program to use of %[^characters] specification*/
#include<stdio.h>
int main()
{
char data[100];
printf(“Enter your details- );
printf(“Enter * to exit-\n”);
scanf(“%[^*]”,data);
printf(“Your details stored in variable is \n%s\n”,data);
return 0; }
4 RSCD
Std 10th C Programs :- Practical Notes
Chapter 13
/* Program to calculate Bigger number between 2 numbers */
#include<stdio.h>
int main()
{
int a,b;
printf("\n Enter two values.-");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("%d is bigger number\n”,a);
}
else
{
printf("%d is bigger number\n”,b);
}
return 0;
}
/* Program to find even or odd number (DIY Leap year)*/
#include<stdio.h>
int main()
{
int number;
printf("\n Enter the value of any number.");
scanf("%d",&number);
if(number%2==0)
{
printf("\n The number =%d is even\n",number);
}
else
{
printf("\n The number =%d is odd\n",number);
}
return 0;
}
/*Program to check voting eligibility */
#include<stdio.h>
int main()
{
int age;
printf(“Enter your age-“);
scanf(“%d”,&age);
if(age>=18)
{
printf(“You are %d years old so you are eligible for vote\n”,age);
}
else
5 RSCD
Std 10th C Programs :- Practical Notes
{
printf(“You are %d years old so you are not eligible for vote\n”,age);
}
return 0; }
/*Program to find positive or negative number */
#include<stdio.h>
int main()
{
int no;
printf(“Enter any number-“);
scanf(“%d”,&no);
if(no==0)
{
printf(“%d is Zero\n”,no);
}
else if(no>0)
{
printf(“%d is Positive number \n”,no);
}
else
{
printf(“%d is Negative number \n”,no);
}
return 0; }
/* Program to find greater no. between 3 numbers */
#include <stdio.h>
int main()
{
int n1,n2,n3;
printf("\n Enter three-.");
scanf("%d%d%d",&n1,&n2,&n3);
if((n1>n2)&&(n1>n3))
{
printf("The greater number is =%d\n",n1);
}
else if((n2>n1)&&(n2>n3))
{
printf("The greater number is =%d\n",n2);
}
else
{
printf("The greater number is =%d\n",n3);
} return 0; }
6 RSCD
Std 10th C Programs :- Practical Notes
7 RSCD
Std 10th C Programs :- Practical Notes
case 'a':
printf("Today is Saturday\n");
break;
default:
printf("%c character not belong to week day letter\n",day);
}
return 0;
}
/* Program of simple calculator using switch statement */
#include<stdio.h>
int main()
{
int n1,n2,choice;
printf("1 for Addition\n");
printf("2 for Subtraction\n");
printf("3 for Multiplication\n");
printf("4 for Division\n");
printf("5 for Modulus\n");
printf("\n Enter two values-");
scanf("%d%d",&n1,&n2);
printf("Enter your choice within the range of 1 -5:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Addition:=%d\n=",(n1+n2));
break;
case 2:
printf("Subtraction:=%d\n",(n1-n2));
break;
case 3:
printf("Multiplication:=%d\n",(n1*n2));
break;
case 4:
printf("Division:=%d\n",(n1/n2));
break;
case 5:
printf("Modulus:=%d\n",(n1%n2));
break;
default:
printf("Wrong choice);
break;
}
return 0;
}
8 RSCD
Std 10th C Programs :- Practical Notes
#include<stdio.h>
int main()
{
char choice;
printf("\n Enter any letter to find vowel or not\n");
scanf(" %c",&choice);
switch(choice)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
printf("Entered %c letter is vowel \n",choice);
break;
default:
printf("Entered %c letter is a consonant \n ",choice);
break;
}
return 0; }
Chapter 14
#include<stdio.h>
int main()
{
int i=1;
while(i<=10)
{
printf(“%d\n”,i);
i++;
}
return 0; }
9 RSCD
Std 10th C Programs :- Practical Notes
#include<stdio.h>
int main()
{
int i;
for(i=2;i<=20;i=i+2)
printf(“%d\n”,i);
return 0;
}
#include<stdio.h>
int main( )
{
int i,t,no;
printf("Enter any number \n");
scanf(" %d",&no);
printf("Table of %d as follows\n",no);
for(i=1;i<=10;i++)
{
t=i*no;
printf("%d * %d = %d\n",no,i,t);
}
return 0;
}
#include<stdio.h>
int main()
{
int count=0;
char choice;
printf("enter your choice (y/n)?\n");
scanf(" %c",&choice);
while(choice=='y')
{
count++;
printf("enter your choice (y/n)?\n");
10 RSCD
Std 10th C Programs :- Practical Notes
scanf(" %c",&choice);
}
printf("You enter in loop %d times\n",count);
return 0;
}
#include<stdio.h>
int main()
{
int i;
for(i=10;i>=1;i--)
printf(“%d\n”,i);
return 0;
}
#include<stdio.h>
int main()
{
int i,number[5]={5,10,15,20,25};
printf("The array elements are: \n");
for(i=0;i<5;i++)
printf("%d\n",number[i]);
return 0;
}
11 RSCD
Std 10th C Programs :- Practical Notes
/* Program of read and display 5 student marks & display average marks using Array*/
#include<stdio.h>
int main()
{
int i,mark[5],total=0;
for(i=0;i<5;i++)
{
printf("Enter marks[%d]",i);
scanf("%d",&mark[i]);
}
for(i=0;i<5;i++)
{
total=total+mark[i];
printf(“The total marks is %d\n”,total);
printf("The average marks of student is %d\n",(total/5));
}
return 0;
}
Chapter 16
#include<stdio.h>
void pl( );
int main()
{
pl();
printf(“Welcome to the world of C programing…\n”);
pl();
return 0;
}
void pl()
{
printf(“= = = = = = = = = = = = = = = = = = = = = = = = \n”);
}
12 RSCD
Std 10th C Programs :- Practical Notes
/* Program to display Sum of two numbers with ‘No Argument with Return’ */
#include<stdio.h>
int sum( );
int main()
{
int total;
total=sum();
printf(“The Addition of two numbers: %d\n”,total);
return 0;
}
int sum()
{
int a,b;
printf(“Enter Two numbers-“);
scanf(“%d%d”,&a,&b);
return (a+b);
}
/*Program to display cube of a number with ‘With Argument No Return’ */
#include<stdio.h>
void cube(int );
int main()
{
int n;
printf(“Enter any number-”);
scanf(“%d”,&n);
cube(n);
return 0;
}
void cube(int i)
{
printf(“The cube of %d number is %d\n”,i,i*i*i);
}
#include<stdio.h>
int sqt(int );
int main()
{
int n,ans;
printf(“Enter any number-”);
scanf(“%d”,&n);
ans=sqt(n);
printf(“The square of %d number is %d\n”,n,ans);
return 0;
}
int sqt(int i)
{
return(i*i);
}
13 RSCD