Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

1) Write a program to display arithmetic operations using

switch case:
#include<stdio.h>
#include"conio.h"
void main()
{
int a,b,c,choice;
clrscr();

printf("enter a=");
scanf("%d",&a);

printf("enter b=");
scanf("%d",&b);

printf("\n****menu****");
printf("\n1. addition");
printf("\n2. subtraction");
printf("\n3. multiplication");
printf("\n4. division");

printf("\n enter your choice=");


scanf("%d",&choice);

switch(choice)

{
case 1:c=a+b;
printf("the ans is=%d",c);
break;
case 2:c=a-b;
printf("the ans is=%d",c);
break;

case 3:c=a*b;
printf("the ans is=%d",c);
break;

case 4:c=a/b;
printf("the ans is=%d",c);
break;

case 5:c=a+b;
printf("good bye....");
break;

default:printf("wrong choice..");
break;
}
getch();
}

2) Write a program to display 10 numbers and their sum:


#include"stdio.h"
#include"conio.h"

void main()
{
int i, sum=0;

clrscr();

for(i=1;i<=10;i++)
{
sum=sum+i;
printf("%d\n",i);
}

printf("\n%d",sum);

getch();
}

3) Write program to show your multiplication table of a


given number:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,i;
clrscr();
printf("enter the number of table=");
scanf("%d",&a);
for(i=1;i<=10;i++)
{
printf("\n%d*%d=%d",a,i,a*i);
}
getch();

5) Write a program to print following string pattern as:

#include<stdio.h>
#include<conio.h>
void main()
{
char x[6]={'H','E','L','L','O'};
int a,i,j,k,l,m;
clrscr();
for(i=0;i<5;i++)
{ for(j=0;j<5-i;j++)
{
printf("%c",a[j]);
}
for(k=j;k<5;k++);
{
printf(" ");
}
for(l=5;l>j;l--)
{
printf(" ");
}
for(m=i;m<0;m++)
{
printf("%c",a[m]);
}
printf("\n");
}
getch();
}
6) Write a program to display following pattern for a given
number
#include<stdio.h>
#include<conio.h>
void main()
{
char x[6]={'H','E','L','L','O'};
int a,i,j,k,l,m;
clrscr();
for(i=0;i<5;i++)
{
for(j=0;j<5-i;j++)
{
printf("%c",a[j]);
}
for(k=j;k<5;k++);
{
printf(" ");
}
for(l=5;l>j;l--)
{
printf(" ");
}
for(m=i;m<0;m++)
{
printf("%c",a[m]);
}
printf("\n");
}
getch();
}
7) Write a program to check whether inputted number is
Armstrong number or not:
#include"stdio.h"
#include"conio.h"
#include"math.h"
void main()
{
int no,rev=0,rem;
int total=0;
int temp;
clrscr();
printf("enter the no =");
scanf("%d",&no);
temp= no;
while(no>0)
{
rem = no%10;
total=total+pow(rem,3);
no=no/10;
}
if(temp==total)
printf("the no is armstrong");
else
printf("the no is not armstrong");

getch();
}

8) Write a program to print Fibonacci serious up to 100:

#include<stdio.h>
#include"conio.h"
void main()
{
int a,b,c,i,n;
clrscr();
printf("enter the value=");
scanf("%d",&n);
a=0;
b=1;
printf("%d,",a);
printf("%d,",b);
for(i=3;i<=n;i++)
{
c=a+b;
printf("%d,",c);
a=b;
b=c;
}
getch();
}

9) Write a program to find factorial of a number:

#include<stdio.h>
#include"conio.h"
void main()
{
int n,i,f;
clrscr();
printf("enter n=");
scanf("%d",&n);
f=1;

for(i=n;i>=1;i--)
{
f=f*i;
}
printf("%d=%d\n",n,f);
getch();
}

10) Write a program to find whether given number is prime


number or not:
#include<stdio.h>
#include"conio.h"
void main()
{
int no,fact=0;
int i;
clrscr();
printf("Enter the no= ");
scanf("%d",&no);

for(i=1;i<no/2;i++)
{
if(no%i==2)
{
fact = 1;
break;
}
}
if(fact==1)
printf("the no is prime");
else
printf("the no is not prime");

getch();
}
11) Write a program to display sum serious
1+1/2+1/3+….+1/n:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,i;
clrscr();
printf("enter the number");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
printf("%d",i);
}
getch();
}

12) Write a program to find that entered year is leap year


or not:

#include<stdio.h>
#include"conio.h"
void main()
{
int year;
clrscr();
printf("\n enter the year=");
scanf("%d",&year);
if(year%4==0)
{
printf("this is leap year");
}
else
{
printf("this is not leap year");
}
getch();
}
13) Write a program to reverse a given number:

#include<stdio.h>
#include"conio.h"
void main()
{

int i,n;
clrscr();
printf("enter n=");
scanf("%d",&n);
for(i=n;i>=1;i++)
{
printf("%d\n",i);
}
getch();
}

You might also like