473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How can I replace an element in array using scanf function ?

Hi all,

First I want the user to input values in 10 numbered-array
If any number is less than 50 , the user must replace it by scanf.

This is what I have for now :
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #define N 5
  3.  
  4. int main()
  5. {
  6.     int array[N];
  7.     int i,element;
  8.  
  9.  
  10.     printf("Enter the array:>");
  11.     for (i=0;i<N;i++) { 
  12.     scanf("%d",&array[i]);
  13.     if (array[i]<=50){
  14.     element=array[i];
  15.     scanf("%d",&element);
  16.     }
  17.     }
  18.     printf("Your Array is:>\n");
  19.     for (i=0;i<N;i++)
  20.     printf("%d\n",array[i]);
  21.  
  22.  
  23.  
  24.  
  25.     return 0;
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
Dec 19 '10 #1
3 2643
weaknessforcats
9,208 Expert Mod 8TB
I would use two loops. The first loop allows the user to enter the integers. Then the second loop makes a pass over the array and has the user re-enter any incorrect values. The new values can be our right in the array as you have done in your code.
Dec 19 '10 #2
That's my problem , I can't figure out how to pass over the array and then re-enter the value
thanks !
Dec 19 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
You have aready done a pass over the array to put in your initial values.

Make a copy of your current loop and remove the first scanf.
Dec 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Kenny | last post by:
Hello, can anyone tell me how to pass an array to a function ? I have this function , part of my class. It works if I do not put in int a everywhere , but obviously , I need to add an array so I...
8
by: Tweaxor | last post by:
Hey, I was trying to figure out was it possible in C to pass the values in an array from one function to another function. Is the possible in C? ex. y is the array that holds seven values If...
1
by: Guha | last post by:
I have a problem with returning a 2D array using a function which is called in main(). The piece of the code is given below. This is a test code only. #include"stdio.h" #include"alloc.h" ...
30
by: James Daughtry | last post by:
char array; scanf("%19s", &array); I know this is wrong because it's a type mismatch, where scanf expects a pointer to char and gets a pointer to an array of 20 char. I know that question 6.12...
10
by: madhura | last post by:
Hello, I have a problem with 2-d arrays and scanf function. I have wriitten a code in which i am accepting values in 1-d arrays int a,i; for(i=0;i<3;i++) scanf("%d",a+i); when I print the...
13
by: arnuld | last post by:
this does not work, i know there is some problem in the "for loop" of "print_arr" function. i am not able to correct the weired results i am getting. i have no compile time error, it is only...
2
by: Bond | last post by:
i have written this program of entering 2-d array through pointers.this shows number of errors.please help me out. #include<stdio.h> #include<alloc.h> void aread(int*,int*,int*); void...
3
by: vaibhavkanwal | last post by:
Hi, i am trying to initialize a dynamic array and use this array to conduct linear search. I know about new and delete but as a pointer can be incremented by the sizeof its dataype, i wanted to...
4
by: drktmplr11 | last post by:
Hi, this is my first post here at the forums, and I am looking for assistance with what looks to be a syntax error within my code. I am attending FIU, and looking to broaden my understanding of...
3
by: SM | last post by:
Hello, I have an array that holds images path of cd covers. The array looks like this: $cd = array( 589=>'sylver.jpg', 782=>'bigone.jpg', 158=>'dime.jpg' );
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.