اكتب برنامج بلغة C وهو برنامج قائم على قائمة (Menu-Driven) لإجراء عملية حسابية بسيطة

  • برمجة
  • برمجة سي c

اكتب برنامج بلغة C وهو برنامج قائم على قائمة (Menu-Driven) لإجراء عملية حسابية بسيطة

بيانات للاختبار :

10
2
3

الخرج المتوقع :

The Multiplication of 10 and 2 is: 20

الأجوبة

/*Write a program in C which is a Menu-Driven Program to perform a simple calculation*/

#include <stdio.h>
void main() {
  int num1,num2,opt;
  printf("Enter the first Integer :");
  scanf("%d",&num1);
  printf("Enter the second Integer :");
  scanf("%d",&num2);
  
    printf("\nInput your option :\n");
    printf("1-Addition.\n2-Substraction.\n3-Multiplication.\n4-Division.\n5-Exit.\n");
    scanf("%d",&opt);
    switch(opt) {
      case 1:
        printf("The Addition of  %d and %d is: %d\n",num1,num2,num1+num2);
        break;
        
      case 2:
        printf("The Substraction of %d  and %d is: %d\n",num1,num2,num1-num2);
        break;
        
      case 3:
        printf("The Multiplication of %d  and %d is: %d\n",num1,num2,num1*num2);
        break;  
      
      case 4:
        if(num2==0) {
          printf("The second integer is zero. Devide by zero.\n");
        } else {
          printf("The Division of %d  and %d is : %d\n",num1,num2,num1/num2);
        }  
        break;
        
      case 5: 
        break; 
        
      default:
        printf("Input correct option\n");
        break; 
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...