#include <stdio.h>
int main(void){
int sum,x;
while(x != 0){
printf("\n Enter a number : ");
scanf("%d",&x);
sum=sum+x;
}
printf("Sum of the entered numbers : %d ", sum);
return 0;
}
Here is one sample output. You can enter different numbers and check the output.
Enter a number : 4
Enter a number : 5
Enter a number : 7
Enter a number : 0
Sum of the entered numbers : 16
#include <stdio.h>
int main(void){
int sum,x;
while(x >= 0){
printf("\n Enter a number : ");
scanf("%d",&x);
if(x>=0) sum=sum+x;// negative number is not added.
}
printf("Sum of the entered numbers : %d ", sum);
return 0;
}
#include
int main(void){
int sum,x;
int max_no=0;
while(x >= 0){
printf("\n Enter a number : ");
scanf("%d",&x);
if(x>=0){
sum=sum+x;// negative number is not added.
if(x > max_no){
max_no=x;
}
}
}
printf("Sum of the entered numbers : %d ",sum);
printf("\n Highest number : %d ",max_no);
return 0;
}
30-04-2022 | |
#include <stdio.h> #include <conio.h> int main() { int grade=74; if (grade>74) { printf(“Passed”); } else if (grade<75 && grade>69) { printf(“Conditional Pass”); } else (grade<70) { printf(“Failed!”); } getch(); return 0; } |