今天白天看了C语言的if语句和while,还有嵌套
晚上学习了三道程序题,分别是计算出1到100里的素数;1000内的完数;以及一个数他本身有多少个9
通过实践发现了自己C语言很薄弱,仍然需要不断的去敲写!
也熟悉了一些C语言的输入规范!现在重新敲写以上程序!
#include <stdio.h>
main()
{
int i;
int j;
int flag = 0;
int sum = 0;
for (i = 2; i < 100;i++)
{
for(j=2;j<i/2;j++)
{
if (i%j == 0)
{
flag = 1;
break;
}
}
if(flag != 1)
{
printf ("%d\n ",i);
sum++;
}
flag = 0;
}
printf("%d\n",sum);
return 0;
}
#include <stdio.h>
main()
{
int i;
int j;
int sum = 0;
for (i = 1; i < 100;i++)
{
for(j = 1;j <= i/2;j++)
{
if ( i%j == 0)
{
sum = sum + j;
}
main()
{
int i;
int j;
int sum = 0;
for (i = 1; i < 100;i++)
{
for(j = 1;j <= i/2;j++)
{
if ( i%j == 0)
{
sum = sum + j;
}
}
if (sum == i)
{
printf ("%d\n",i);
}
sum = 0;
}
return 0;
}
if (sum == i)
{
printf ("%d\n",i);
}
sum = 0;
}
return 0;
}
#include <stdio.c>
int main()
{
int i;
int num;
int temp;
int count = 0;
printf("please input numble:\n");
scanf("%d",&num);
for(i=1;i <= num; i++ )
{
int main()
{
int i;
int num;
int temp;
int count = 0;
printf("please input numble:\n");
scanf("%d",&num);
for(i=1;i <= num; i++ )
{
while (temp != 0)
{
if(temp % 10 == 9)
{
count++;
}
temp = temp / 10;
}
printf("9 count = %d\n",count);
{
if(temp % 10 == 9)
{
count++;
}
temp = temp / 10;
}
printf("9 count = %d\n",count);
return 0;
}
}