Page 1 of 16
Page 1 of 16
Program – 1
Aim: Write a program to convert Fahrenheit temperature into centigrade.
c=5*(f-32)/9.0
#include<stdio.h>
#include<conio.h>
void main()
{
int f;
float c;
clrscr();
printf("Enter the temp in F:");
scanf("%d",&f);
c=(5*(f-32)/9.0);
printf("temp in centigrade: %f",c);
getch();
}
Program – 2
Aim: Write a program to find the area of triangle.
Area = sqrt(s*(s-a)*(s-b)*(s-c))
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c;
float s,d,area;
clrscr();
printf("Enter the sides of tringle:");
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2.0;
d=(s*(s-a)*(s-b)*(s-c));
area=sqrt(d);
printf("Area of:%f",area);
getch();
}
Program -3
Aim: Write a program to find the sum of series till n elements
1^1 + 2^2 + 3^3 +----
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,i;
static temp=0;
clrscr();
printf("Series: 1^1 + 2^2 +3^3 +4^4 + ------");
printf("\nEnter the no of element:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
temp=temp+pow(i,i);
}
printf("sum:%d",temp);
getch();
}
Program – 4
Aim: Write a program to find the sum of series till n elements
1/!1 + 2/!2 + 3/!3 +----
#include<stdio.h>
Page 2 of 16
#include<conio.h>
void main()
{
int n,i,j;
float fact=1;
float sum=0;
clrscr();
printf("sum of series: 1/!1 + 2/!2 + ");
printf("\nEnter the no of element for sesies:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
fact=fact*j;
}
sum=sum+(i/fact);
}
printf("Sum : %f",sum);
getch();
}
Program – 5
Aim: Write a program to find number is even or odd.
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
if(n%2==0)
{
printf("Number is even");
}
else
{
printf("Number is odd");
}
getch();
}
Program – 6
Aim: Write a program for finding year is leap or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter the year");
scanf("%d",&year);
if((year%400==0) ||(year%100!=0 && year%4==0))
{
printf("%d is leap year");
}
else
{
printf(" %d is not a leap year");
}
getch();
}
Program – 7
Aim: Write a program to find ASCII Code of the entered character.
Page 3 of 16
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("Enter the chracter:");
scanf("%c",&ch);
printf("%c 's ASCII code is: %d",ch,ch);
getch();
}
Program – 8
Aim: Admission to a professional course is subject to the following condition
math>=60, phy>=50, chem>= 150.
Write a program for finding that candidtes are eliglible or not
#include<stdio.h>
#include<conio.h>
void main()
{
int math,phy,chem;
clrscr();
printf("Enter the marks math:");
scanf("%c",&math);
printf("Enter the marks phy:");
scanf("%c",&phy);
printf("Enter the marks chem:");
scanf("%c",&chem);
#include<stdio.h>
#include<conio.h>
void main()
{
int bs;
float da,hra,gross;
clrscr();
printf("Enter the basic salary:");
scanf("%d",&bs);
da = (0.4*bs);
hra = (0.2*bs);
gross = bs+da+hra;
printf("\nDearness allowance: %f",da);
printf("\nHouse rent allowance: %f",hra);
printf("\nGross salary: %f",gross);
getch();
}
Program – 10
Aim: Write a program for performing all arithmetic operation using switch
case.
Page 4 of 16
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,n;
float c;
clrscr();
printf("Enter the number:");
scanf("%d%d",&a,&b);
printf("1.Addition\n");
printf("2.Subtraction\n");
printf("3.Division\n");
printf("4.Multiply\n");
printf("5.Modulo Division\n");
printf("Enter ur choce:");
scanf("%d",&n);
switch(n)
{
case 1: c=a+b;
printf("Add:%f",c);
break;
case 2: c=a-b;
printf("Sub:%f",c);
break;
case 3: c=a/b;
printf("Div:%f",c);
break;
case 4: c=a*b;
printf("Muli:%f",c);
break;
case 5: c=a%b;
printf("Modulo Div:%f",c);
break;
default:
printf("U enter worng choice");
}
getch();
}
Program – 11
WAP to print all prime numbers less than 500.
#include<stdio.h>
#include<conio.h>
void main()
{
int count,i=1;
int a;
clrscr();
while(i<=500)
{
count=0;
a=1;
while(a<=i)
{
if(i%a==0)
count++;
a++;
}
if(count==2)
printf("%d\t",i);
i++;
}
getch();
}
Page 5 of 16
Program – 12
WAP to search for an item from a given array.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i;
int ele,temp=0,pos=0;
clrscr();
printf("enter the array elements\n");
for (i=0; i<5; i++)
scanf("%d",&a[i]);
printf("Enter the element to be search\n");
scanf("%d",&ele);
if (temp==1)
printf("Element found %d , position==%d",ele,pos);
else
printf("Element not found\n");
getch();
}
Program – 13
Explain a “C” program to test whether a given number is prime number or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,c=0,i,n;
printf("enter the number to be checked");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a=n%i;
if(a==0)
{
c=c+1;
}
}
if (c==2)
{ printf("the given number is prime"); }
else
printf("the given number is not prime");
getch();
}
Program – 14
Explain a “C” program to test whether a given year is leap year or not.
#include<stdio.h>
#include<conio.h>
void main( )
Page 6 of 16
{
int year;
printf("Enter the year: ");
scanf("%d",&year);
Program – 16
WAP to find the reverse of a number and check whether it is palindrome or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,mod,rev=0;
Page 7 of 16
printf("Enter a number:");
scanf("%d", &num);
while(num>0)
{
mod=num%10;
rev=(rev*10)+mod;
num=num/10;
}
printf("Reverse of the given number: %d", rev);
if(num==rev)
printf(“No is palindrome”);
else
printf(“No is not palindrome”);
getch();
}
Program – 17
WAP to accept any number n and print the sum of square of all numbers from 1 to n.
#include<stdio.h>
#include<conio.h>
void main()
{
int sqr,n,sum=0; ;
printf("Enter a number:");
scanf("%d", &n);
while(n>=1)
{
sqr=n*n;
sum=sum+sqr;
n=n-1;
}
printf(“sum of square of all numbers from 1 to %d is %d”,n,sum);
getch();
}
Program – 18
Write a program to accept three numbers and smallest number among them.
# include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf(“enter 3 nos”);
scanf(“%d%d%d”,&a,&b,&c);
if((a<b)&&(a<c))
printf(“smallest no among given three no is %d”,a);
else
{if(b<c)
printf(“smallest no among given three no is %d”,b);
else
printf(“smallest no among given three no is %d”,c);}
getch();
}
Program – 19
Write a program to print odd numbers starting from 1 to 10 and printing their sum also.
# include<stdio.h>
#include<conio.h>
void main()
{ int i sum=0;
for(i=1;i<=10;i++)
{ if (i%2!=0)
{printf( “%d\n”,i);
Page 8 of 16
sum=sum+i;
}
}
printf(“sum of odd nos :%d”,sum);
getch();
}
Program – 20
Write a program, which accepts salary of a person. If salary is greater than Rs. 10,000
but less than 20,000 then it should print “executive”. If the salary is greater than or
equal to 20,000 then it should print “manager”. In rest of condition, it should print
“worker”.
#include<stdio.h>
#include<conio.h>
void main()
{int sal;
printf(“enter salary of a person”);
scanf(“%d”,sal);
if (sal<=10000)
printf(“WORKER”);
else
{if ((sal>10000)&&(sal<20000))
printf(“EXECUTE”);
else
printf(“MANAGER”);
}
getch();
}
Program – 21
#include<stdio.h>
#include<conio.h> case 4:
printf(“Thursday”);
void main( ) break;
{ case 5:
int choice; printf(“Friday”);
printf(“Enter Choice:”); break;
scanf(“%d”,&choice); case 6:
printf(“Saturday”);
switch(choice) break;
{ case 7:
case 1: printf(“Sunday”);
printf(“Monday”); break;
break; default:
case 2: printf(“U enter wrong choice”);
printf(“Tuesday”);
break;
case 3: }
printf(“Wednesday”); getch();
break; }
Write a program to print the all even numbers starting for 1 to 100 in reverse order i.e.
100, 98, and 96 and so on.
#include<stdio.h>
#include<conio.h>
void main()
{ int i;
for (i=100; i>1;i--)
{ if(i%2==0)
printf(“%d”,i);}
getch();
Page 9 of 16
}
Program – 23
Write a program to accept value of N and the sum of N term Fibonacci series.
#include<stdio.h>
#include<conio.h>
void main()
{ int i, n, a=0,b=1,sum=0,s=1;
printf(“enter the no “);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{ sum=a+b;
a=b;
b=sum;
s=s+sum;
}
printf(“sum of %d term Fibonacci series is %d”,n,s);
getch();
}
Program – 24
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],count_even=0,count_odd=0,i;
for(i=0;i<5;i++)
scanf("%d",&a[i]);
/* display the number of odd and even intergers */
for(i=0;i<5;i++)
{
if((a[i]%2 ==0))
count_even++;
if((a[i]%2==1))
count_odd++;
}
printf("%d %d",count_even,count_odd);
getch();
}
Program – 25
What is pointer? Write a C program to swap the values of two variables making use of
pointers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf(“enter 2 values”);
scanf(“%d%d”,&a,&b);
swap(a,b);
printf("%d%d",b,a);
getch();
}
Page 10 of 16
swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
printf("%d%d",x,y);
}
Program – 26
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50][50],b[50][50],c[50][50],i,j,n;
clrscr();
printf("Enter the size of matrix n i.e. n xn not more than 50");
scanf("%d",&n);
/* Addition of Matrix */
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j] + b[i][j];
}
}
void main()
{
int a[50][50],b[50][50],c[50][50],i,j,k,n;
clrscr();
printf("Enter the size of matrix n i.e. n xn not more than 50");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=0;
}
}
/* Multiplication of Matrix */
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+ a[i][k] * b[k][j];
}
}
}
/* Printing Of Resultant Matrix */
printf("\nThe Resultant matrix is\n");
Page 12 of 16
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
getch();
}
Program – 25
}
Program – 28
Wap for storing the 100 student detail and retrieved them with the help of structure
#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
int roll;
char branch[10];
};
struct student std[100];
void main()
{
clrscr();
int i;
for(i=0;i<100;i++)
{
printf("enter student detail");
scanf("%s%d%s",std[i].name,&std[i].roll,std[i].branch);
}
for(i=0;i<100;i++)
printf("%s%d%s",std[i].name,std[i].roll,std[i].branch);
getch();
}
Program – 28
Wap for Copy a file to another file.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *fs,*ft;
char ch;
clrscr();
fs = fopen(“Source.c”,"r");
if(fs==NULL)
{
printf("Cannot open source file ! Press key to exit.");
getch();
exit(0);
}
ft = fopen(“Destination.c”,"w");
if(ft==NULL)
{
Page 16 of 16
printf("Cannot copy file ! Press key to exit.");
fclose(fs);
getch();
exit(0);
}
while(1)
{
ch = getc(fs);
if(ch==EOF)
{
break;
}
else
putc(ch,ft);
}
printf("File copied succesfully!");
fclose(fs);
fclose(ft);
}