0% found this document useful (0 votes)
2 views

C_programs

The document contains practical notes for C programming, including various example programs for basic operations such as variable usage, average calculation, conversions, and control structures. It covers topics like loops, conditionals, and arrays, providing code snippets for each example. The notes are structured by chapters, detailing specific programming tasks and their implementations.

Uploaded by

Aashish Rathor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C_programs

The document contains practical notes for C programming, including various example programs for basic operations such as variable usage, average calculation, conversions, and control structures. It covers topics like loops, conditionals, and arrays, providing code snippets for each example. The notes are structured by chapters, detailing specific programming tasks and their implementations.

Uploaded by

Aashish Rathor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Computer practical notes C language

Chapter 10 & 11

Note - Type the program in SciTe.


Save the file with .c extension.
For example, file name is one.c
In Terminal type the commands
for compilation: $ gcc one.c
for execution $. /sqrt

/* Program - use of variable*/ (1)


#include<stdio.h>
int main()
{
int a=10;
float b=20.6;
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*/ (2)
#include<stdio.h>
int main( )
{
float f,s,t,avg;
printf("\n Enter the value of first no.");
scanf("%f",&f);
printf("\n Enter the value of second no.");
scanf("%f",&s);
printf("\n Enter the value of third no.");
scanf("%f",&t);
avg=(f+s+t)/3;
printf("Average:=%f",avg);
return 0;
}

/* Program to convert rupees into paise */ (3)


#include<stdio.h>
int main()
{
float r,p;
printf("\n Enter the value of rupees.");
scanf("%f",&r);
p=r*100.0;
printf(" %f Rupees=%f paise\n",r,p);
return 0;
}

/* Program to convert centimetre into meter */ (4)


#include<stdio.h>
int main()
{
float cm,m;
printf("\n Enter the value of centimetre.");

Std 10th 1
Computer practical notes C language

scanf("%f",&cm);
m=cm/100.0;
printf(" %f Centimetre=%f meter\n",cm,m);
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;
}

/* Program for use of typedef (Calculate simple interest)*/ (5)


#include<stdio.h>
int main()
{
typedef float real;
real p,r,t,SI;
printf("\nEnter the value of principal, rate and time in years-");
scanf("%f%f%f",&p,&r,&t);
SI=(p*r*t)/100;
printf("Simple Interest :=%f\n",SI);
return 0;
}
/* Program for use of comma and sizeof() operator */ (6)
#include<stdio.h>
int main()
{
int a,b,c,size;
c=(a=30,b=20,a/b);
printf("\n The value of a:=%d\n, b:=%d\n, c:=%d\n",a,b,c);
size=sizeof(c);
printf("The size allocated to c variable :=%d\n",size);
return 0;
}
/* Program for use of typecast (Calculation of cost of one item) */ (7) page 235

#include<stdio.h>
int main()
{
int cost,qty;
float ans;
printf("\n Enter the cost and quantity-");
scanf("%d%d",&cost,&qty);
ans=cost/(float)qty;
printf("Cost of one item after type casting is %f\n",ans);
return 0;
}
Std 10th 2
Computer practical notes C language

Chapter 13
/* Program to calculate Bigger number between 2 numbers */ (7)

#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)*/ Lab ex. 4
#include<stdio.h>
int main()
{
int n;
printf("\n Enter the value of any number.");
scanf("%d",&n);
if(n%2==0)
{
printf("\n The number =%d is even\n",n);
}
else
{
printf("\n The number =%d is odd\n",n);
}
return 0;
}
/*Program to check voting eligibility */ Lab ex. 2
#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
{
printf(“You are %d years old so you are not eligible for vote\n”,age);
}
return 0;
}
/*Program to find positive or negative number */ Lab ex. 1
#include<stdio.h>
int main()
{
Std 10th 3
Computer practical notes C language

int n;
printf(“Enter any number-“);
scanf(“%d”,&n);
if(n==0)
{
printf(“%d is Zero\n”,n);
}
else if(n>0)
{
printf(“%d is Positive number \n”,n);
}
else
{
printf(“%d is Negative number \n”,no);
}
return 0;
}
/* Program of display Weekday name*/ (8)
#include<stdio.h>
int main()
{
int day;
printf("\n Enter the number of any day");
scanf(“%d”,&day;
switch(day)
{
case 1:
printf("Today is Sunday\n");
break;
case 2:
printf("Today is Monday\n");
break;
case 3:
printf("Today is Tuesday\n");
break;
case 4:
printf("Today is Wednesday\n");
break;
case 5:
printf("Today is Thrusday\n");
break;
case 6:
printf("Today is Friday\n");
break;
case 7:
printf("Today is Saturday\n");
break;
default:
printf("%d character not belong to week day number\n",day);
}
return 0;
}

Std 10th 4
Computer practical notes C language

/* Program of check vowel or consonant using switch statement */ Lab ex. 5

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

Std 10th 5
Computer practical notes C language

Chapter 14
/* Program of Counting using for loop*/(9)
#include<stdio.h>
int main()
{
int i;
for(i=1;i<=10;i++)
printf(“%d\n”,i);
return 0;
}
/* Program of Counting using while loop*/(9.1)

#include<stdio.h>
int main()
{
int i=1;
while(i<=10)
{
printf(“%d\n”,i);
i++;
}
return 0;
}
/* Program of Counting using do-while loop*/(9.2)
#include<stdio.h>
int main()
{
int i=1;
do
{
printf(“%d\n”,i);
i++;
} while(i<=10);
return 0;
}
/*Program to series 2,4,6,8……. (Even numbers) (10) DIY Odd numbers */

#include<stdio.h>
int main()
{
int i;
for(i=2;i<=20;i=i+2)
printf(“%d\n”,i);
return 0;
}
/* Program to display reverse counting (10,9,8,7….) using for loop */(11)

#include<stdio.h>
int main()
{
int i;
for(i=10;i>=1;i--)
printf(“%d\n”,i);
return 0;
}

Std 10th 6
Computer practical notes C language

/*Program to print star pattern*/ (12)


#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf(“* “); // printf(“%d “,i) or printf(“%d “,j);
}
printf(“\n”);
}
return 0;
}
Chapter 15
/* Program of read and display 5 student marks & 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;
}

Std 10th 7

You might also like