Friday 24 June 2016

Basic C language programs



1. WAP in C to print "hello c ....."

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“hello c ……”);
getch();
}

output:








2. WAP in C to accept a number from user and print square of it:

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf("Enter any number\n");
scanf("%d",&x);
y=x*x;
printf("square of %d is %d",x,y);
getch();
}

output:







3. WAP in C to find sum of two numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
clrscr();
printf("Enter two number\n");
scanf("%d",&x);
scanf("%d",&z);
z=x+y;
printf("sum of %d and %d is %d",x,y,z);
getch();
}

output:








4. WAP in C to find area of circle:

#include<stdio.h>
#include<conio.h>
void main()
{
float a,r;
clrscr();
printf("enter radius :");
scanf("%f",&r);
a=3.14*r*r;
printf("Area of circle with radius %f is %f",r,a);
getch();
}

output:








5. WAP in C to find circumference of circle:

#include<stdio.h>
#include<conio.h>
void main()
{
float a,r;
clrscr();
printf("enter radius :");
scanf("%f",&r);
a=2*3.14*r;
printf("Circumference of circle with radius %f is %f",r,a);
getch();
}

output:










6. WAP in C for formula s=ut+½at².

#include<stdio.h>
#include<conio.h>
void main()
{
float s,u,t,a;
clrscr();
printf("enter value for u:");
scanf("%f",&u);
printf("enter value for a:");
scanf("%f",&a);
printf("enter value for t:");
scanf("%f",&t);
s=u*t+0.5*a*t*t;
printf("value of s=%f",s);
getch();
}

output:







7. WAP in C to accept five subject marks from user and then print total marks and percentage:

#include<stdio.h>
#include<conio.h>
void main()
{
float s1,s2,s3,s4,s5,t,p;
clrscr();
printf("enter five subject marks:");
scanf("%f%f%f%f%f",&s1,&s2,&s3,&s4,&s5);
t=s1+s2+s3+s4+s5;
printf("\nmarks obtained=%f\n",t);
p=t*100/500;
printf("percentage=%f",p);
getch();
}

output:









8. WAP in C for swapping using third variable:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("Enter value of a:");
scanf("%d",&a);
printf("\nEnter value of b:");
scanf("%d",&b);
printf("\nBefore swapping a=%d and b=%d",a,b);
temp=a;
a=b;
b=temp;
printf("\nAfter swapping a=%d and b=%d",a,b);
getch();
}

output:











9. WAP in C for swapping without using third variable: 

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b;
clrscr();printf("Enter value of a:");
scanf("%d",&a);
printf("\nEnter value of b:");
scanf("%d",&b);
printf("\nBefore swapping a=%d and b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swapping a=%d and b=%d",a,b);
getch();
}

output:








10. WAP in C to calculate total salary:

/*In this program we accept basic salary of user then calculate total salary according to formula
total Salary = basic Salary+TA+DA+HRA
TA=40% of basic salary
DA=60% of basic salary
HRA=50% of basic salary*/

#include<stdio.h>
#include<conio.h>
void main()
{
float bs,ta,da,hra,ts;
clrscr();
printf("Enter basic salary:");
scanf("%f",&bs);
ta=bs*40/100;
da=bs*60/100;
hra=bs*50/100;
ts=bs+ta+da+hra;
printf("\nTA=%f",ta);
printf("\nDA=%f",da);
printf("\nHRA=%f",hra);
printf("\ntotal salary=%f",ts);
getch();
}

output:









No comments:

Post a Comment

index

MENU Sample Papers  (new sample paper added for computers) C Language Mathematics IX (NCERT solution)   Computer IX (CBSE) ...