使用visualstudio代码在ubuntu中编写C程序
我写的代码是:使用visualstudio代码在ubuntu中编写C程序,c,linux,C,Linux,我写的代码是: #include<stdio.h> int main() { int i,m,maths=0,english=0,e,science=0,s,all=0; for(i=1;i<=5;i++) { printf("enter the marks of english:\n"); scanf("%d",&e); printf("enter the marks of mat
#include<stdio.h>
int main()
{
int i,m,maths=0,english=0,e,science=0,s,all=0;
for(i=1;i<=5;i++)
{
printf("enter the marks of english:\n");
scanf("%d",&e);
printf("enter the marks of maths:\n");
scanf("%d",&m);
printf("enter the marks of science:\n");
scanf("%d",&s);
if(m>=95 && s>=95 && e>=95)
all++;
if(m>=90)
maths++;
if(e>=90)
english++;
if(s>=90)
science++;
}
printf("95% or above in all subject : %d \n",all);
printf("90% or above in maths :%d\n",maths);
printf("90% or above in english: %d\n",english);
printf("90% or above in science: %d\n",science);
}
在C编程中%o表示八进制值。因此,当你写95%或读它为%o时。因为在%和o之间有一个空格,所以C编译器不能将其识别为八进制或百分比,这就是为什么它会发出警告。 但是,如果将95%替换为95%%,则c编译器将其读取为95%
#include<stdio.h>
int main()
{
int i,m,maths=0,english=0,e,science=0,s,all=0;
for(i=1;i<=5;i++)
{
printf("enter the marks of english:\n");
scanf("%d",&e);
printf("enter the marks of maths:\n");
scanf("%d",&m);
printf("enter the marks of science:\n");
scanf("%d",&s);
if(m>=95 && s>=95 && e>=95)
all++;
if(m>=90)
maths++;
if(e>=90)
english++;
if(s>=90)
science++;
}
printf("95%% or above in all subject : %d \n",all);
printf("90%% or above in maths :%d\n",maths);
printf("90%% or above in english: %d\n",english);
printf("90%% or above in science: %d\n",science);
}
#包括
int main()
{
int i,m,数学=0,英语=0,e,科学=0,s,all=0;
对于(i=1;i=95&&s>=95&&e>=95)
全部++;
如果(m>=90)
数学++;
如果(e>=90)
英语++;
如果(s>=90)
科学++;
}
printf(“95%%或以上所有科目:%d\n”,全部);
printf(“数学方面90%或以上:%d\n”,数学);
printf(“90%%或以上英语:%d\n”,英语);
printf(“90%%或以上,科学:%d\n”,科学);
}
现在应该可以了。对于从第24行到第27行的每一行,编译器都会发出两个警告(而不是您指出的错误)来帮助您解决问题 第一个原因是编译器遇到较长子字符串
95%或中的%o
%o
为%o
,带有空白标志,允许在签名数字类型为负数时发出-
第二个警告是由于第一次解释以及在格式字符串后仅包含一个参数而引起的。如果您意外地在格式字符串之后提供了两个带符号整数参数,那么您将不会看到任何警告
如果您不顾警告尝试按原样执行代码,那么您将得到未定义的行为
任何时候,如果您想在格式字符串中包含%%
,并且希望按字面意思发出它,则必须将其编码为%%
另外,与您的问题无关,您提供给gcc
-o
选项的值是不寻常的。人们通常会调用输出可执行文件studentMarks
或studentMarks
,而不是studentMarks.out
是的,你说得对,我使用%%时它工作了。是的,它工作了。谢谢@Gopal_Srivastava
#include<stdio.h>
int main()
{
int i,m,maths=0,english=0,e,science=0,s,all=0;
for(i=1;i<=5;i++)
{
printf("enter the marks of english:\n");
scanf("%d",&e);
printf("enter the marks of maths:\n");
scanf("%d",&m);
printf("enter the marks of science:\n");
scanf("%d",&s);
if(m>=95 && s>=95 && e>=95)
all++;
if(m>=90)
maths++;
if(e>=90)
english++;
if(s>=90)
science++;
}
printf("95%% or above in all subject : %d \n",all);
printf("90%% or above in maths :%d\n",maths);
printf("90%% or above in english: %d\n",english);
printf("90%% or above in science: %d\n",science);
}