Professional Documents
Culture Documents
C - Practical
C - Practical
#include<stdio.h>
#include<conio.h>
void main ( )
{
clrscr ( );
printf(”hello”);
getch ();
}
#include<stdio.h>
#include<conio.h>
void main ( )
{
int a, b, c;
clrscr ( );
printf(”enter a number=”);
scanf(“%d”,& a);
printf(”enter another number=”);
scanf(“%d”,& b);
c=a+b;
printf(“the ans is=%d”,c);
getch();
}
3. TO ACCEPT DAYS AND DISPLAY THEM IN THE FORMAT MONTHS
AND DAYS. (45DAYS=1MONTHS 15 DAYS).
#include<stdio.h>
#include<conio.h>
void main ( )
int d, m, y;
clrscr ( );
d=y%30;
m=y/30;
printf(”days=%d”,d);
getch();
}
4. TO DISPLAY PRINCIPLE AMOUNT
#include<stdio.h>
#include<conio.h>
void main ( )
float d,p,r;
int t;
clrscr ( );
scanf(“%f”,&p);
scanf(“%f”,&r);
printf(”enter time=”);
scanf(“%d”,&t);
d=p*r*t/100;
getch();
}
5. IF STATEMENT.
#include<stdio.h>
#include<conio.h>
void main ( )
int mark;
clrscr( );
scanf(“%d”,& mark);
if (mark>300)
getch ();
#include< stdio.h>
#include<conio.h>
void main ( )
int mark;
clrscr( );
if (mark>300)
else
getch ();
#include< stdio.h>
#include<conio.h>
void main ( )
int a;
clrscr( );
scanf(“%d”,& a);
if(a>0)
printf(”the no.is positive’’);
else
printf(”the no.is negetive’’);
getch( );
}
9. WRITE A PROGRAM TO DISPLAY A MULTIPLICATION
#include<stdio.h>
#include<conio.h>
void main ( )
{
int i, a, b;
clrscr ( );
printf(”enter a number=”);
scanf(“%d”,& a);
for(i=1;i<=10;i++)
{
b=a*i;
printf(“\n the result is=%d”,b);
}
getch();
}
10. WRITE A PROGRAM TO DISPLAY THE EVEN NO BETWEEN 1-20 USING WHILE LOOP.
#include<stdio.h>
#include<conio.h>
void main ( )
{
Int i=1;
Clrscr();
While(i<=20)
{
If(i%2==0)
i++;
getch();
11. WRITE A PROGRAM TO DISPLAY THE EVEN NO BETWEEN 1-20 USING DO WHILE LOOP.
#include<stdio.h>
#include<conio.h>
void main ( )
{
int i=0;
Clrscr();
do
If(i%2==0)
i++;
}while (i<=20);
getch();
}
12. WRITE A PROGRAM TO DISPLAY SUM OF 10 NO. USING
#include<stdio.h>
#include<conio.h>
void main ( )
{
int i,sum=0,a[10];
clrscr();
for(i=0;i<=9;i++)
{
printf(“enter values=”);
scanf(“%d”,& a[i]);
sum=sum+a[i];
}
printf(“the sum=%d”,sum);
getch();
}