Programs With Flowchart and Algorithm
Programs With Flowchart and Algorithm
Step 2: Read two values and an operator- num1, num2 and operator
else
result = num1/num2
goto step 7
FLOWCHART:
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,res;
char op;
printf("Enter an Expression (eg:1+6): ");
scanf("%f %c %f",&a,&op,&b);
switch(op)
{
case '+' : res=a+b;
break;
case '-' : res=a-b;
break;
case '*' : res=a*b;
break;
case '/' : if(b==0)
{
printf("Arthimetic Exception:Cannot Divide a number by 0.");
return; D
}
else
{
res=a/b;
}
break;
case '%' : res= (int)a % (int)b;
}
printf("%g %c %g = %g \n",a,op,b,res);
}
OUTPUT:
3. Develop a program to compute the roots of a quadratic equation by accepting the coefficients.
Print appropriate messages.
ALGORITHM:
#include<stdio.h>
#include<math.h>
void main( )
{
float a,b,c,disc,root1,root2,real,imag;
OUTPUT:
4. Develop a program to find the reverse of a positive integer and check for palindrome or not.
Display appropriate messages.
ALGORITHM:
Step 5: [Check if original number and reversed number are same. If it is then, number is a
palindrome. Otherwise, not palindrome]
if(rev=n) then
print “palindrome”
else
print “not a palindrome”
end if
Step 6: [Finished]
End
FLOWCHART:
#include<stdio.h>
void main()
{
long int temp,rev=0,i,num,remainder;
printf("Enter the number \n");
scanf("%ld",&num);
temp=num;
while(num!=0)
{
remainder=num%10;
num=num/10;
rev=rev*10+remainder;
}
printf("The reverse of the number is %ld\n",rev);
if(rev==temp)
printf("%ld is a palindrome \n",temp);
else
printf("%ld is not a palindrome \n",temp);
}