C Programming: Do an operation until the desired result [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm really new to programming so please help me.
Here's my algorithm:
Enter a number
If the number is greater than 26
Subtract 26 from the number
Until the number is less than 26
Then display the final result
How do I write the code for this?
Thank You!

Try this. But next time do put some effort when formulating your question
if (scanf("%d", &n) == 1) {
while (n >= 26) {
n -= 26;
}
printf("%d", n) ;
}

Related

In C language, how can I print 1234567890 to create a position/location ruler? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
basically, I want to create a Position/location ruler which shows each numeric position starting at 1. let's say, if the characters in the above statement are 20 then in the next line 12345678901234567890 should be printed. similarly, if the characters are 30 then 123456789012345678901234567890 should be printed.
how can I do that?
Let's say n is the length you need to match
int n = 20; // or 30, or whatever
for (int i = 0; i < n; i++) printf("%d", (i + 1) % 10);
puts(""); // add newline

I am a beginer at programming,I wrote a code which gives perfect output but online judge didn't accepted.Why it's happen?(Codeforces problem 69A. ) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
#include<stdio.h>
int main(){
int a,b[101],i,j,sum=0;
scanf("%d",&a);
for(i=0;i<a;i++){
for(j=0;j<3;j++){
scanf("%d",&b[j]);
sum=sum+b[j];
}
}
if(sum==0) printf("YES\n");
else printf("NO\n");
return 0;
}
outputs are showed perfectly but online judge didn't accept.
online judge message"wrong answer on test 81".
link of problem"http://codeforces.com/problemset/problem/69/A"
The problem is asking to check if the sum of all vectors is zero.
Sum of vectors is element-wise addition of vectors, not simple summation of all elements.
Your program will fail in, for example, this case:
1
1 0 -1

How to get 4 characters of a string at a time iterating backwards [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
If I have a string, say "abcdefghij"
How can I iterate and get to characters backwards at a time.
For example
first loop : ghij
second loop: fedc
third loop: ab
Im using C++ but dont feel like its simple enough i should be able to adapt any language
Heres what I have so far:
for(long unsigned int i=0; i<s.length();i+=4){
digits.push_back(std::stoi(s.substr(i, 4)));
}
My issue is that this is left justified, not right justified
In pseudo code:
iterate i from s.length stepping by -4, while i > 0
start = max(i - 4, 0)
part = s.substring(start, i)

Combining 2 ctype.h functions into an IF in C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am having trouble with the following line of code.
//check number of words
if ((isblank(s[i]) != 0 && isblank(s[i+1] == 0)))
words++;
I would like to count the number of "blanks" that is followed by a non-blank, but combining these 2 isblanks do not seem to count correctly. Could someone please help me out?
I think it is a typo problem, your bracket is not in the correct place.
In this case the isblank() function get TRUE parameter if the s[i+1] is equal to 0, otherwise FALSE:
isblank(s[i+1] == 0)
I believe you wanted the to write the following:
isblank(s[i+1]) == 0

Validation of space in C syntax [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How to write syntax that can validate allow only one space input from user? Example, if the user input
"eat_food" it is VALID , when user enter "eat__food"(with 2 spaces) it would be INVALID..
and then show the appropriate error message to return right input?
This can be checked with strstr():
#define IS_VALID_INPUT(input) !strstr(input, " ")
This will result in 1 if there is not more than one space in the input, and 0 otherwise.
After the following code, n is the number of spaces in the string str.
Then you can check it.
int i, n = 0;
for (i = 0; str[i]!='\0'; i++)
n = (str[i] == ' ') ? (n+1) : n;

Resources