Practical File For External 2nd
Practical File For External 2nd
PROJECT-C PROGRAMS
-
2.write a program to find out the square of
number.
SOURCE CODE-
#include<stdio.h>
int main()
{
int a,c;
printf("enter a number");
scanf("%d",&a);
c=a*a;
printf("%d",c);
return 0;
}
OUTPUT-
}
3.write a program of swapping two number with
the help of temporary variable.
SOURCE CODE-
#include<stdio.h>
int main()
{
int a,b,temp;
printf("enter the number");
scanf("%d%d",&a,&b);
temp=a;
a=b;
b=temp;
printf("a=%d b=%d",a,b);
return 0;
}
Output-
4.write a program of swapping two number
without temporary variable.
SOURCE CODE-
#include<stdio.h>
int main()
{
int a,b;
printf("enter two number");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("a=%d b=%d",a,b);
return 0;
}
OUTPUT-
5.write a program to find out whether a number
is even or odd.
SOURCE CODE-
#include<stdio.h>
int main()
{
int n;
printf("enter a number");
scanf("%d",&n);
if(n%2==0)
{
printf("even");
}
else
{
printf("odd");
}
return 0;
}
OUTPUT-
6.write a program to find sum of first n natural
number.
SOURCE CODE-
#include<stdio.h>
int main()
{
int n,sum=0,i;
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf("%d",sum);
return 0;
}
OUTPUT-
7.Write a program to print a table of 5.
SOURCE CODE-
#include<stdio.h>
int main()
{
int i;
printf("enter table of five\n");
for(i=1;i<=10;i++)
{
printf("%d\n",5*i);
}
return 0;
}
OUTPUT-
8.Write a program to print first 20 even numbers
.
SOURCE CODE-
#include<stdio.h>
int main()
{
int i;
printf("enter first 20 even numbers\n");
for(i=1;i<=20;i++)
{
if(i%2==0)
{
printf("%d\n",i);
}}
return 0;
}
OUTPUT-