Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/*Write a function named myMessage() that prints the following message until the user inputs a non-negative integer. But it will not print the message more than N times which is taken from caller. The function should return the number of times that it prints the message to the caller. "This is an imaginary world and I am alive in this world"*/ #include
int myMessage(int Lim); int main() { int N,result; scanf("%d",&N); result=myMessage(N);//U can deny this declaration line(#prototype) by defining the function before main() printf("%d",result); return 0; } int myMessage(int Lim) { int i,a,cnt=0; if(Lim==0)return cnt;//If we consider the case N can be equal to 0 scanf("%d",&a); while(a<0) { printf("This is an imaginary world and I am alive in this world\n"); cnt++; if(cnt==Lim)//You can put ">=" in stead of "==" break; scanf("%d",&a); } return cnt; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)