[Solved] how to assign a fix value to int in c


There are some problem in this code :

1) According to the standard you shouldn’t use

void main()

But either

int main()
int main(void)
int main(int argc, char *argv[])

Also never forget

return 0;

Sample program :

#include <stdio.h>

int main(void) {       
    /* Do stuff */        
    return 0;    
}

If you wish to read more information about that, click here.

2)

int "1" ;

That’s not a correct way to declare a variable. You should have write :

int variable_name = 1;

Moreover, if you want to declare an array of 10 integer elements you have to write :

int array[10] = {....}

3)

"1= 1000";

I guess you want to overwrite the value of the variable prior declared with “1”. Following my example given before :

variable_name = 1000;

4)

scanf( "%d ",&number2 );

number2 = c;

You didn’t declare either the variable number2 nor c.

5)

printf(,1)

That’s not how you use printf. My guess here is that you tried to print :

int "1" ;

Following my example you can achieve this doing:

printf("%d", variable_name);

EDIT : My advices given above are corrects. Perhaps you was looking for something like that :

#include <stdio.h>

int main(void){

        int array[10] = {1000,2000,3000,4000,5000,6000,7000,8000,9000,10000}, user_choiche = 0, sum = 0, i = 0;

        do
        {
                printf("\nEnter a valid position (0 <= n <= 10) : ");
                scanf("%d", &user_choiche);
        }
        while(user_choiche < 0 || user_choiche > 10);

        printf("\nThe value stored in the %d position of the array is : %d\n\n", user_choiche, array[user_choiche]);

        for(i = 0; i < 10; i++)
             sum += array[i];

        printf("\nSum is %d.\n\n", sum);


return 0;

}

Input :

Enter a valid position (0 <= n <= 10) : -2

Enter a valid position (0 <= n <= 10) : 2

Output :

The value stored in the 2 position of the array is : 3000

Sum is 55000

11

solved how to assign a fix value to int in c