Showing posts with label if-else. Show all posts
Showing posts with label if-else. Show all posts
C Program to Detect int Underflow-Overflow using if-else
How to write a C Program to detect integer overflow-underflow in C Programming Language ?
Solution:
/*Program detect overflow-underflow in C*?
#include<stdio.h>
int main()
{
unsigned long long int a,b,i;
while(scanf("%llu",&a)!=EOF)
{
if(a<8)
{
printf("Underflow!\n");
}
else if(a<14)
{
b=1;
for(i=1;i<=a;i++)
{
b=b*i;
}
printf("%llu\n",b);
}
else
{
printf("Overflow!\n");
}
}
return 0;
}
Calculator Using IF-ELSE in C Program
How to write a c program to create a calculator using if-Else statement in C Programming Language ?
Solution:
/*Calculator Using IF-ELSE in C Program*/
#include <stdio.h>
#include <stmib.h>
int main(int argc, char *argv[]);
{
printf("Welcome in my suprematorCalculator 1.0 !\nBy AerysFeather\n\n\n");
delay(2500);
printf("What do you want to do ? (press the nuber)\n");
int choice = 0;
printf("-Addition(1)\n-Substraction(2)\n-Multiplication(3)\n-Division(4)")
scanf("%d", %choice)
float numberFirst = 0;
printf("Please enter the first number.");
scanf("%f", %numberFirst);
float numberSecond = 0;
printf("Please enter the second number.");
scandf("%f", %numberSecond);
int result = 0;
if (choice = 1)
{
printf("%d + %f = %d", numberFirst, numberSecond, result)
}
if (choice = 2)
{
printf("%d - %f = %d", numberFirst, numberSecond, result)
}
if (choice = 3)
{
printf("%d * %f = %d", numberFirst, numberSecond, result)
}
if (choice = 4)
{
printf("%d / %f = %d", numberFirst, numberSecond, result)
}
else
{
printf("Please choose a calcul type.");
}
return 0;
}
Subscribe to:
Posts (Atom)