#include<stdio.h>
int main()
{
int u1,u2;
printf("Enter two num : ");
scanf("%d %d",&u1,&u2);
return u1 == 30 || u2 == 30 || (u1+u2 == 30);
}
Question is: Write a C program to check two given integers, and return true if one of them is 30 or if their sum is 30. I am new to Programming, If anyone Help me out what's wrong in this code. It should return 1 or True
The return value is mapped to the process exit code. Normally 0
is success, so this will have a failure if that is logically true.
You may want to put this in a proper function and write a printf
to display it:
#include <stdio.h>
int compare()
{
int u1,u2;
printf("Enter two num : ");
scanf("%d %d",&u1,&u2);
return u1 == 30 || u2 == 30 || (u1+u2 == 30);
}
int main(int argc, char** argv) {
printf("Result=%d\n", compare());
return 0;
}
Tip: Instead of taking interactive input notice how
argv
is like right there awaiting input as command-line arguments!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.