11. Write a program to perform some mathematic functions with the help of “switch-case” statement.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,ans;
char c;
clrscr();
printf("\ Enter a and b:");
scanf("%d%d",&a,&b);
printf("\n Enter operator:");
fflush(stdin);
scanf("%c",&c);
switch(c)
{
case'+':ans=a+b;
break;
case'-':ans=a-b;
break;
case'*':ans=a*b;
break;
case'/':ans=a/b;
break;
}
printf("\n ans %d",ans);
getch();
}
12. Print the Fibonacci series
#include<stdio.h>
#include<conio.h>
void main()
{
int a=1,b=1,s=3,c,ch;
clrscr();
printf("how many steps=");
scanf("%d",&ch);
printf("%5d%5d",a,b);
for(s=3;s<=ch;s++)
{
c=a+b;
printf("%5d",c);
a=b;
b=c;
}
getch();
}
13. Write a program to check whether the number entered by the user is Palindrome or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int x=0,y,no,temp;
clrscr();
printf("no");
scanf("%d",&no);
temp=no;
while(no>0)
{
y=no%10;
x=(x*10)+y;
no=no/10;
}
if(temp==x)
printf("palindrome");
else
printf("not");
getch();
}
14. Make the simple calculator, where the operator to perform mathematical task will be entered by the user.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
char d;
clrscr();
printf(" Enter any two no=");
scanf("%d%d",&a,&b);
printf("enter operator");
scanf("%c",&d);
switch(d)
{
case '+': c=a+b;
printf("%d",c);
break;
case '-':c=a-b;
printf("%d",c);
break;
case '*' : c=a*b;
printf("%d",c);
break;
default:
printf("invalid");
}
getch();
}
15. Simple example using “continue” keyword.
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("enter any no=");
scanf("%d",&no);
for(no=1;no<=100;no++)
{
if(no%13==0)
continue;
printf("%5d",no);
}
getch();
}
Made By: Chaudhary Amit V.
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteIn 11th program why we should use fflush(stdin);
ReplyDeletewithout this there is error in my o/p but using this makes my o/p correct.