C Programming File: Guru Gobind Singh Indraprastha University
C Programming File: Guru Gobind Singh Indraprastha University
UNIVERSITY
C PROGRAMMING FILE
Submitted by:
Mansi Marwah
(02116001318)
B.Tech. (biotech) Sem 1
Index
S.No. Program Date Teacher’s sign.
1.Write a program for addition of two numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
a=1;
b=2;
c=a+b;
printf("the sum of 1 and 2 is %d",c);
getch();
}
2.Write a program for addition of two numbers inserted
by user.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter first number ");
scanf("%d",&a);
printf("enter second number ");
scanf("%d",&b);
c=a+b;
printf("the sum is %d",c);
getch();
}
3. Write a program to calculate simple interest.
#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,t,i;
clrscr();
printf("enter principle ");
scanf("%f",&p);
printf("enter rate ");
scanf("%f",&r);
printf("enter time in years ");
scanf("%f",&t);
i=(p*r*t)/100.0;
printf("interst is %f",i);
getch();
}
4.Write a program to calculate simple interest for three users by
taking principle, rate and time as input from the users.
#include<stdio.h>
#include<conio.h>
void main()
{
int p,r,t,i, count=1;
clrscr();
while(count<=3)
{ printf("\nenter principle ");
scanf("%d",&p);
printf("enter rate ");
scanf("%d",&r);
printf("enter time in years ");
scanf("%d",&t);
i=(p*r*t)/100.0;
printf("interst is %d",i);
count++;
}
getch();
}
5.Write a program to calculate largest of two numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter first number");
scanf("%d",&a);
printf("enter second number");
scanf("%d",&b);
if(a>b)
printf("greater number is %d",a);
else
printf(" greater number is %d",b);
getch();
}
6.Write a program to calculate largest of three numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter first number");
scanf("%d",&a);
printf("enter second number");
scanf("%d",&b);
printf("enter third number");
scanf("%d",&c);
if(a>b && a>c)
printf("greatest number is a-> %d",a);
else if (b>a && b>c)
printf(" greatest number is b-> %d",b);
else
printf("greatest no is c -> %d",c);
getch();
}
7.Write a program to check whether a number is even or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("insert any number");
scanf("%d",&i);
{
if (i%2==0)
{printf("this no is even");
}
else
printf("this is not an even number");
i++;
}
getch();
}
8.Write a program to print even numbers from 1 to 20.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while(i<=20)
{
if(i%2==0)
{
printf("%d ",i);
}
i++;
}
getch();
}
9.Write a program to select a number upto which even numbers
have to be written.
#include<stdio.h>
#include<conio.h>
void main()
{
int i, count=1;
clrscr();
printf("enter number");
scanf("%d",&i);
while(count<=i)
{ if(count%2==0)
printf("%d ",count);
count++;
}
getch();
}
10.Write a program to check whether a number is prime or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a,temp=0;
clrscr();
printf("enter an number");
scanf("%d",&a);
for(i=2; i<a; i++ )
{
if(a%i==0)
{
temp=1;
break;
}
}
if(temp==1)
printf("\nno is not prime ");
else
printf("the number is prime");
getch();
}
11. Write a program to calculate sum of maximum 10 numbers
and negative numbers must be skipped from calculations.
#include<stdio.h>
#include<conio.h>
void main()
{ int i, sum=0 , n;
clrscr();
for(i=1; i<=10; i++)
{
printf("enter no.(%d) : ",i);
scanf("%d",&n);
if(n<0)
continue;
sum=sum+n;
}
printf("the sum is : %d",sum);
getch();
}