Write a program in C language. Here is the complete assignment.

Through the standard user input stream, integers are entered. The last number is entered 0. After the user has entered the last number (zero), the program should print to the standard output stream:

  • the number of positive numbers in decimal notation ending in 7.

I tried to do something, but all attempts fail, help to finish the code.

#include <conio.h> #include <stdio.h> int main() { int num = 0; int x = 0; printf("To quit, enter 0\n"); /*бесконечный цикл*/ while (1) { printf("Please, enter number: "); scanf_s("%d", &num); /*условие выхода из цикла*/ if (num == 0) { break; } if ((num % 10) &&(num=7)){ 
  • if ((num % 10) &&(num=7)){ replace with if (num % 10=7){ - Vladimir Klykov
  • one
    num=7 you are not the case num == 7 wanted to write? - LLENN

1 answer 1

This

 if ((num % 10) &&(num=7)){ 

It should be replaced by

 if (num % 10 == 7) { 

This is the verification of the last digit of the number.

  • Thank you very much)) But how to display the number of digits ending in the number 7? - user312221 5:52 pm
  • Maybe the number of numbers? :) Start a variable counter of this number, and if the condition is fulfilled, increase it by 1. And at the end of the work, after exiting the cycle, output it. - Harry
  • Yes, the number of numbers ending in a number 7)) if I increase by one, I will get all the numbers, but I need only those that end in 7 - user312221
  • 2
    Got sick. Get the finished program - ideone.com/B7Hdcz - and do not say nonsense. And remember - the NUMBER is just a symbol, the number cannot end at 7. Otherwise, you, as the student who writes to the teacher, “I wrote the word" went "a hundred times and went home ..." - Harry