我正在尝试获取所有具有唯一数字的9位数字.我的第一种方法似乎有点过于复杂,编写起来也很乏味.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int indx;
int num;
int d1, d2, d3, d4, d5, d6, d7, d8, d9;
for(indx = 123456789; indx <= 987654321; indx++)
{
num = indx;
d1 = num % 10;
d2 = ( num / 10 ) % 10;
d3 = ( num / 100 ) % 10;
d4 = ( num / 1000 ) % 10;
d5 = ( num / 10000 ) % 10;
d6 = ( num …Run Code Online (Sandbox Code Playgroud) 我的程序将从用户获取一串字符并向后打印该句子,它将继续向用户询问另一个字符串,直到该字符串等于退出.我遇到的问题是,当用户进入退出时,它继续循环,当我希望它只打印"谢谢".我不知道为什么当用户进入退出时if和else语句不起作用.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char chr;
char *cPtr;
char someString[50];
int stringSize;
int indx;
printf("Enter a string of characters: ");
cPtr = someString;
while ((chr = getchar()) != '\n')
{
*cPtr = chr;
cPtr++;
}
*cPtr = '\0';
stringSize = strlen(someString);
if (someString == "quit" )
{
printf("Thank you.");
}
else
{
while (someString != "quit")
{
for (indx = stringSize; indx >= 0; indx--)
{
printf("%c",*cPtr--);
}
printf("\nEnter a string of characters: "); …Run Code Online (Sandbox Code Playgroud)